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-08-13 04:56:22 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             : #if FD_HAS_ZSTD
       7             : #define ZSTD_STATIC_LINKING_ONLY
       8             : #include <zstd.h>
       9             : #endif
      10             : 
      11          39 : #define FD_HTTP_SERVER_MAGIC (0xF17EDA2CE50A11D0) /* FIREDANCER HTTP V0 */
      12             : 
      13          51 : #define FD_HTTP_SERVER_CONNECTION_STATE_READING        0
      14          51 : #define FD_HTTP_SERVER_CONNECTION_STATE_WRITING_HEADER 1
      15           3 : #define FD_HTTP_SERVER_CONNECTION_STATE_WRITING_BODY   2
      16             : 
      17          27 : #define FD_HTTP_SERVER_PONG_STATE_NONE    0
      18           6 : #define FD_HTTP_SERVER_PONG_STATE_WAITING 1
      19           3 : #define FD_HTTP_SERVER_PONG_STATE_WRITING 2
      20             : 
      21          15 : #define FD_HTTP_SERVER_SEND_FRAME_STATE_HEADER 0
      22           6 : #define FD_HTTP_SERVER_SEND_FRAME_STATE_DATA   1
      23             : 
      24             : struct fd_http_server_connection {
      25             :   int          state;
      26             : 
      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             : 
      35             :   fd_http_server_response_t response;
      36             :   ulong response_bytes_written;
      37             : 
      38             :   /* The treap fields */
      39             :   ushort left;
      40             :   ushort right;
      41             :   ushort parent;
      42             :   ushort prio;
      43             :   ushort prev;
      44             :   ushort next;
      45             : 
      46             :   /* The memory for the request is placed at the end of the struct here...
      47             :   char request[ ]; */
      48             : };
      49             : 
      50             : struct fd_http_server_ws_frame {
      51             :   ulong off;
      52             :   ulong len;
      53             :   int compressed;
      54             : };
      55             : 
      56             : typedef struct fd_http_server_ws_frame fd_http_server_ws_frame_t;
      57             : 
      58             : struct fd_http_server_ws_connection {
      59             :   int   pong_state;
      60             :   ulong pong_data_len;
      61             :   uchar pong_data[ 125 ];
      62             :   ulong pong_bytes_written;
      63             : 
      64             :   int     recv_started_msg;
      65             :   ulong   recv_bytes_parsed;
      66             :   ulong   recv_bytes_read;
      67             :   uchar * recv_bytes;
      68             : 
      69             :   int                         send_frame_state;
      70             :   ulong                       send_frame_bytes_written;
      71             :   ulong                       send_frame_cnt;
      72             :   ulong                       send_frame_idx;
      73             :   fd_http_server_ws_frame_t * send_frames;
      74             : 
      75             :   int compress_websocket;
      76             : 
      77             :   /* The treap fields */
      78             :   ushort left;
      79             :   ushort right;
      80             :   ushort parent;
      81             :   ushort prio;
      82             :   ushort prev;
      83             :   ushort next;
      84             : };
      85             : 
      86             : struct fd_http_server_hcache_private {
      87             :   int   err; /* If there has been an error while printing */
      88             :   ulong off; /* Offset into the staging buffer */
      89             :   ulong len; /* Length of the staging buffer */
      90             : };
      91             : 
      92             : struct __attribute__((aligned(FD_HTTP_SERVER_ALIGN))) fd_http_server_private {
      93             : 
      94             :   int   socket_fd;
      95             : 
      96             :   uchar * oring;
      97             :   ulong   oring_sz;
      98             : 
      99             :   int compress_websocket;
     100             : #if FD_HAS_ZSTD
     101             :   uchar * zstd_scratch;
     102             :   ulong   zstd_scratch_sz;
     103             :   ZSTD_CCtx * zstd_ctx;
     104             : #endif
     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             : 
     132             :   ulong evict_conn_id;
     133             :   ulong evict_ws_conn_id;
     134             : 
     135             :   ulong poll_conn_idx; /* Next connection index to consider for service */
     136             : 
     137             :   void * callback_ctx;
     138             :   fd_http_server_callbacks_t callbacks;
     139             : 
     140             :   struct fd_http_server_connection *    conns;
     141             :   struct fd_http_server_ws_connection * ws_conns;
     142             :   struct pollfd *                       pollfds;
     143             : 
     144             :   void * conn_treap;
     145             :   void * ws_conn_treap;
     146             : 
     147             :   struct {
     148             :     ulong connection_cnt;
     149             :     ulong ws_connection_cnt;
     150             : 
     151             :     ulong bytes_written;
     152             :     ulong bytes_read;
     153             : 
     154             :     ulong frames_written;
     155             :     ulong frames_read;
     156             :   } metrics;
     157             : 
     158             :   ulong magic;      /* ==FD_HTTP_SERVER_MAGIC */
     159             : 
     160             :   /* The memory for conns and pollfds is placed at the end of the struct
     161             :      here...
     162             : 
     163             :   struct fd_http_server_connection    conns[ ];
     164             :   struct fd_http_server_ws_connection ws_conns[ ];
     165             :   struct pollfd                       pollfds[ ]; */
     166             : };
     167             : 
     168             : #endif /* HEADER_fd_src_waltz_http_fd_http_server_private_h */

Generated by: LCOV version 1.14