| 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 | |
| 34 | G_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 | |
| 48 | typedef struct _GSocketPrivate GSocketPrivate; |
| 49 | typedef struct _GSocketClass GSocketClass; |
| 50 | |
| 51 | struct _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 | |
| 70 | struct _GSocket |
| 71 | { |
| 72 | GObject parent_instance; |
| 73 | GSocketPrivate *priv; |
| 74 | }; |
| 75 | |
| 76 | GIO_AVAILABLE_IN_ALL |
| 77 | GType g_socket_get_type (void) G_GNUC_CONST; |
| 78 | GIO_AVAILABLE_IN_ALL |
| 79 | GSocket * g_socket_new (GSocketFamily family, |
| 80 | GSocketType type, |
| 81 | GSocketProtocol protocol, |
| 82 | GError **error); |
| 83 | GIO_AVAILABLE_IN_ALL |
| 84 | GSocket * g_socket_new_from_fd (gint fd, |
| 85 | GError **error); |
| 86 | GIO_AVAILABLE_IN_ALL |
| 87 | int g_socket_get_fd (GSocket *socket); |
| 88 | GIO_AVAILABLE_IN_ALL |
| 89 | GSocketFamily g_socket_get_family (GSocket *socket); |
| 90 | GIO_AVAILABLE_IN_ALL |
| 91 | GSocketType g_socket_get_socket_type (GSocket *socket); |
| 92 | GIO_AVAILABLE_IN_ALL |
| 93 | GSocketProtocol g_socket_get_protocol (GSocket *socket); |
| 94 | GIO_AVAILABLE_IN_ALL |
| 95 | GSocketAddress * g_socket_get_local_address (GSocket *socket, |
| 96 | GError **error); |
| 97 | GIO_AVAILABLE_IN_ALL |
| 98 | GSocketAddress * g_socket_get_remote_address (GSocket *socket, |
| 99 | GError **error); |
| 100 | GIO_AVAILABLE_IN_ALL |
| 101 | void g_socket_set_blocking (GSocket *socket, |
| 102 | gboolean blocking); |
| 103 | GIO_AVAILABLE_IN_ALL |
| 104 | gboolean g_socket_get_blocking (GSocket *socket); |
| 105 | GIO_AVAILABLE_IN_ALL |
| 106 | void g_socket_set_keepalive (GSocket *socket, |
| 107 | gboolean keepalive); |
| 108 | GIO_AVAILABLE_IN_ALL |
| 109 | gboolean g_socket_get_keepalive (GSocket *socket); |
| 110 | GIO_AVAILABLE_IN_ALL |
| 111 | gint g_socket_get_listen_backlog (GSocket *socket); |
| 112 | GIO_AVAILABLE_IN_ALL |
| 113 | void g_socket_set_listen_backlog (GSocket *socket, |
| 114 | gint backlog); |
| 115 | GIO_AVAILABLE_IN_ALL |
| 116 | guint g_socket_get_timeout (GSocket *socket); |
| 117 | GIO_AVAILABLE_IN_ALL |
| 118 | void g_socket_set_timeout (GSocket *socket, |
| 119 | guint timeout); |
| 120 | |
| 121 | GIO_AVAILABLE_IN_2_32 |
| 122 | guint g_socket_get_ttl (GSocket *socket); |
| 123 | GIO_AVAILABLE_IN_2_32 |
| 124 | void g_socket_set_ttl (GSocket *socket, |
| 125 | guint ttl); |
| 126 | |
| 127 | GIO_AVAILABLE_IN_2_32 |
| 128 | gboolean g_socket_get_broadcast (GSocket *socket); |
| 129 | GIO_AVAILABLE_IN_2_32 |
| 130 | void g_socket_set_broadcast (GSocket *socket, |
| 131 | gboolean broadcast); |
| 132 | |
| 133 | GIO_AVAILABLE_IN_2_32 |
| 134 | gboolean g_socket_get_multicast_loopback (GSocket *socket); |
| 135 | GIO_AVAILABLE_IN_2_32 |
| 136 | void g_socket_set_multicast_loopback (GSocket *socket, |
| 137 | gboolean loopback); |
| 138 | GIO_AVAILABLE_IN_2_32 |
| 139 | guint g_socket_get_multicast_ttl (GSocket *socket); |
| 140 | GIO_AVAILABLE_IN_2_32 |
| 141 | void g_socket_set_multicast_ttl (GSocket *socket, |
| 142 | guint ttl); |
| 143 | GIO_AVAILABLE_IN_ALL |
| 144 | gboolean g_socket_is_connected (GSocket *socket); |
| 145 | GIO_AVAILABLE_IN_ALL |
| 146 | gboolean g_socket_bind (GSocket *socket, |
| 147 | GSocketAddress *address, |
| 148 | gboolean allow_reuse, |
| 149 | GError **error); |
| 150 | GIO_AVAILABLE_IN_2_32 |
| 151 | gboolean g_socket_join_multicast_group (GSocket *socket, |
| 152 | GInetAddress *group, |
| 153 | gboolean source_specific, |
| 154 | const gchar *iface, |
| 155 | GError **error); |
| 156 | GIO_AVAILABLE_IN_2_32 |
| 157 | gboolean g_socket_leave_multicast_group (GSocket *socket, |
| 158 | GInetAddress *group, |
| 159 | gboolean source_specific, |
| 160 | const gchar *iface, |
| 161 | GError **error); |
| 162 | GIO_AVAILABLE_IN_2_56 |
| 163 | gboolean g_socket_join_multicast_group_ssm (GSocket *socket, |
| 164 | GInetAddress *group, |
| 165 | GInetAddress *source_specific, |
| 166 | const gchar *iface, |
| 167 | GError **error); |
| 168 | GIO_AVAILABLE_IN_2_56 |
| 169 | gboolean g_socket_leave_multicast_group_ssm (GSocket *socket, |
| 170 | GInetAddress *group, |
| 171 | GInetAddress *source_specific, |
| 172 | const gchar *iface, |
| 173 | GError **error); |
| 174 | GIO_AVAILABLE_IN_ALL |
| 175 | gboolean g_socket_connect (GSocket *socket, |
| 176 | GSocketAddress *address, |
| 177 | GCancellable *cancellable, |
| 178 | GError **error); |
| 179 | GIO_AVAILABLE_IN_ALL |
| 180 | gboolean g_socket_check_connect_result (GSocket *socket, |
| 181 | GError **error); |
| 182 | |
| 183 | GIO_AVAILABLE_IN_ALL |
| 184 | gssize g_socket_get_available_bytes (GSocket *socket); |
| 185 | |
| 186 | GIO_AVAILABLE_IN_ALL |
| 187 | GIOCondition g_socket_condition_check (GSocket *socket, |
| 188 | GIOCondition condition); |
| 189 | GIO_AVAILABLE_IN_ALL |
| 190 | gboolean g_socket_condition_wait (GSocket *socket, |
| 191 | GIOCondition condition, |
| 192 | GCancellable *cancellable, |
| 193 | GError **error); |
| 194 | GIO_AVAILABLE_IN_2_32 |
| 195 | gboolean g_socket_condition_timed_wait (GSocket *socket, |
| 196 | GIOCondition condition, |
| 197 | gint64 timeout_us, |
| 198 | GCancellable *cancellable, |
| 199 | GError **error); |
| 200 | GIO_AVAILABLE_IN_ALL |
| 201 | GSocket * g_socket_accept (GSocket *socket, |
| 202 | GCancellable *cancellable, |
| 203 | GError **error); |
| 204 | GIO_AVAILABLE_IN_ALL |
| 205 | gboolean g_socket_listen (GSocket *socket, |
| 206 | GError **error); |
| 207 | GIO_AVAILABLE_IN_ALL |
| 208 | gssize g_socket_receive (GSocket *socket, |
| 209 | gchar *buffer, |
| 210 | gsize size, |
| 211 | GCancellable *cancellable, |
| 212 | GError **error); |
| 213 | GIO_AVAILABLE_IN_2_80 |
| 214 | GBytes * g_socket_receive_bytes (GSocket *socket, |
| 215 | gsize size, |
| 216 | gint64 timeout_us, |
| 217 | GCancellable *cancellable, |
| 218 | GError **error); |
| 219 | GIO_AVAILABLE_IN_ALL |
| 220 | gssize g_socket_receive_from (GSocket *socket, |
| 221 | GSocketAddress **address, |
| 222 | gchar *buffer, |
| 223 | gsize size, |
| 224 | GCancellable *cancellable, |
| 225 | GError **error); |
| 226 | GIO_AVAILABLE_IN_2_80 |
| 227 | GBytes * g_socket_receive_bytes_from (GSocket *socket, |
| 228 | GSocketAddress **address, |
| 229 | gsize size, |
| 230 | gint64 timeout_us, |
| 231 | GCancellable *cancellable, |
| 232 | GError **error); |
| 233 | GIO_AVAILABLE_IN_ALL |
| 234 | gssize g_socket_send (GSocket *socket, |
| 235 | const gchar *buffer, |
| 236 | gsize size, |
| 237 | GCancellable *cancellable, |
| 238 | GError **error); |
| 239 | GIO_AVAILABLE_IN_ALL |
| 240 | gssize g_socket_send_to (GSocket *socket, |
| 241 | GSocketAddress *address, |
| 242 | const gchar *buffer, |
| 243 | gsize size, |
| 244 | GCancellable *cancellable, |
| 245 | GError **error); |
| 246 | GIO_AVAILABLE_IN_ALL |
| 247 | gssize 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); |
| 256 | GIO_AVAILABLE_IN_ALL |
| 257 | gssize 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 | |
| 267 | GIO_AVAILABLE_IN_2_48 |
| 268 | gint g_socket_receive_messages (GSocket *socket, |
| 269 | GInputMessage *messages, |
| 270 | guint num_messages, |
| 271 | gint flags, |
| 272 | GCancellable *cancellable, |
| 273 | GError **error); |
| 274 | GIO_AVAILABLE_IN_2_44 |
| 275 | gint g_socket_send_messages (GSocket *socket, |
| 276 | GOutputMessage *messages, |
| 277 | guint num_messages, |
| 278 | gint flags, |
| 279 | GCancellable *cancellable, |
| 280 | GError **error); |
| 281 | |
| 282 | GIO_AVAILABLE_IN_ALL |
| 283 | gboolean g_socket_close (GSocket *socket, |
| 284 | GError **error); |
| 285 | GIO_AVAILABLE_IN_ALL |
| 286 | gboolean g_socket_shutdown (GSocket *socket, |
| 287 | gboolean shutdown_read, |
| 288 | gboolean shutdown_write, |
| 289 | GError **error); |
| 290 | GIO_AVAILABLE_IN_ALL |
| 291 | gboolean g_socket_is_closed (GSocket *socket); |
| 292 | GIO_AVAILABLE_IN_ALL |
| 293 | GSource * g_socket_create_source (GSocket *socket, |
| 294 | GIOCondition condition, |
| 295 | GCancellable *cancellable); |
| 296 | GIO_AVAILABLE_IN_ALL |
| 297 | gboolean g_socket_speaks_ipv4 (GSocket *socket); |
| 298 | GIO_AVAILABLE_IN_ALL |
| 299 | GCredentials *g_socket_get_credentials (GSocket *socket, |
| 300 | GError **error); |
| 301 | |
| 302 | GIO_AVAILABLE_IN_ALL |
| 303 | gssize g_socket_receive_with_blocking (GSocket *socket, |
| 304 | gchar *buffer, |
| 305 | gsize size, |
| 306 | gboolean blocking, |
| 307 | GCancellable *cancellable, |
| 308 | GError **error); |
| 309 | GIO_AVAILABLE_IN_ALL |
| 310 | gssize g_socket_send_with_blocking (GSocket *socket, |
| 311 | const gchar *buffer, |
| 312 | gsize size, |
| 313 | gboolean blocking, |
| 314 | GCancellable *cancellable, |
| 315 | GError **error); |
| 316 | GIO_AVAILABLE_IN_2_60 |
| 317 | GPollableReturn 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); |
| 328 | GIO_AVAILABLE_IN_2_36 |
| 329 | gboolean g_socket_get_option (GSocket *socket, |
| 330 | gint level, |
| 331 | gint optname, |
| 332 | gint *value, |
| 333 | GError **error); |
| 334 | GIO_AVAILABLE_IN_2_36 |
| 335 | gboolean g_socket_set_option (GSocket *socket, |
| 336 | gint level, |
| 337 | gint optname, |
| 338 | gint value, |
| 339 | GError **error); |
| 340 | |
| 341 | G_END_DECLS |
| 342 | |
| 343 | #endif /* __G_SOCKET_H__ */ |
| 344 | |