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

Generated by: LCOV version 1.14