A simple library which can be used to write a web server.
- For all methods with
bool failed_req = false
as the final parameter, this basically indicates this event failed, so use this to handle clean up operations - A
client_num
refers to a socket or any sort of file descriptor that is being used - To use network server methods with your own fd, use the pass to network server method to get a clinet number to work with
- First you make a new
eventfd
witheventfd_open()
- Then you prepare an event with some information using
eventfd_prepare(pfd, additional_info)
- Then you trigger it, and the callback will be called using
eventfd_trigger(pfd)
- Used with any
client_num
, same as normalread
,write
,writev
,reav
andclose
calls
http_write
andhttp_writev
for writing to a HTTP client, andhttp_close
for closing when neededhttp_send_file
, is a special request, regardless of error outcome, it will always give a response in thehttp_writev_callback
, it basically tries sending a file to the client. You pass the http request object to it, which it will use to send the appropriate file range.- The enum
HTTP_POST_READ
is specifically used for reading POST data
websocket_write
,websocket_writev
for writing to a websocket client andwebsocket_close
for closing a websocket clientwebsocket_broadcast
to broadcast to allclient_num
s in the passed container
void accept_callback(int client_num)
:- Called when a new client is accepted
void event_trigger_callback(int client_num, uint64_t additional_info)
:- Called when a custom event is triggered, the second parameter contains information you passed when you called
eventfd_prepare(...)
- Called when a custom event is triggered, the second parameter contains information you passed when you called
void event_error_close_callback(int client_num, uint64_t additional_info)
:- Called in the off chance there is an error with after you called
eventfd_prepare(...)
, so do any cleanup required here
- Called in the off chance there is an error with after you called
- Raw, as in, not HTTP or websocket opened by the network server, they could still be a network socket of some sort, but you have to manage it
void raw_read_callback(buff_data data, int client_num, bool failed_req = false)
:- Called after something has been read from a client
void raw_readv_callback(struct iovec *data, size_t num_iovecs, int client_num, bool failed_req = false)
:- Called after something was read using
readv
,iovecs
contain the required data
- Called after something was read using
void raw_write_callback(buff_data data, int client_num, bool failed_req = false)
:- Called when something is written
void raw_writev_callback(struct iovec *data, size_t num_iovecs, int client_num, bool failed_req = false)
:- Called when something is written using
writev
- Called when something is written using
void raw_close_callback(int client_num)
:- Called when the client is closed, deal with cleanup
void websocket_read_callback(buff_data data, int client_num, bool failed_req = false)
:- Something read from a websocket
void websocket_write_callback(buff_data data, int client_num, bool failed_req = false)
:- Something was written to a websocket
void websocket_writev_callback(struct iovec *data, size_t num_iovecs, int client_num, bool failed_req = false)
:- Something was written to a websocket using
writev
- Something was written to a websocket using
void websocket_close_callback(int client_num)
:- A websocket was closed, deal with cleanup
void http_read_callback(http_request req, int client_num, bool failed_req = false)
:- Something was read from a HTTP connected client
void http_write_callback(buff_data data, int client_num, bool failed_req = false)
:- Something was written to a HTTP connected client (connection will be closed after this)
void http_writev_callback(struct iovec *data, size_t num_iovecs, int client_num, bool failed_req = false)
:- Something was written using
writev
to a HTTP client
- Something was written using
void http_close_callback(int client_num)
:- The client was closed, deal with cleanup
- fix the errors in errors.txt (buffer overflow, leaking FDs)
- fix freeing task IDs, since can only seem to avoid errors by not enabling freeing them
- fix LRU cache, enable it by going to http_send_file.cpp:81
- appears to be issue with unlocking items, and potentially a memory leak
- add in unit test for rest of network server, aim for >=80% branch coverage and ~100% line coverage
- add in TLS support
- The network server should be able to load in the
event_manager
library dynamically, instantiate it, start it, and replace an older version with a newer version. - Similarly the application stuff should be able to do the same for the
network_server
.- This is just a thought for later.
- websocket negotiation
- websocket unpacking frames
- websocket packing frames
- websocket broadcasts, add another task_type which is basically reference counter
- and find out how to constrain ranges container to containers storing ints
- Unless a bunch of operations MUST happen at once (i.e if a single failure means all of them should fail), use the
submit_*
functions rather thanqueue_*
and thensubmit_*
Run gdb then run nsdebug
to run a couple of convenient commands
define nsdebug
handle SIGPIPE nostop noprint pass
set breakpoint pending on
shell ./compile.sh
file build/example/network_server_example
run
bt