Line data Source code
1 : #ifndef HEADER_fd_src_ballet_http_fd_http_server_private_h 2 : #define HEADER_fd_src_ballet_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 6 : #define FD_HTTP_SERVER_MAGIC (0xF17EDA2CE50A11D0) /* FIREDANCER HTTP V0 */ 12 : 13 0 : #define FD_HTTP_SERVER_CONNECTION_STATE_READING 0 14 0 : #define FD_HTTP_SERVER_CONNECTION_STATE_WRITING_HEADER 1 15 0 : #define FD_HTTP_SERVER_CONNECTION_STATE_WRITING_BODY 2 16 : 17 0 : #define FD_HTTP_SERVER_PONG_STATE_NONE 0 18 0 : #define FD_HTTP_SERVER_PONG_STATE_WAITING 1 19 0 : #define FD_HTTP_SERVER_PONG_STATE_WRITING 2 20 : 21 0 : #define FD_HTTP_SERVER_SEND_FRAME_STATE_HEADER 0 22 0 : #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 : int recv_last_opcode; 66 : ulong recv_bytes_parsed; 67 : ulong recv_bytes_read; 68 : uchar * recv_bytes; 69 : 70 : int send_frame_state; 71 : ulong send_frame_bytes_written; 72 : ulong send_frame_cnt; 73 : ulong send_frame_idx; 74 : fd_http_server_ws_frame_t * send_frames; 75 : 76 : int compress_websocket; 77 : 78 : /* The treap fields */ 79 : ushort left; 80 : ushort right; 81 : ushort parent; 82 : ushort prio; 83 : ushort prev; 84 : ushort next; 85 : }; 86 : 87 : struct fd_http_server_hcache_private { 88 : int err; /* If there has been an error while printing */ 89 : ulong off; /* Offset into the staging buffer */ 90 : ulong len; /* Length of the staging buffer */ 91 : }; 92 : 93 : struct __attribute__((aligned(FD_HTTP_SERVER_ALIGN))) fd_http_server_private { 94 : 95 : int socket_fd; 96 : 97 : uchar * oring; 98 : ulong oring_sz; 99 : 100 : int compress_websocket; 101 : #if FD_HAS_ZSTD 102 : uchar * zstd_scratch; 103 : ulong zstd_scratch_sz; 104 : ZSTD_CCtx * zstd_ctx; 105 : #endif 106 : 107 : int stage_err; 108 : ulong stage_off; 109 : ulong stage_len; 110 : 111 : /* The server needs to maintain two copies of the data (one 112 : compressed, one uncompressed), since a broadcast message may need 113 : to send compressed data to some clients and uncompressed data to 114 : others. The server will only compress outgoing messages after they 115 : have been fully staged. The memory layout will look like this: 116 : 117 : uncompressed compressed 118 : |------------|----------------|-------------------------|-----| 119 : ^oring ^ ^ ^ 120 : | | | 121 : oring+(stage_off%oring_sz) | | 122 : oring+(stage_off%oring_sz)+stage_len | 123 : oring+(stage_off%oring_sz)+stage_len+stage_comp_len 124 : */ 125 : ulong stage_comp_len; 126 : 127 : ulong max_conns; 128 : ulong max_ws_conns; 129 : ulong max_request_len; 130 : ulong max_ws_recv_frame_len; 131 : ulong max_ws_send_frame_cnt; 132 : 133 : ulong evict_conn_id; 134 : ulong evict_ws_conn_id; 135 : 136 : void * callback_ctx; 137 : fd_http_server_callbacks_t callbacks; 138 : 139 : ulong magic; /* ==FD_HTTP_SERVER_MAGIC */ 140 : 141 : 142 : struct fd_http_server_connection * conns; 143 : struct fd_http_server_ws_connection * ws_conns; 144 : struct pollfd * pollfds; 145 : 146 : void * conn_treap; 147 : void * ws_conn_treap; 148 : 149 : /* The memory for conns and pollfds is placed at the end of the struct 150 : here... 151 : 152 : struct fd_http_server_connection conns[ ]; 153 : struct fd_http_server_ws_connection ws_conns[ ]; 154 : struct pollfd pollfds[ ]; */ 155 : }; 156 : 157 : #endif /* HEADER_fd_src_ballet_http_fd_http_server_private_h */