27 |
27 |
28 // store type |
28 // store type |
29 sock->type = type; |
29 sock->type = type; |
30 } |
30 } |
31 |
31 |
32 void sock_stream_set_callbacks (struct sock_stream *sock, const struct sock_stream_callbacks *callbacks, void *arg) |
32 int sock_stream_read (struct sock_stream *sock, void *buf, size_t len) |
|
33 { |
|
34 err_t err; |
|
35 |
|
36 // proxy off to method handler |
|
37 if ((err = sock->type->methods.read(sock, buf, &len))) |
|
38 return err; |
|
39 |
|
40 // return updated bytes-read len |
|
41 return len; |
|
42 } |
|
43 |
|
44 int sock_stream_write (struct sock_stream *sock, const void *buf, size_t len) |
|
45 { |
|
46 err_t err; |
|
47 |
|
48 // proxy off to method handler |
|
49 if ((err = sock->type->methods.write(sock, buf, &len))) |
|
50 return err; |
|
51 |
|
52 // return updated bytes-written len |
|
53 return len; |
|
54 } |
|
55 |
|
56 err_t sock_stream_event_init (struct sock_stream *sock, const struct sock_stream_callbacks *callbacks, void *arg) |
33 { |
57 { |
34 // store |
58 // store |
35 sock->cb_info = callbacks; |
59 sock->cb_info = callbacks; |
36 sock->cb_arg = arg; |
60 sock->cb_arg = arg; |
|
61 |
|
62 // run method |
|
63 return sock->type->methods.event_init(sock); |
37 } |
64 } |
38 |
65 |
39 err_t sock_stream_read (struct sock_stream *sock, void *buf, size_t len) |
66 err_t sock_stream_event_enable (struct sock_stream *sock, short mask) |
40 { |
67 { |
41 // proxy off to method handler |
68 // run method |
42 return sock->type->methods.read(sock, buf, len); |
69 return sock->type->methods.event_enable(sock, mask); |
43 } |
|
44 |
|
45 err_t sock_stream_write (struct sock_stream *sock, const void *buf, size_t len) |
|
46 { |
|
47 // proxy off to method handler |
|
48 return sock->type->methods.write(sock, buf, len); |
|
49 } |
70 } |
50 |
71 |
51 const struct error_info* sock_stream_error (struct sock_stream *sock) |
72 const struct error_info* sock_stream_error (struct sock_stream *sock) |
52 { |
73 { |
53 // return pointer |
74 // return pointer |