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