Skip to content
Maru Berezin edited this page Feb 15, 2018 · 1 revision

This week was all about re-reading code, re-designing structures and re-writing code...

  • The first prototype was OK to test the nghttp2 library.

  • But each stream needs independent buffers for reading and writing (it was all handled by a unique read/write_buffer in MHD_Connection). Both reading and writing frames are events handled by the event loop. They need to be registered in order to be "executed".

    The state machines in MHD:

    1. HTTP states: - HTTP1 connections have request and response states (enum MHD_CONNECTION_STATE) - We added MHD_CONNECTION_HTTP2_... states for HTTP2 connections.

      • MHD_CONNECTION_HTTP2_INIT: initial state of the connection. Prefaces had not been received or sent.
      • MHD_CONNECTION_HTTP2_OPEN: open connection, client and server prefaces have been exchanged.
      • MHD_CONNECTION_HTTP2_CLOSED_REMOTE, MHD_CONNECTION_HTTP2_CLOSED_LOCAL: client or server, respectively, sent a GOAWAY frame. Connection is half-closed.
      • MHD_CONNECTION_HTTP2_CLOSED: connection is closed.
      • MHD_CONNECTION_HTTP2_IN_CLEANUP: connection is finished, needs to be freed.
    2. Event loop states: - MHD_EVENT_LOOP_INFO_WRITE: fired when sending the server preface and after reading client frames (e.g. Settings, Header). - MHD_EVENT_LOOP_INFO_READ: normal (idle) state.

    MHD_connection_update_event_loop_info (struct MHD_Connection *connection) function updates the event loop state in HTTP/1. For HTTP/2, this is done directly after reading frames (next state is WRITE) and after writing frames (next state is READ).

  • I will postpone the separation between the HTTP connection and the protocol version used by it. Right now, the http2 functions for the connection states read, write, and idle (not sure what can be done here...) are called and the HTTP1 code was left in the MHD_connection_handle_xxxx functions. It's not the most elegant solution, but this way, the file connection.c has only a few modifications.

  • What is changing?

    • Information hiding: what is visible? what is private?

      • Visible:
        • MHD_http2_session_start
        • MHD_http2_session_delete
        • MHD_http2_handle_read
        • MHD_http2_handle_write
        • MHD_http2_handle_idle
      • Private:
        • All interaction with nghttp2 library. The client application only sees the incoming requests (unaware of the protocol used) and responds to them.
    • Resource management:

      • Memory: both for reading and writing frames
      • Shared information, sockets: stored in MHD_Connection.

What I learned this week, equivalent system calls:

  • read(fd, buf, len) == recv(fd, buf, len, 0)
  • write(fd, buf, len) == send(fd, buf, len, 0)
Clone this wiki locally