1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* Copyright (C) 2010 Jonathon Jongsma
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <glibmm/object.h>
#include <giomm/asyncresult.h>
#include <giomm/cancellable.h>
#include <giomm/socketconnectable.h>
#include <giomm/enums.h>
#include <giomm/socket.h>
#include <giomm/socketconnection.h>
#include <giomm/proxyresolver.h>
_DEFS(giomm,gio)
_PINCLUDE(glibmm/private/object_p.h)
namespace Gio
{
_WRAP_ENUM(SocketClientEvent, GSocketClientEvent)
/** Helper for connecting to a network service.
*
* @see SocketConnection, SocketListener
*
* SocketClient is a high-level utility class for connecting to a
* network host using a connection oriented socket type.
*
* You create a SocketClient object, set any options you want, then
* call a sync or async connect operation, which returns a SocketConnection
* subclass on success.
*
* The type of the SocketConnection object returned depends on the type of
* the underlying socket that is in use. For instance, for a TCP/IP connection
* it will be a TcpConnection.
*
* @newin{2,24}
* @ingroup NetworkIO
*/
class SocketClient : public Glib::Object
{
_CLASS_GOBJECT(SocketClient, GSocketClient, G_SOCKET_CLIENT, Glib::Object, GObject)
protected:
_CTOR_DEFAULT
public:
_WRAP_CREATE()
_WRAP_METHOD(SocketFamily get_family() const, g_socket_client_get_family)
_WRAP_METHOD(void set_family(SocketFamily family), g_socket_client_set_family)
_WRAP_METHOD(SocketType get_socket_type() const, g_socket_client_get_socket_type)
_WRAP_METHOD(void set_socket_type(SocketType type), g_socket_client_set_socket_type)
_WRAP_METHOD(SocketProtocol get_protocol() const, g_socket_client_get_protocol)
_WRAP_METHOD(void set_protocol(SocketProtocol protocol), g_socket_client_set_protocol)
_WRAP_METHOD(Glib::RefPtr<SocketAddress> get_local_address(), g_socket_client_get_local_address)
_WRAP_METHOD(Glib::RefPtr<const SocketAddress> get_local_address() const, g_socket_client_get_local_address, constversion)
_WRAP_METHOD(void set_local_address(const Glib::RefPtr<SocketAddress>& address), g_socket_client_set_local_address)
_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect(const Glib::RefPtr<SocketConnectable>& connectable, const Glib::RefPtr<Cancellable>& cancellable{?}), g_socket_client_connect, errthrow)
_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect_to_host(const Glib::ustring& host_and_port, guint16 default_port, const Glib::RefPtr<Cancellable>& cancellable{?}), g_socket_client_connect_to_host, errthrow)
_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect_to_service(const Glib::ustring& domain, const Glib::ustring& service, const Glib::RefPtr<Cancellable>& cancellable{?}), g_socket_client_connect_to_service, errthrow)
_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect_to_uri(const Glib::ustring& uri, guint16 default_port, const Glib::RefPtr<Cancellable>& cancellable{?}), g_socket_client_connect_to_uri, errthrow)
_WRAP_METHOD_DOCS_ONLY(g_socket_client_connect_async)
void connect_async(const Glib::RefPtr<SocketConnectable>& connectable, const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot);
/** This is the asynchronous version of connect().
* When the operation is finished @a slot will be called. You can then call finish() to get the result of the operation.
*
* @param connectable A SocketConnectable specifying the remote address.
* @param slot A callback slot to call after the operation completes.
*/
void connect_async(const Glib::RefPtr<SocketConnectable>& connectable, const SlotAsyncReady& slot);
_IGNORE(g_socket_client_connect_async)
_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect_finish(const Glib::RefPtr<AsyncResult>& result), g_socket_client_connect_finish, errthrow)
_WRAP_METHOD_DOCS_ONLY(g_socket_client_connect_to_host_async)
void connect_to_host_async(const Glib::ustring& host_and_port, guint16 default_port, const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot);
/** This is the asynchronous version of connect_to_host().
* When the operation is finished @a slot will be called. You can then call connect_to_host_finish() to get the result of the operation.
*
* @param host_and_port The name and optionally the port of the host to connect to.
* @param default_port The default port to connect to.
* @param slot A callback slot to call after the opration completes.
*/
void connect_to_host_async(const Glib::ustring& host_and_port, guint16 default_port, const SlotAsyncReady& slot);
_IGNORE(g_socket_client_connect_to_host_async)
_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect_to_host_finish(const Glib::RefPtr<AsyncResult>& result), g_socket_client_connect_to_host_finish, errthrow)
_WRAP_METHOD_DOCS_ONLY(g_socket_client_connect_to_service_async)
void connect_to_service_async(const Glib::ustring& domain, const Glib::ustring& service, const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot);
/** This is the asynchronous version of connect_to_service().
*
* @param domain A domain name.
* @param service The name of the service to connect to
* @param slot A callback slot to call after the opration completes.
*/
void connect_to_service_async(const Glib::ustring& domain, const Glib::ustring& service, const SlotAsyncReady& slot);
_IGNORE(g_socket_client_connect_to_service_async)
_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect_to_service_finish(const Glib::RefPtr<AsyncResult>& result), g_socket_client_connect_to_service_finish, errthrow)
_WRAP_METHOD_DOCS_ONLY(g_socket_client_connect_to_uri_async)
void connect_to_uri_async(const Glib::ustring& uri, guint16 default_port, const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot);
/** This is the asynchronous version of connect_to_uri().
*
* @param uri A network URI.
* @param default_port The default port to connect to.
* @param slot A callback slot to call after the opration completes.
*/
void connect_to_uri_async(const Glib::ustring& uri, guint16 default_port, const SlotAsyncReady& slot);
_IGNORE(g_socket_client_connect_to_uri_async)
_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect_to_uri_finish(const Glib::RefPtr<AsyncResult>& result), g_socket_client_connect_to_uri_finish, errthrow)
_WRAP_METHOD(bool get_enable_proxy() const, g_socket_client_get_enable_proxy)
_WRAP_METHOD(void set_enable_proxy(bool enable), g_socket_client_set_enable_proxy)
_WRAP_METHOD(bool get_tls() const, g_socket_client_get_tls)
_WRAP_METHOD(void set_tls(bool tls = true), g_socket_client_set_tls)
_WRAP_METHOD(TlsCertificateFlags get_tls_validation_flags() const, g_socket_client_get_tls_validation_flags)
_WRAP_METHOD(void set_tls_validation_flags(TlsCertificateFlags flags), g_socket_client_set_tls_validation_flags)
_WRAP_METHOD(Glib::RefPtr<ProxyResolver> get_proxy_resolver(), g_socket_client_get_proxy_resolver, refreturn)
_WRAP_METHOD(Glib::RefPtr<const ProxyResolver> get_proxy_resolver() const, g_socket_client_get_proxy_resolver, refreturn, constversion)
_WRAP_METHOD(void set_proxy_resolver(const Glib::RefPtr<ProxyResolver>& proxy_resolver), g_socket_client_set_proxy_resolver)
_WRAP_METHOD(guint get_timeout() const, g_socket_client_get_timeout)
_WRAP_METHOD(void set_timeout(guint timeout), g_socket_client_set_timeout)
_WRAP_METHOD(void add_application_proxy(const Glib::ustring& protocol), g_socket_client_add_application_proxy)
_WRAP_PROPERTY("family", SocketFamily)
_WRAP_PROPERTY("local-address", Glib::RefPtr<SocketAddress>)
_WRAP_PROPERTY("protocol", SocketProtocol)
_WRAP_PROPERTY("type", SocketType)
_WRAP_PROPERTY("timeout", guint)
_WRAP_PROPERTY("enable-proxy", bool)
_WRAP_PROPERTY("tls", bool)
_WRAP_PROPERTY("tls-validation-flags", TlsCertificateFlags)
_WRAP_PROPERTY("proxy-resolver", Glib::RefPtr<ProxyResolver>)
#m4 _CONVERSION(`GSocketConnectable*',`const Glib::RefPtr<SocketConnectable>&',`Glib::wrap($3)')
#m4 _CONVERSION(`GIOStream*',`const Glib::RefPtr<IOStream>&',`Glib::wrap($3)')
_WRAP_SIGNAL(void event(SocketClientEvent event, const Glib::RefPtr<SocketConnectable>& connectable, const Glib::RefPtr<IOStream>& connection), event, no_default_handler)
};
} // namespace Gio
|