11#ifndef SERVER_H
22#define SERVER_H
33
4+ #include <stdbool.h>
5+
46/*
57 * You should not want to know what is inside those structures.
68 */
@@ -34,7 +36,7 @@ server_t server_init(
3436 int port ,
3537 onmessage_callback_t onmessage ,
3638 onconnect_callback_t onconnect ,
37- ondisconnect_callback_t ondisconnect ,
39+ ondisconnect_callback_t ondisconnect
3840);
3941
4042/*
@@ -53,17 +55,17 @@ void server_loop(server_t server);
5355 * 'client'. The server does not care about this data and will not free it on
5456 * client disconnection.
5557 */
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 );
5860
5961/*
6062 * Puts an empty message header into the output buffer of the corresponding
6163 * socket. The message will not be sent until you call the _finish() method.
6264 * A call to this function may lead to a send() call if there is not enough
6365 * space in the buffer.
64- *
66+ *
6567 * Returns 'true' on success, 'false' otherwise.
66- *
68+ *
6769 * NOTE: Be careful not to call the _message_ methods for other clients until
6870 * you _finish() this message. This limitation is due to the fact that multiple
6971 * clients share the same socket.
@@ -74,17 +76,25 @@ bool client_message_start(client_t client);
7476 * Appends 'len' bytes of 'data' to the buffer of the corresponding socket.
7577 * A call to this function may lead to a send() call if there is not enough
7678 * space in the buffer.
77- *
79+ *
7880 * Returns 'true' on success, 'false' otherwise.
7981 */
8082bool client_message_append (client_t client , size_t len , void * data );
8183
8284/*
8385 * Finalizes the message. After finalizing the message becomes ready to be sent
8486 * over the corresponding socket, and you may _start() another message.
85- *
87+ *
8688 * Returns 'true' on success, 'false' otherwise.
8789 */
8890bool client_message_finish (client_t client );
8991
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+
90100#endif
0 commit comments