2 #include "sock_gnutls.h" |
2 #include "sock_gnutls.h" |
3 |
3 |
4 #include <stdlib.h> |
4 #include <stdlib.h> |
5 #include <err.h> |
5 #include <err.h> |
6 |
6 |
7 static err_t sock_gnutls_read (struct sock_stream *base_sock, void *buf, size_t len) |
7 // XXX: errors |
|
8 static err_t sock_gnutls_read (struct sock_stream *base_sock, void *buf, size_t *len) |
|
9 { |
|
10 struct sock_gnutls *sock = SOCK_FROM_BASE(base_sock, struct sock_gnutls); |
|
11 int ret; |
|
12 |
|
13 // just map to gnutls_record_recv |
|
14 if ((ret = gnutls_record_recv(sock->session, buf, *len)) < 0) |
|
15 RETURN_SET_ERROR_ERRNO(SOCK_GNUTLS_ERR(sock), ERR_GNUTLS_RECORD_RECV); |
|
16 |
|
17 // updated length |
|
18 *len = ret; |
|
19 |
|
20 return SUCCESS; |
|
21 } |
|
22 |
|
23 static err_t sock_gnutls_write (struct sock_stream *base_sock, const void *buf, size_t *len) |
|
24 { |
|
25 struct sock_gnutls *sock = SOCK_FROM_BASE(base_sock, struct sock_gnutls); |
|
26 int ret; |
|
27 |
|
28 // just map to gnutls_record_send |
|
29 if ((ret = gnutls_record_send(sock->session, buf, *len)) < 0) |
|
30 RETURN_SET_ERROR_ERRNO(SOCK_GNUTLS_ERR(sock), ERR_GNUTLS_RECORD_SEND); |
|
31 |
|
32 // updated length |
|
33 *len = ret; |
|
34 |
|
35 return SUCCESS; |
|
36 } |
|
37 |
|
38 static err_t sock_gnutls_event_init (struct sock_stream *base_sock) |
8 { |
39 { |
9 struct sock_gnutls *sock = SOCK_FROM_BASE(base_sock, struct sock_gnutls); |
40 struct sock_gnutls *sock = SOCK_FROM_BASE(base_sock, struct sock_gnutls); |
10 |
41 |
11 // just map to gnutls_record_recv |
42 return SUCCESS; |
12 return gnutls_record_recv(sock->session, buf, len); |
|
13 } |
43 } |
14 |
44 |
15 static err_t sock_gnutls_write (struct sock_stream *base_sock, const void *buf, size_t len) |
45 static err_t sock_gnutls_event_enable (struct sock_stream *base_sock, short mask) |
16 { |
46 { |
17 struct sock_gnutls *sock = SOCK_FROM_BASE(base_sock, struct sock_gnutls); |
47 struct sock_gnutls *sock = SOCK_FROM_BASE(base_sock, struct sock_gnutls); |
18 |
48 |
19 // just map to gnutls_record_send |
49 return SUCCESS; |
20 return gnutls_record_send(sock->session, buf, len); |
|
21 } |
50 } |
22 |
51 |
23 /* |
52 /* |
24 * Our sock_stream_Type |
53 * Our sock_stream_Type |
25 */ |
54 */ |
26 struct sock_stream_type sock_gnutls_type = { |
55 struct sock_stream_type sock_gnutls_type = { |
27 .methods.read = &sock_gnutls_read, |
56 .methods.read = &sock_gnutls_read, |
28 .methods.write = &sock_gnutls_write, |
57 .methods.write = &sock_gnutls_write, |
|
58 .methods.event_init = &sock_gnutls_event_init, |
|
59 .methods.event_enable = &sock_gnutls_event_enable, |
29 }; |
60 }; |
30 |
61 |
31 /* |
62 /* |
32 * XXX: global shared sock_gnutls_ctx |
63 * XXX: global shared sock_gnutls_ctx |
33 */ |
64 */ |