-
Notifications
You must be signed in to change notification settings - Fork 6
Week 2
Maru Berezin edited this page Feb 15, 2018
·
3 revisions
This week was all about MHD code analysis and design of the new API.
-
function MHD_start_daemon_va: starts the web server
- Parses options
parse_options_va()
- (if https) Initializes HTTPS certificates
-
bind()
s andlisten()
s - Creates the thread that runs the epoll/poll/select loop (until the daemon is explicitly shut down)
- Parses options
-
In the event processing function, the following functions are called:
-
MHD_accept_connection
:accept()
s an incoming connection. -
internal_add_connection
: creates an MHD_Connection object, set the receive and send callbacks (see next item), and inserts the connection in the connections list. -
MHD_set_http_callbacks_
/MHD_set_https_callbacks
: set recv_cls and send_cls callbacks, functions for reading requests and writing responses:- http:
recv_param_adapter
,send_param_adapter
- https:
recv_tls_adapter
,send_tls_adapter
- http:
-
-
Connection handlers (both HTTP and HTTPS):
-
MHD_connection_handle_read
: reads data from socket to read_buffer by callingrecv_cls
. -
MHD_connection_handle_idle
: parses data from read_buffer. Expects HTTP/1 syntax. -
MHD_connection_handle_write
: writes data to socket by callingsend_cls
-
These are the different states that a connection can be in:
Connection state: Request
Connection state: Response
List inspired by The practice of programming:
- Interfaces: what services and access are provided?
- connection_http2.c: handles a single HTTP/2 connection (session), with its own streams, frames, flow control, prioritization and server push services. Defines its own MHD_connection_handle_read, MHD_connection_handle_idle and MHD_connection_handle_write HTTP2 functions.
- Information hiding: what is visible? what is private?
- Visible: same API as in connection.h:
- MHD_set_http_callbacks_
- MHD_connection_handle_read
- MHD_connection_handle_write
- MHD_connection_handle_idle
- MHD_connection_mark_closed_
- MHD_connection_close_
- MHD_connection_finish_forward_
- MHD_connection_epoll_update_
- MHD_update_last_activity_
- Private:
- Session (connection) data
- Streams: add, remove from session (stored in a DLL)
- Set
nghttp2_session_callbacks
- Send and receive data from nghttp2 library
- Visible: same API as in connection.h:
- Resource management: memory, shared information, sockets.
- As in connection.c
- Error handling: detect, report, how? Recovery.
- As in connection.c