1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* |
---|
3 | * Copyright (C) 2000-2003, Ximian, Inc. |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef SOUP_SOCKET_H |
---|
7 | #define SOUP_SOCKET_H 1 |
---|
8 | |
---|
9 | #include <libsoup/soup-types.h> |
---|
10 | |
---|
11 | #define SOUP_TYPE_SOCKET (soup_socket_get_type ()) |
---|
12 | #define SOUP_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOUP_TYPE_SOCKET, SoupSocket)) |
---|
13 | #define SOUP_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SOUP_TYPE_SOCKET, SoupSocketClass)) |
---|
14 | #define SOUP_IS_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SOUP_TYPE_SOCKET)) |
---|
15 | #define SOUP_IS_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), SOUP_TYPE_SOCKET)) |
---|
16 | #define SOUP_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SOUP_TYPE_SOCKET, SoupSocketClass)) |
---|
17 | |
---|
18 | typedef struct SoupSocketPrivate SoupSocketPrivate; |
---|
19 | |
---|
20 | struct SoupSocket { |
---|
21 | GObject parent; |
---|
22 | |
---|
23 | SoupSocketPrivate *priv; |
---|
24 | }; |
---|
25 | |
---|
26 | typedef struct { |
---|
27 | GObjectClass parent_class; |
---|
28 | |
---|
29 | /* signals */ |
---|
30 | void (*connect_result) (SoupSocket *, guint); |
---|
31 | void (*readable) (SoupSocket *); |
---|
32 | void (*writable) (SoupSocket *); |
---|
33 | void (*disconnected) (SoupSocket *); |
---|
34 | |
---|
35 | void (*new_connection) (SoupSocket *, SoupSocket *); |
---|
36 | } SoupSocketClass; |
---|
37 | |
---|
38 | #define SOUP_SOCKET_FLAG_NONBLOCKING "non-blocking" |
---|
39 | #define SOUP_SOCKET_FLAG_NODELAY "nodelay" |
---|
40 | #define SOUP_SOCKET_FLAG_REUSEADDR "reuseaddr" |
---|
41 | #define SOUP_SOCKET_IS_SERVER "is-server" |
---|
42 | #define SOUP_SOCKET_SSL_CREDENTIALS "ssl-creds" |
---|
43 | |
---|
44 | GType soup_socket_get_type (void); |
---|
45 | |
---|
46 | SoupSocket *soup_socket_new (const char *optname1, |
---|
47 | ...); |
---|
48 | |
---|
49 | guint soup_socket_connect (SoupSocket *sock, |
---|
50 | SoupAddress *remote_addr); |
---|
51 | gboolean soup_socket_listen (SoupSocket *sock, |
---|
52 | SoupAddress *local_addr); |
---|
53 | gboolean soup_socket_start_ssl (SoupSocket *sock); |
---|
54 | gboolean soup_socket_start_proxy_ssl (SoupSocket *sock, |
---|
55 | const char *ssl_host); |
---|
56 | |
---|
57 | void soup_socket_disconnect (SoupSocket *sock); |
---|
58 | gboolean soup_socket_is_connected (SoupSocket *sock); |
---|
59 | |
---|
60 | typedef void (*SoupSocketCallback) (SoupSocket *sock, |
---|
61 | guint status, |
---|
62 | gpointer user_data); |
---|
63 | typedef void (*SoupSocketListenerCallback) (SoupSocket *listener, |
---|
64 | SoupSocket *sock, |
---|
65 | gpointer user_data); |
---|
66 | |
---|
67 | SoupSocket *soup_socket_client_new_async (const char *hostname, |
---|
68 | guint port, |
---|
69 | gpointer ssl_creds, |
---|
70 | SoupSocketCallback callback, |
---|
71 | gpointer user_data); |
---|
72 | SoupSocket *soup_socket_client_new_sync (const char *hostname, |
---|
73 | guint port, |
---|
74 | gpointer ssl_creds, |
---|
75 | guint *status_ret); |
---|
76 | SoupSocket *soup_socket_server_new (SoupAddress *local_addr, |
---|
77 | gpointer ssl_creds, |
---|
78 | SoupSocketListenerCallback callback, |
---|
79 | gpointer user_data); |
---|
80 | |
---|
81 | SoupAddress *soup_socket_get_local_address (SoupSocket *sock); |
---|
82 | SoupAddress *soup_socket_get_remote_address (SoupSocket *sock); |
---|
83 | |
---|
84 | |
---|
85 | typedef enum { |
---|
86 | SOUP_SOCKET_OK, |
---|
87 | SOUP_SOCKET_WOULD_BLOCK, |
---|
88 | SOUP_SOCKET_EOF, |
---|
89 | SOUP_SOCKET_ERROR |
---|
90 | } SoupSocketIOStatus; |
---|
91 | |
---|
92 | SoupSocketIOStatus soup_socket_read (SoupSocket *sock, |
---|
93 | gpointer buffer, |
---|
94 | gsize len, |
---|
95 | gsize *nread); |
---|
96 | SoupSocketIOStatus soup_socket_read_until (SoupSocket *sock, |
---|
97 | gpointer buffer, |
---|
98 | gsize len, |
---|
99 | gconstpointer boundary, |
---|
100 | gsize boundary_len, |
---|
101 | gsize *nread, |
---|
102 | gboolean *got_boundary); |
---|
103 | |
---|
104 | SoupSocketIOStatus soup_socket_write (SoupSocket *sock, |
---|
105 | gconstpointer buffer, |
---|
106 | gsize len, |
---|
107 | gsize *nwrote); |
---|
108 | |
---|
109 | |
---|
110 | #endif /* SOUP_SOCKET_H */ |
---|