1/*
2 * Copyright © 2008 Christian Kellner, Samuel Cormier-Iijima
3 * Copyright © 2009 Codethink Limited
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Christian Kellner <gicmo@gnome.org>
19 * Samuel Cormier-Iijima <sciyoshi@gmail.com>
20 * Ryan Lortie <desrt@desrt.ca>
21 */
22
23#ifndef __G_SOCKET_H__
24#define __G_SOCKET_H__
25
26#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
27#error "Only <gio/gio.h> can be included directly."
28#endif
29
30#include <gio/giotypes.h>
31
32G_BEGIN_DECLS
33
34#define G_TYPE_SOCKET (g_socket_get_type ())
35#define G_SOCKET(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
36 G_TYPE_SOCKET, GSocket))
37#define G_SOCKET_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
38 G_TYPE_SOCKET, GSocketClass))
39#define G_IS_SOCKET(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
40 G_TYPE_SOCKET))
41#define G_IS_SOCKET_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \
42 G_TYPE_SOCKET))
43#define G_SOCKET_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
44 G_TYPE_SOCKET, GSocketClass))
45
46typedef struct _GSocketPrivate GSocketPrivate;
47typedef struct _GSocketClass GSocketClass;
48
49struct _GSocketClass
50{
51 GObjectClass parent_class;
52
53 /*< private >*/
54
55 /* Padding for future expansion */
56 void (*_g_reserved1) (void);
57 void (*_g_reserved2) (void);
58 void (*_g_reserved3) (void);
59 void (*_g_reserved4) (void);
60 void (*_g_reserved5) (void);
61 void (*_g_reserved6) (void);
62 void (*_g_reserved7) (void);
63 void (*_g_reserved8) (void);
64 void (*_g_reserved9) (void);
65 void (*_g_reserved10) (void);
66};
67
68struct _GSocket
69{
70 GObject parent_instance;
71 GSocketPrivate *priv;
72};
73
74GLIB_AVAILABLE_IN_ALL
75GType g_socket_get_type (void) G_GNUC_CONST;
76GLIB_AVAILABLE_IN_ALL
77GSocket * g_socket_new (GSocketFamily family,
78 GSocketType type,
79 GSocketProtocol protocol,
80 GError **error);
81GLIB_AVAILABLE_IN_ALL
82GSocket * g_socket_new_from_fd (gint fd,
83 GError **error);
84GLIB_AVAILABLE_IN_ALL
85int g_socket_get_fd (GSocket *socket);
86GLIB_AVAILABLE_IN_ALL
87GSocketFamily g_socket_get_family (GSocket *socket);
88GLIB_AVAILABLE_IN_ALL
89GSocketType g_socket_get_socket_type (GSocket *socket);
90GLIB_AVAILABLE_IN_ALL
91GSocketProtocol g_socket_get_protocol (GSocket *socket);
92GLIB_AVAILABLE_IN_ALL
93GSocketAddress * g_socket_get_local_address (GSocket *socket,
94 GError **error);
95GLIB_AVAILABLE_IN_ALL
96GSocketAddress * g_socket_get_remote_address (GSocket *socket,
97 GError **error);
98GLIB_AVAILABLE_IN_ALL
99void g_socket_set_blocking (GSocket *socket,
100 gboolean blocking);
101GLIB_AVAILABLE_IN_ALL
102gboolean g_socket_get_blocking (GSocket *socket);
103GLIB_AVAILABLE_IN_ALL
104void g_socket_set_keepalive (GSocket *socket,
105 gboolean keepalive);
106GLIB_AVAILABLE_IN_ALL
107gboolean g_socket_get_keepalive (GSocket *socket);
108GLIB_AVAILABLE_IN_ALL
109gint g_socket_get_listen_backlog (GSocket *socket);
110GLIB_AVAILABLE_IN_ALL
111void g_socket_set_listen_backlog (GSocket *socket,
112 gint backlog);
113GLIB_AVAILABLE_IN_ALL
114guint g_socket_get_timeout (GSocket *socket);
115GLIB_AVAILABLE_IN_ALL
116void g_socket_set_timeout (GSocket *socket,
117 guint timeout);
118
119GLIB_AVAILABLE_IN_2_32
120guint g_socket_get_ttl (GSocket *socket);
121GLIB_AVAILABLE_IN_2_32
122void g_socket_set_ttl (GSocket *socket,
123 guint ttl);
124
125GLIB_AVAILABLE_IN_2_32
126gboolean g_socket_get_broadcast (GSocket *socket);
127GLIB_AVAILABLE_IN_2_32
128void g_socket_set_broadcast (GSocket *socket,
129 gboolean broadcast);
130
131GLIB_AVAILABLE_IN_2_32
132gboolean g_socket_get_multicast_loopback (GSocket *socket);
133GLIB_AVAILABLE_IN_2_32
134void g_socket_set_multicast_loopback (GSocket *socket,
135 gboolean loopback);
136GLIB_AVAILABLE_IN_2_32
137guint g_socket_get_multicast_ttl (GSocket *socket);
138GLIB_AVAILABLE_IN_2_32
139void g_socket_set_multicast_ttl (GSocket *socket,
140 guint ttl);
141GLIB_AVAILABLE_IN_ALL
142gboolean g_socket_is_connected (GSocket *socket);
143GLIB_AVAILABLE_IN_ALL
144gboolean g_socket_bind (GSocket *socket,
145 GSocketAddress *address,
146 gboolean allow_reuse,
147 GError **error);
148GLIB_AVAILABLE_IN_2_32
149gboolean g_socket_join_multicast_group (GSocket *socket,
150 GInetAddress *group,
151 gboolean source_specific,
152 const gchar *iface,
153 GError **error);
154GLIB_AVAILABLE_IN_2_32
155gboolean g_socket_leave_multicast_group (GSocket *socket,
156 GInetAddress *group,
157 gboolean source_specific,
158 const gchar *iface,
159 GError **error);
160GLIB_AVAILABLE_IN_2_56
161gboolean g_socket_join_multicast_group_ssm (GSocket *socket,
162 GInetAddress *group,
163 GInetAddress *source_specific,
164 const gchar *iface,
165 GError **error);
166GLIB_AVAILABLE_IN_2_56
167gboolean g_socket_leave_multicast_group_ssm (GSocket *socket,
168 GInetAddress *group,
169 GInetAddress *source_specific,
170 const gchar *iface,
171 GError **error);
172GLIB_AVAILABLE_IN_ALL
173gboolean g_socket_connect (GSocket *socket,
174 GSocketAddress *address,
175 GCancellable *cancellable,
176 GError **error);
177GLIB_AVAILABLE_IN_ALL
178gboolean g_socket_check_connect_result (GSocket *socket,
179 GError **error);
180
181GLIB_AVAILABLE_IN_ALL
182gssize g_socket_get_available_bytes (GSocket *socket);
183
184GLIB_AVAILABLE_IN_ALL
185GIOCondition g_socket_condition_check (GSocket *socket,
186 GIOCondition condition);
187GLIB_AVAILABLE_IN_ALL
188gboolean g_socket_condition_wait (GSocket *socket,
189 GIOCondition condition,
190 GCancellable *cancellable,
191 GError **error);
192GLIB_AVAILABLE_IN_2_32
193gboolean g_socket_condition_timed_wait (GSocket *socket,
194 GIOCondition condition,
195 gint64 timeout,
196 GCancellable *cancellable,
197 GError **error);
198GLIB_AVAILABLE_IN_ALL
199GSocket * g_socket_accept (GSocket *socket,
200 GCancellable *cancellable,
201 GError **error);
202GLIB_AVAILABLE_IN_ALL
203gboolean g_socket_listen (GSocket *socket,
204 GError **error);
205GLIB_AVAILABLE_IN_ALL
206gssize g_socket_receive (GSocket *socket,
207 gchar *buffer,
208 gsize size,
209 GCancellable *cancellable,
210 GError **error);
211GLIB_AVAILABLE_IN_ALL
212gssize g_socket_receive_from (GSocket *socket,
213 GSocketAddress **address,
214 gchar *buffer,
215 gsize size,
216 GCancellable *cancellable,
217 GError **error);
218GLIB_AVAILABLE_IN_ALL
219gssize g_socket_send (GSocket *socket,
220 const gchar *buffer,
221 gsize size,
222 GCancellable *cancellable,
223 GError **error);
224GLIB_AVAILABLE_IN_ALL
225gssize g_socket_send_to (GSocket *socket,
226 GSocketAddress *address,
227 const gchar *buffer,
228 gsize size,
229 GCancellable *cancellable,
230 GError **error);
231GLIB_AVAILABLE_IN_ALL
232gssize g_socket_receive_message (GSocket *socket,
233 GSocketAddress **address,
234 GInputVector *vectors,
235 gint num_vectors,
236 GSocketControlMessage ***messages,
237 gint *num_messages,
238 gint *flags,
239 GCancellable *cancellable,
240 GError **error);
241GLIB_AVAILABLE_IN_ALL
242gssize g_socket_send_message (GSocket *socket,
243 GSocketAddress *address,
244 GOutputVector *vectors,
245 gint num_vectors,
246 GSocketControlMessage **messages,
247 gint num_messages,
248 gint flags,
249 GCancellable *cancellable,
250 GError **error);
251
252GLIB_AVAILABLE_IN_2_48
253gint g_socket_receive_messages (GSocket *socket,
254 GInputMessage *messages,
255 guint num_messages,
256 gint flags,
257 GCancellable *cancellable,
258 GError **error);
259GLIB_AVAILABLE_IN_2_44
260gint g_socket_send_messages (GSocket *socket,
261 GOutputMessage *messages,
262 guint num_messages,
263 gint flags,
264 GCancellable *cancellable,
265 GError **error);
266
267GLIB_AVAILABLE_IN_ALL
268gboolean g_socket_close (GSocket *socket,
269 GError **error);
270GLIB_AVAILABLE_IN_ALL
271gboolean g_socket_shutdown (GSocket *socket,
272 gboolean shutdown_read,
273 gboolean shutdown_write,
274 GError **error);
275GLIB_AVAILABLE_IN_ALL
276gboolean g_socket_is_closed (GSocket *socket);
277GLIB_AVAILABLE_IN_ALL
278GSource * g_socket_create_source (GSocket *socket,
279 GIOCondition condition,
280 GCancellable *cancellable);
281GLIB_AVAILABLE_IN_ALL
282gboolean g_socket_speaks_ipv4 (GSocket *socket);
283GLIB_AVAILABLE_IN_ALL
284GCredentials *g_socket_get_credentials (GSocket *socket,
285 GError **error);
286
287GLIB_AVAILABLE_IN_ALL
288gssize g_socket_receive_with_blocking (GSocket *socket,
289 gchar *buffer,
290 gsize size,
291 gboolean blocking,
292 GCancellable *cancellable,
293 GError **error);
294GLIB_AVAILABLE_IN_ALL
295gssize g_socket_send_with_blocking (GSocket *socket,
296 const gchar *buffer,
297 gsize size,
298 gboolean blocking,
299 GCancellable *cancellable,
300 GError **error);
301
302GLIB_AVAILABLE_IN_2_36
303gboolean g_socket_get_option (GSocket *socket,
304 gint level,
305 gint optname,
306 gint *value,
307 GError **error);
308GLIB_AVAILABLE_IN_2_36
309gboolean g_socket_set_option (GSocket *socket,
310 gint level,
311 gint optname,
312 gint value,
313 GError **error);
314
315G_END_DECLS
316
317#endif /* __G_SOCKET_H__ */
318