2 #define SOCK_H |
2 #define SOCK_H |
3 |
3 |
4 /* |
4 /* |
5 * Low-level socket-related functions |
5 * Low-level socket-related functions |
6 */ |
6 */ |
|
7 #include "error.h" |
7 #include <sys/types.h> |
8 #include <sys/types.h> |
8 |
9 |
9 /* |
10 /* |
10 * The generic socket handle |
11 * The generic socket handle |
11 */ |
12 */ |
12 struct sock_stream; |
13 struct sock_stream; |
13 |
14 |
14 /* |
15 /* |
15 * A simple blocking TCP connect to the given host/service, using getaddrinfo. |
16 * Initialize the socket module's global state. Call this before calling any other sock_* functions. |
|
17 */ |
|
18 err_t sock_init (void); |
|
19 |
|
20 /* |
|
21 * 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 |
|
23 * |
|
24 * @return zero on success, nonzero on error |
16 * |
25 * |
17 * XXX: blocking |
26 * XXX: blocking |
18 * XXX: exits on error |
|
19 * |
|
20 * Returns the socket handle. |
|
21 */ |
27 */ |
22 struct sock_stream *sock_tcp_connect (const char *host, const char *service); |
28 err_t sock_tcp_connect (struct sock_stream **sock_ptr, const char *host, const char *service, struct error_info *err); |
23 |
29 |
24 /* |
30 /* |
25 * A simple blocking SSL connect to the given host/service. |
31 * A simple blocking SSL connect to the given host/service. |
26 * |
32 * |
27 * XXX: blocking |
33 * XXX: blocking |
28 * XXX: doesn't do any certificate verification. |
34 * XXX: doesn't do any certificate verification. |
29 * XXX: exits on error |
35 * XXX: exits on error |
30 * |
36 * |
31 * Returns the socket handle. |
37 * Returns the socket handle, or NULL on errors. |
32 */ |
38 */ |
33 struct sock_stream *sock_ssl_connect (const char *host, const char *service); |
39 struct sock_stream *sock_ssl_connect (const char *host, const char *service); |
34 |
40 |
35 /* |
41 /* |
36 * Initialize the socket module's global state |
|
37 */ |
|
38 void sock_init (void); |
|
39 |
|
40 /* |
|
41 * The generic read/write API for stream sockets. |
42 * The generic read/write API for stream sockets. |
42 */ |
43 */ |
43 int sock_stream_read (struct sock_stream *sock, void *buf, size_t len); |
44 err_t sock_stream_read (struct sock_stream *sock, void *buf, size_t len); |
44 int sock_stream_write (struct sock_stream *sock, const void *buf, size_t len); |
45 err_t sock_stream_write (struct sock_stream *sock, const void *buf, size_t len); |
|
46 |
|
47 /** |
|
48 * Get last err_info for \a sock, returned via \a *err. |
|
49 */ |
|
50 void sock_stream_error (struct sock_stream *sock, struct error_info *err); |
45 |
51 |
46 #endif |
52 #endif |