-
Notifications
You must be signed in to change notification settings - Fork 253
Transports
libonion has two builtin transports: SSL and plain text, both over TCP/IP (both IPv4 and IPv6). Given the nature of libonion other transports can be added, for example stdin/stdout for inet daemons, or other SSL libraries.
Normally all use of libonion is more or less through an onion
object, but this is just the entry point for the default transports. If you want to implement you own transport you should use the onion_server
object.
It must be created with onion_server_new
and there are several setting functions.
onion_server_set_write(onion_server *server, onion_write write_function);
The write function needs to be with the signature: write(void *private_data, const char *data, unsigned int length);
. The private data is passed later for each request, and allows to write to the right place. For example on the standard TCP/IP handler is just the file descriptor as given by the accept(...)
socket function.
On your program you must create the requests, with onion_request_new(onion_server *server, void *private_data)
. It creates the request object on which to write the data, and sets the private_data to be given to your write function.
Now on every bit of data you have available you must write it to the request with int onion_request_write(onion_request *request, const char *data, unsigned int length);
this function will fill the request as needed and process it when ready. On every bit of data wrote it returns the status of the request. Normally >= 0 means you can continue writing, and <0 that there was any error and connection should be closed.
The request can be on keep-alive mode, which means that the connection should be closed only on some specific conditions: no length set, not using chunk encoding, requested by user... All this is handled by libonion internally and should not be a concern.
Just filling the request will trigger the response processing, calling the proper handlers according to headers and path.