1
1
#ifndef SERVER_H
2
2
#define SERVER_H
3
3
4
+ #include <stdbool.h>
5
+
4
6
/*
5
7
* You should not want to know what is inside those structures.
6
8
*/
@@ -34,7 +36,7 @@ server_t server_init(
34
36
int port ,
35
37
onmessage_callback_t onmessage ,
36
38
onconnect_callback_t onconnect ,
37
- ondisconnect_callback_t ondisconnect ,
39
+ ondisconnect_callback_t ondisconnect
38
40
);
39
41
40
42
/*
@@ -53,17 +55,17 @@ void server_loop(server_t server);
53
55
* 'client'. The server does not care about this data and will not free it on
54
56
* client disconnection.
55
57
*/
56
- void client_set_data (client_t client , void * userdata );
57
- void * client_get_data (client_t client );
58
+ void client_set_userdata (client_t client , void * userdata );
59
+ void * client_get_userdata (client_t client );
58
60
59
61
/*
60
62
* Puts an empty message header into the output buffer of the corresponding
61
63
* socket. The message will not be sent until you call the _finish() method.
62
64
* A call to this function may lead to a send() call if there is not enough
63
65
* space in the buffer.
64
- *
66
+ *
65
67
* Returns 'true' on success, 'false' otherwise.
66
- *
68
+ *
67
69
* NOTE: Be careful not to call the _message_ methods for other clients until
68
70
* you _finish() this message. This limitation is due to the fact that multiple
69
71
* clients share the same socket.
@@ -74,17 +76,25 @@ bool client_message_start(client_t client);
74
76
* Appends 'len' bytes of 'data' to the buffer of the corresponding socket.
75
77
* A call to this function may lead to a send() call if there is not enough
76
78
* space in the buffer.
77
- *
79
+ *
78
80
* Returns 'true' on success, 'false' otherwise.
79
81
*/
80
82
bool client_message_append (client_t client , size_t len , void * data );
81
83
82
84
/*
83
85
* Finalizes the message. After finalizing the message becomes ready to be sent
84
86
* over the corresponding socket, and you may _start() another message.
85
- *
87
+ *
86
88
* Returns 'true' on success, 'false' otherwise.
87
89
*/
88
90
bool client_message_finish (client_t client );
89
91
92
+ /*
93
+ * A shortcut to perform all three steps in one, if you only have one number in
94
+ * the message.
95
+ *
96
+ * Returns 'true' on success, 'false' otherwise.
97
+ */
98
+ bool client_message_shortcut (client_t client , long long arg );
99
+
90
100
#endif
0 commit comments