2 * Copyright (C) 2014 Martin Willi
3 * Copyright (C) 2014 revosec AG
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * @defgroup vici_socket vici_socket
21 #ifndef VICI_SOCKET_H_
22 #define VICI_SOCKET_H_
27 * Maximum size of a single message exchanged.
29 #define VICI_MESSAGE_SIZE_MAX (512 * 1024)
31 typedef struct vici_socket_t vici_socket_t
;
34 * Callback function for dispatching inbound client messages.
36 * @param user user data, as passed during registration
37 * @param id unique client connection identifier
38 * @param data incoming message data
40 typedef void (*vici_inbound_cb_t
)(void *user
, u_int id
, chunk_t data
);
43 * Callback function invoked when new clients connect
45 * @param user user data, as passed during registration
46 * @param id unique client connection identifier
47 * @return client connection context
49 typedef void (*vici_connect_cb_t
)(void *user
, u_int id
);
52 * Callback function invoked when connected clients disconnect
54 * @param user user data, as passed during registration
55 * @param id unique client connection identifier
57 typedef void (*vici_disconnect_cb_t
)(void *user
, u_int id
);
60 * Vici socket, low level socket input/output handling.
62 * On the socket, we pass raw chunks having a 2 byte network order length
63 * prefix. The length field does not count the length header itself, and
64 * is not included in the data passed over this interface.
66 struct vici_socket_t
{
69 * Send a message to a client identified by connection identifier.
71 * @param id unique client connection identifier
72 * @param data data to send to client, gets owned
74 void (*send
)(vici_socket_t
*this, u_int id
, chunk_t data
);
79 void (*destroy
)(vici_socket_t
*this);
83 * Create a vici_socket instance.
85 * @param uri socket URI to listen on
86 * @param inbound inbound message callback
87 * @param connect connect callback
88 * @param disconnect disconnect callback
89 * @param user user data to pass to callbacks
91 vici_socket_t
*vici_socket_create(char *uri
, vici_inbound_cb_t inbound
,
92 vici_connect_cb_t connect
,
93 vici_disconnect_cb_t disconnect
, void *user
);
95 #endif /** VICI_SOCKET_H_ @}*/