equal
deleted
inserted
replaced
|
1 #ifndef LIBQMSK_MSG_PROTO_H |
|
2 #define LIBQMSK_MSG_PROTO_H |
|
3 |
|
4 /** |
|
5 * @param |
|
6 * |
|
7 * Support for simple protocols that send/recieve length-prefixed messages over a transport stream. |
|
8 * |
|
9 * This implementation is mostly geared towards handling a reasonable number of reasonably sized messages in a |
|
10 * reasonable way. Hence, |
|
11 */ |
|
12 #include "transport.h" |
|
13 |
|
14 /** |
|
15 * Protocol state struct |
|
16 */ |
|
17 struct msg_proto; |
|
18 |
|
19 /** |
|
20 * User callbacks |
|
21 */ |
|
22 struct msg_proto_callbacks { |
|
23 /** |
|
24 * Message recieved. |
|
25 * |
|
26 * XXX: currently you must not call msg_proto_destroy from within this callback |
|
27 */ |
|
28 void (*on_msg) (struct msg_proto *proto, void *data, size_t len, void *arg); |
|
29 |
|
30 /** |
|
31 * Transport/protocol error occured in event handling. |
|
32 */ |
|
33 void (*on_error) (struct msg_proto *proto, const error_t *err, void *arg); |
|
34 }; |
|
35 |
|
36 /** |
|
37 * Create a msg_proto state using the given transport. |
|
38 * |
|
39 * This will install our callback handlers on the given transport. |
|
40 */ |
|
41 err_t msg_proto_create (struct msg_proto **proto_ptr, transport_t *transport, const struct msg_proto_callbacks *cb_tbl, void *cb_arg, error_t *err); |
|
42 |
|
43 /** |
|
44 * Send a message to the other endpoint |
|
45 */ |
|
46 err_t msg_proto_send (struct msg_proto *proto, const void *data, size_t len, error_t *err); |
|
47 |
|
48 /** |
|
49 * Destroy the protocol state and transport |
|
50 */ |
|
51 void msg_proto_destroy (struct msg_proto *proto); |
|
52 |
|
53 |
|
54 #endif |