Typedefs | |
| typedef struct con_connection_tag | con_connection_s |
| typedef struct con_handler_tag | con_handler_s |
| typedef enum con_close_reason_tag | con_close_reason_e |
| typedef enum con_connect_reason_tag | con_connect_reason_e |
| typedef enum con_upstream_action_tag | con_upstream_action_e |
Enumerations | |
| enum | con_close_reason_tag { CON_CLOSE_ERROR = 0, CON_CLOSE_EOF, CON_CLOSE_TIMEOUT } |
| enum | con_connect_reason_tag { CON_CONNECT_OKAY = 0, CON_CONNECT_DNS_FAILURE, CON_CONNECT_ERROR, CON_CONNECT_TIMEOUT } |
| enum | con_upstream_action_tag { CON_UPSTREAM_CONTINUE = 0, CON_UPSTREAM_CLOSE } |
Functions | |
| bool | con_module_init (void) |
| Initialise the connection module. | |
| void | con_module_close (void) |
| Close the connection module. | |
| con_handler_s * | con_handler_register (const char *name, const unsigned short int port, const unsigned long int maxClients, const int backlog, con_upstream_action_e(*readCb)(con_connection_s *), bool(*acceptCb)(con_connection_s *), void(*closeCb)(con_connection_s *, con_close_reason_e)) |
| Register a new connection handler to listen for. | |
| bool | con_listen (con_handler_s *handler) |
| Start listening on the given connection handler. | |
| void | con_event_loop (void) |
| Start the event loop. | |
| void | con_close_event_loop (void) |
| Close the event loop. | |
| void | con_set_userdata (con_connection_s *connection, void *data) |
| Set the user data of a connection. | |
| void * | con_get_userdata (con_connection_s *connection) |
| Get the user data of a connection. | |
| con_handler_s * | con_get_handler (con_connection_s *connection) |
| Get the connection handler for the given connection. | |
| bool | con_is_connector (const con_connection_s *connection) |
| Returns true if we made this connection. | |
| net_recv_result_e | con_read_data (con_connection_s *connection, void *buffer, const size_t len, size_t *bytesRead) |
| Read data from a connection data structure. | |
| net_send_result_e | con_send_data (con_connection_s *connection, const void *data, const size_t len, size_t *bytesSent) |
| Send data. | |
| size_t | con_send_data_fully (con_connection_s *connection, const void *data, const size_t len) |
| bool | con_connector_register (const char *hostname, const unsigned short int port, const int timeout, con_handler_s *handler, void(*connectCb)(con_connection_s *, con_connect_reason_e), void *userData) |
| Register a new connector. | |
| void | con_close_connection (con_connection_s *connection, con_close_reason_e reason) |
| Called when we want to close/free a connection. | |
| typedef enum con_close_reason_tag con_close_reason_e |
| typedef enum con_connect_reason_tag con_connect_reason_e |
| typedef struct con_connection_tag con_connection_s |
| typedef struct con_handler_tag con_handler_s |
| typedef enum con_upstream_action_tag con_upstream_action_e |
| enum con_close_reason_tag |
| void con_close_connection | ( | con_connection_s * | connection, | |
| con_close_reason_e | reason | |||
| ) |
Called when we want to close/free a connection.
The registered close callback will be called.
| connection | The connection to close. | |
| reason | The reason for the close. |
| void con_close_event_loop | ( | void | ) |
Close the event loop.
| bool con_connector_register | ( | const char * | hostname, | |
| const unsigned short int | port, | |||
| const int | timeout, | |||
| con_handler_s * | handler, | |||
| void(*)(con_connection_s *, con_connect_reason_e) | connectCb, | |||
| void * | userData | |||
| ) |
Register a new connector.
Once the connection is made, the callback will be called.
| hostname | The IPv4, IPv6 or hostname of the server. | |
| port | The port to connect on. | |
| timeout | How long to try to connect before timing out. | |
| handler | The connection handler to use, once the socket is connected. | |
| connectCb | The callback to call on error, or successful connect. | |
| userData | The user-defined data to give the connection (get with con_get_userdata()) |
| void con_event_loop | ( | void | ) |
Start the event loop.
Previously listening handlers will begin to accept connections.
| con_handler_s* con_get_handler | ( | con_connection_s * | connection | ) |
Get the connection handler for the given connection.
| connection | The connection to set the data of. |
| void* con_get_userdata | ( | con_connection_s * | connection | ) |
Get the user data of a connection.
| connection | The connection to set the data of. |
NULL is returned. | con_handler_s* con_handler_register | ( | const char * | name, | |
| const unsigned short int | port, | |||
| const unsigned long int | maxClients, | |||
| const int | backlog, | |||
| con_upstream_action_e(*)(con_connection_s *) | readCb, | |||
| bool(*)(con_connection_s *) | acceptCb, | |||
| void(*)(con_connection_s *, con_close_reason_e) | closeCb | |||
| ) |
Register a new connection handler to listen for.
| name | The name of the connection handler. | |
| port | The port to listen on. | |
| maxClients | The max number of clients to have at any one time. | |
| backlog | How many clients to backlog before accepting them. | |
| readCb | The callback to call when data can be read. | |
| acceptCb | The callback to call when a client connects. If returned false, the client is rejected. Use this callback to set userdata. | |
| closeCb | The callback to call when the connection is closed. |
NULL is returned | bool con_is_connector | ( | const con_connection_s * | connection | ) |
Returns true if we made this connection.
| connection | The connection to check. |
| bool con_listen | ( | con_handler_s * | handler | ) |
Start listening on the given connection handler.
| handler | The handler to bind to and start listening on. |
true on success. On error, false is returned. | void con_module_close | ( | void | ) |
Close the connection module.
Any unclosed handlers are closed.
| bool con_module_init | ( | void | ) |
Initialise the connection module.
This should be called before any other functions.
true on success. On error, false is returned | net_recv_result_e con_read_data | ( | con_connection_s * | connection, | |
| void * | buffer, | |||
| const size_t | len, | |||
| size_t * | bytesRead | |||
| ) |
Read data from a connection data structure.
| connection | The connection. | |
| buffer | Where to put the data. | |
| len | The number of bytes to read. | |
| bytesRead | Where to record how many bytes were read. |
net_recv_result_e value | net_send_result_e con_send_data | ( | con_connection_s * | connection, | |
| const void * | data, | |||
| const size_t | len, | |||
| size_t * | bytesSent | |||
| ) |
Send data.
| connection | The connection to send on. | |
| data | The data to send. | |
| len | The length of the data. | |
| bytesSent | Where to record how many bytes were sent. |
| size_t con_send_data_fully | ( | con_connection_s * | connection, | |
| const void * | data, | |||
| const size_t | len | |||
| ) |
| void con_set_userdata | ( | con_connection_s * | connection, | |
| void * | data | |||
| ) |
Set the user data of a connection.
| connection | The connection to set the data of. | |
| data | The userdata to set. |
1.6.2