LCOV - code coverage report
Current view: top level - waltz/http - fd_http_server_private.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 9 9 100.0 %
Date: 2026-09-17 04:28:31 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_waltz_http_fd_http_server_private_h
       2             : #define HEADER_fd_src_waltz_http_fd_http_server_private_h
       3             : 
       4             : #include "fd_http_server.h"
       5             : 
       6             : #define ZSTD_STATIC_LINKING_ONLY
       7             : #include <zstd.h>
       8             : 
       9          66 : #define FD_HTTP_SERVER_MAGIC (0xF17EDA2CE50A11D0) /* FIREDANCER HTTP V0 */
      10             : 
      11        1083 : #define FD_HTTP_SERVER_CONNECTION_STATE_READING        0
      12         639 : #define FD_HTTP_SERVER_CONNECTION_STATE_WRITING_HEADER 1
      13         594 : #define FD_HTTP_SERVER_CONNECTION_STATE_WRITING_BODY   2
      14             : 
      15         114 : #define FD_HTTP_SERVER_PONG_STATE_NONE    0
      16           6 : #define FD_HTTP_SERVER_PONG_STATE_WAITING 1
      17           3 : #define FD_HTTP_SERVER_PONG_STATE_WRITING 2
      18             : 
      19          18 : #define FD_HTTP_SERVER_SEND_FRAME_STATE_HEADER 0
      20           6 : #define FD_HTTP_SERVER_SEND_FRAME_STATE_DATA   1
      21             : 
      22             : struct fd_http_server_connection {
      23             :   int          state;
      24             : 
      25             :   int          keep_alive;
      26             :   int          upgrade_websocket;
      27             :   int          compress_websocket;
      28             :   ulong        request_bytes_len;
      29             :   char const * sec_websocket_key;
      30             : 
      31             :   char * request_bytes;
      32             :   ulong  request_bytes_read;
      33             :   ulong  request_bytes_off;
      34             :   ulong  request_consumed;
      35             :   ulong  request_expected_len; /* header+body length once the headers parsed, 0 while incomplete */
      36             : 
      37             :   fd_http_server_response_t response;
      38             :   ulong response_bytes_written;
      39             : 
      40             :   /* The treap fields */
      41             :   ushort left;
      42             :   ushort right;
      43             :   ushort parent;
      44             :   ushort prio;
      45             :   ushort prev;
      46             :   ushort next;
      47             : 
      48             :   /* The memory for the request is placed at the end of the struct here...
      49             :   char request[ ]; */
      50             : };
      51             : 
      52             : struct fd_http_server_ws_frame {
      53             :   ulong off;
      54             :   ulong len;
      55             :   int compressed;
      56             : };
      57             : 
      58             : typedef struct fd_http_server_ws_frame fd_http_server_ws_frame_t;
      59             : 
      60             : struct fd_http_server_ws_connection {
      61             :   int   pong_state;
      62             :   ulong pong_data_len;
      63             :   uchar pong_data[ 125 ];
      64             :   ulong pong_bytes_written;
      65             : 
      66             :   int     recv_started_msg;
      67             :   ulong   recv_bytes_parsed;
      68             :   ulong   recv_bytes_read;
      69             :   uchar * recv_bytes;
      70             : 
      71             :   int                         send_frame_state;
      72             :   ulong                       send_frame_bytes_written;
      73             :   ulong                       send_frame_cnt;
      74             :   ulong                       send_frame_idx;
      75             :   fd_http_server_ws_frame_t * send_frames;
      76             : 
      77             :   int compress_websocket;
      78             : 
      79             :   /* The treap fields */
      80             :   ushort left;
      81             :   ushort right;
      82             :   ushort parent;
      83             :   ushort prio;
      84             :   ushort prev;
      85             :   ushort next;
      86             : };
      87             : 
      88             : struct fd_http_server_hcache_private {
      89             :   int   err; /* If there has been an error while printing */
      90             :   ulong off; /* Offset into the staging buffer */
      91             :   ulong len; /* Length of the staging buffer */
      92             : };
      93             : 
      94             : struct __attribute__((aligned(FD_HTTP_SERVER_ALIGN))) fd_http_server_private {
      95             : 
      96             :   int   socket_fd;
      97             : 
      98             :   uchar * oring;
      99             :   ulong   oring_sz;
     100             : 
     101             :   int compress_websocket;
     102             :   uchar * zstd_scratch;
     103             :   ulong   zstd_scratch_sz;
     104             :   ZSTD_CCtx * zstd_ctx;
     105             : 
     106             :   int   stage_err;
     107             :   ulong stage_off;
     108             :   ulong stage_len;
     109             : 
     110             :   /* The server needs to maintain two copies of the data (one
     111             :      compressed, one uncompressed), since a broadcast message may need
     112             :      to send compressed data to some clients and uncompressed data to
     113             :      others.  The server will only compress outgoing messages after they
     114             :      have been fully staged. The memory layout will look like this:
     115             : 
     116             :                      uncompressed           compressed
     117             :      |------------|----------------|-------------------------|-----|
     118             :      ^oring       ^                ^                         ^
     119             :                   |                |                         |
     120             :      oring+(stage_off%oring_sz)    |                         |
     121             :                        oring+(stage_off%oring_sz)+stage_len  |
     122             :                                  oring+(stage_off%oring_sz)+stage_len+stage_comp_len
     123             :   */
     124             :   ulong stage_comp_len;
     125             : 
     126             :   ulong max_conns;
     127             :   ulong max_ws_conns;
     128             :   ulong max_request_len;
     129             :   ulong max_ws_recv_frame_len;
     130             :   ulong max_ws_send_frame_cnt;
     131             :   ulong send_buffer_sz;
     132             : 
     133             :   ulong evict_conn_id;
     134             :   ulong evict_ws_conn_id;
     135             : 
     136             :   int epoll_fd;
     137             : 
     138             :   void * callback_ctx;
     139             :   fd_http_server_callbacks_t callbacks;
     140             : 
     141             :   struct fd_http_server_connection *    conns;
     142             :   struct fd_http_server_ws_connection * ws_conns;
     143             :   struct pollfd *                       pollfds;
     144             : 
     145             :   void * conn_treap;
     146             :   void * ws_conn_treap;
     147             : 
     148             :   struct {
     149             :     ulong connection_cnt;
     150             :     ulong ws_connection_cnt;
     151             : 
     152             :     ulong bytes_written;
     153             :     ulong bytes_read;
     154             : 
     155             :     ulong frames_written;
     156             :     ulong frames_read;
     157             :   } metrics;
     158             : 
     159             :   ulong magic;      /* ==FD_HTTP_SERVER_MAGIC */
     160             : 
     161             :   /* The memory for conns and pollfds is placed at the end of the struct
     162             :      here...
     163             : 
     164             :   struct fd_http_server_connection    conns[ ];
     165             :   struct fd_http_server_ws_connection ws_conns[ ];
     166             :   struct pollfd                       pollfds[ ]; */
     167             : };
     168             : 
     169             : #endif /* HEADER_fd_src_waltz_http_fd_http_server_private_h */

Generated by: LCOV version 1.14