40 |
40 |
41 /** |
41 /** |
42 * An asynchronous error has occured. This is only called for errors that occur while being called directly from |
42 * An asynchronous error has occured. This is only called for errors that occur while being called directly from |
43 * the underlying event loop, and never from inside an API function. |
43 * the underlying event loop, and never from inside an API function. |
44 */ |
44 */ |
45 void (*on_error) (transport_t *transport, error_t *err, void *arg); |
45 void (*on_error) (transport_t *transport, const error_t *err, void *arg); |
|
46 }; |
|
47 |
|
48 /** |
|
49 * Bitmask of available events |
|
50 */ |
|
51 enum transport_event { |
|
52 TRANSPORT_READ = 0x01, |
|
53 TRANSPORT_WRITE = 0x02, |
46 }; |
54 }; |
47 |
55 |
48 /** |
56 /** |
49 * User info required to build a transport |
57 * User info required to build a transport |
50 */ |
58 */ |
52 /** The callbacks table */ |
60 /** The callbacks table */ |
53 const struct transport_callbacks *cb_tbl; |
61 const struct transport_callbacks *cb_tbl; |
54 |
62 |
55 /** The callback context argument */ |
63 /** The callback context argument */ |
56 void *cb_arg; |
64 void *cb_arg; |
|
65 |
|
66 /** Initial event mask using transport_event flags */ |
|
67 short ev_mask; |
57 }; |
68 }; |
58 |
69 |
59 /** |
70 /** |
60 * Read a series of bytes from the transport into the given \a buf (up to \a len bytes). If succesfull, this returns |
71 * Read a series of bytes from the transport into the given \a buf (up to \a len bytes). If succesfull, this returns |
61 * the number of bytes read (which will be less than or equal to \a len). If the transport is nonblocking, and there is |
72 * the number of bytes read (which will be less than or equal to \a len). If the transport is nonblocking, and there is |
62 * no data available, this returns zero, and need not be called again until transport_callbacks::on_read is invoked. |
73 * no data available, this returns zero, and need not be called again until transport_callbacks::on_read is invoked. |
63 * |
74 * |
64 * On errors, this returns the negative error code, and more info via \a err. |
75 * On errors, this returns the negative error code, and more info via \a err. Note that as opposed to read(2), EOF is |
|
76 * handled as an error, returning ERR_EOF. |
65 * |
77 * |
66 * @param transport the transport state |
78 * @param transport the transport state |
67 * @param buf the buffer to read the bytes into |
79 * @param buf the buffer to read the bytes into |
68 * @param len the number of bytes to read into the buffer |
80 * @param len the number of bytes to read into the buffer |
69 * @param err returned error info |
81 * @param err returned error info |
87 * @return bytes written, zero if would have blocked, -err_t |
99 * @return bytes written, zero if would have blocked, -err_t |
88 */ |
100 */ |
89 int transport_write (transport_t *transport, const void *buf, size_t len, error_t *err); |
101 int transport_write (transport_t *transport, const void *buf, size_t len, error_t *err); |
90 |
102 |
91 /** |
103 /** |
|
104 * Change the mask of enabled events |
|
105 */ |
|
106 void transport_events (transport_t *transport, short mask); |
|
107 |
|
108 /** |
92 * Close and destroy the transport immediately, severing any established connection rudely. |
109 * Close and destroy the transport immediately, severing any established connection rudely. |
93 * |
110 * |
94 * This will release all resources associated with the transport, including the transport itself, which must not be |
111 * This will release all resources associated with the transport, including the transport itself, which must not be |
95 * used anymore. |
112 * used anymore. |
96 */ |
113 */ |