New header with typedefs, to avoid #include loops among other headers.
[platform/upstream/libsoup.git] / libsoup / soup-socket.h
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 *, SoupKnownErrorCode);
31         void (*readable)       (SoupSocket *);
32         void (*writable)       (SoupSocket *);
33         void (*disconnected)   (SoupSocket *);
34
35         void (*new_connection) (SoupSocket *, SoupSocket *);
36 } SoupSocketClass;
37
38 typedef enum {
39         SOUP_SOCKET_FLAG_NONBLOCKING,
40         SOUP_SOCKET_FLAG_NODELAY,
41         SOUP_SOCKET_FLAG_REUSEADDR,
42 } SoupSocketFlag;
43
44 GType soup_socket_get_type (void);
45
46 SoupSocket    *soup_socket_new                (void);
47 void           soup_socket_set_flag           (SoupSocket         *sock,
48                                                SoupSocketFlag      flag,
49                                                gboolean            value);
50
51 void           soup_socket_connect            (SoupSocket         *sock,
52                                                SoupAddress        *rem_addr);
53 gboolean       soup_socket_listen             (SoupSocket         *sock,
54                                                SoupAddress        *local_addr);
55 void           soup_socket_start_ssl          (SoupSocket         *sock);
56
57 void           soup_socket_disconnect         (SoupSocket         *sock);
58 gboolean       soup_socket_is_connected       (SoupSocket         *sock);
59
60 typedef void (*SoupSocketCallback)            (SoupSocket         *sock,
61                                                SoupKnownErrorCode  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         (const char         *hostname,
68                                                guint               port,
69                                                gboolean            ssl,
70                                                SoupSocketCallback  callback,
71                                                gpointer            user_data);
72 SoupSocket    *soup_socket_server_new         (SoupAddress        *local_addr,
73                                                gboolean            ssl,
74                                                SoupSocketListenerCallback,
75                                                gpointer            user_data);
76
77
78 GIOChannel    *soup_socket_get_iochannel      (SoupSocket         *sock);
79
80 SoupAddress   *soup_socket_get_local_address  (SoupSocket         *sock);
81 SoupAddress   *soup_socket_get_remote_address (SoupSocket         *sock);
82
83
84 typedef enum {
85         SOUP_SOCKET_OK,
86         SOUP_SOCKET_WOULD_BLOCK,
87         SOUP_SOCKET_EOF,
88         SOUP_SOCKET_ERROR
89 } SoupSocketIOStatus;
90
91 SoupSocketIOStatus  soup_socket_read       (SoupSocket         *sock,
92                                             gpointer            buffer,
93                                             guint               len,
94                                             guint              *nread);
95 SoupSocketIOStatus  soup_socket_read_until (SoupSocket         *sock,
96                                             gpointer            buffer,
97                                             guint               len,
98                                             gconstpointer       boundary,
99                                             guint               boundary_len,
100                                             guint              *nread,
101                                             gboolean           *got_boundary);
102
103 SoupSocketIOStatus  soup_socket_write      (SoupSocket         *sock,
104                                             gconstpointer       buffer,
105                                             guint               len,
106                                             guint              *nwrote);
107
108
109 #endif /* SOUP_SOCKET_H */