1 #ifndef LINE_PROTO_H |
1 #ifndef LINE_PROTO_H |
2 #define LINE_PROTO_H |
2 #define LINE_PROTO_H |
3 |
3 |
4 /* |
4 /** |
|
5 * @file |
|
6 * |
5 * Support for protocols that send/receive lines |
7 * Support for protocols that send/receive lines |
6 */ |
8 */ |
7 #include "sock.h" |
9 #include "sock.h" |
8 #include "error.h" |
10 #include "error.h" |
9 |
11 |
10 /* |
12 /** |
11 * The state handle |
13 * The line_proto state handle |
12 */ |
14 */ |
13 struct line_proto; |
15 struct line_proto; |
14 |
16 |
15 /* |
17 /** |
16 * The callback for receiving lines |
18 * User callback list |
17 */ |
19 */ |
18 typedef void (*line_proto_read_cb)(char *line, void *arg); |
20 struct line_proto_callbacks { |
|
21 /** Handle received line */ |
|
22 void (*on_line) (char *line, void *arg); |
|
23 |
|
24 }; |
19 |
25 |
20 /** |
26 /** |
21 * Create a new line_proto off the the given sock_stream. The newly allocated line_proto will be returned via *lp_ptr. |
27 * Create a new line_proto off the the given sock_stream. The newly allocated line_proto will be returned via *lp_ptr. |
22 * |
28 * |
23 * The incoming lines are buffered in a buffer of \a buf_size bytes. This imposes a maximum limit on the line length. |
29 * The incoming lines are buffered in a buffer of \a buf_size bytes. This imposes a maximum limit on the line length. |
24 * |
30 * |
25 * The given callback function/argument will be used to provide event-based recv support. |
|
26 * |
|
27 * @param lp_ptr a pointer to the new line_proto will be returned via this pointer |
31 * @param lp_ptr a pointer to the new line_proto will be returned via this pointer |
28 * @param sock the sock_stream to use |
32 * @param sock the sock_stream to use |
29 * @param buf_size the incoming/outgoing buffer size, should be enough to hold the biggest possible line |
33 * @param buf_size the incoming/outgoing buffer size, should be enough to hold the biggest possible line |
30 * @param cb_func the read_cb callback |
34 * @param callbacks the callback struct to use |
31 * @param cb_arg the read_cb callback argument |
35 * @param cb_arg the read_cb callback argument |
32 * @param err error information is returned via this pointer |
36 * @param err error information is returned via this pointer |
33 */ |
37 */ |
34 err_t line_proto_create (struct line_proto **lp_ptr, struct sock_stream *sock, size_t buf_size, |
38 err_t line_proto_create (struct line_proto **lp_ptr, struct sock_stream *sock, size_t buf_size, |
35 line_proto_read_cb cb_func, void *cb_arg, struct error_info *err); |
39 const struct line_proto_callbacks *callbacks, void *cb_arg, struct error_info *err); |
36 |
40 |
37 /** |
41 /** |
38 * Runs the socket recv() into our internal buffer. If a full line was received, a pointer to our internal bufffer is |
42 * Runs the socket recv() into our internal buffer. If a full line was received, a pointer to our internal bufffer is |
39 * returned via *line_ptr, and we return SUCCESS. If we don't yet have a full line, and receiving more would block, |
43 * returned via *line_ptr, and we return SUCCESS. If we don't yet have a full line, and receiving more would block, |
40 * NULL is returned via *line_ptr instead. Otherwise, nonzero error return code. |
44 * NULL is returned via *line_ptr instead. Otherwise, nonzero error return code. |