equal
deleted
inserted
replaced
4 /* |
4 /* |
5 * Low-level socket-related functions |
5 * Low-level socket-related functions |
6 */ |
6 */ |
7 #include "error.h" |
7 #include "error.h" |
8 #include <sys/types.h> |
8 #include <sys/types.h> |
|
9 #include <event2/event.h> |
9 |
10 |
10 /* |
11 /* |
11 * The generic socket handle |
12 * The generic socket handle |
12 */ |
13 */ |
13 struct sock_stream; |
14 struct sock_stream; |
14 |
15 |
15 /* |
16 /* |
|
17 * Async callbacks for socket operation |
|
18 */ |
|
19 struct sock_stream_callbacks { |
|
20 /* Sockeet is readable */ |
|
21 void (*on_read)(struct sock_stream *sock, void *arg); |
|
22 |
|
23 /* Socket is writeable */ |
|
24 void (*on_write)(struct sock_stream *sock, void *arg); |
|
25 }; |
|
26 |
|
27 /* |
16 * Initialize the socket module's global state. Call this before calling any other sock_* functions. |
28 * Initialize the socket module's global state. Call this before calling any other sock_* functions. |
|
29 * |
|
30 * The given \a ev_base is the libevent base to use for nonblocking operation. |
17 */ |
31 */ |
18 err_t sock_init (struct error_info *err); |
32 err_t sock_init (struct event_base *ev_base, struct error_info *err); |
19 |
33 |
20 /* |
34 /* |
21 * A simple blocking TCP connect to the given host/service, using getaddrinfo. The connected socket is returned via |
35 * A simple blocking TCP connect to the given host/service, using getaddrinfo. The connected socket is returned via |
22 * *sock_ptr. In case of errors, additional error information is stored in *err. |
36 * *sock_ptr. In case of errors, additional error information is stored in *err. |
23 * |
37 * |
35 * XXX: doesn't do any certificate verification. |
49 * XXX: doesn't do any certificate verification. |
36 */ |
50 */ |
37 err_t sock_gnutls_connect (struct sock_stream **sock_ptr, const char *host, const char *service, struct error_info *err); |
51 err_t sock_gnutls_connect (struct sock_stream **sock_ptr, const char *host, const char *service, struct error_info *err); |
38 |
52 |
39 /* |
53 /* |
|
54 * Set the callbacks for a sock_stream. Note that the callbacks struct isn't copied - it's used as-is-given. |
|
55 */ |
|
56 void sock_stream_set_callbacks (struct sock_stream *sock, const struct sock_stream_callbacks *callbacks, void *arg); |
|
57 |
|
58 /* |
40 * The generic read/write API for stream sockets. |
59 * The generic read/write API for stream sockets. |
41 */ |
60 */ |
42 err_t sock_stream_read (struct sock_stream *sock, void *buf, size_t len); |
61 err_t sock_stream_read (struct sock_stream *sock, void *buf, size_t len); |
43 err_t sock_stream_write (struct sock_stream *sock, const void *buf, size_t len); |
62 err_t sock_stream_write (struct sock_stream *sock, const void *buf, size_t len); |
44 |
63 |