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 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 : /* Absolute ring offset up to which the message being staged has 111 : already evicted the connections in its way; reset when it is 112 : committed or dropped. */ 113 : ulong stage_reserved_end; 114 : 115 : /* The server needs to maintain two copies of the data (one 116 : compressed, one uncompressed), since a broadcast message may need 117 : to send compressed data to some clients and uncompressed data to 118 : others. The server will only compress outgoing messages after they 119 : have been fully staged. The memory layout will look like this: 120 : 121 : uncompressed compressed 122 : |------------|----------------|-------------------------|-----| 123 : ^oring ^ ^ ^ 124 : | | | 125 : oring+(stage_off%oring_sz) | | 126 : oring+(stage_off%oring_sz)+stage_len | 127 : oring+(stage_off%oring_sz)+stage_len+stage_comp_len 128 : */ 129 : ulong stage_comp_len; 130 : 131 : ulong max_conns; 132 : ulong max_ws_conns; 133 : ulong max_request_len; 134 : ulong max_ws_recv_frame_len; 135 : ulong max_ws_send_frame_cnt; 136 : ulong send_buffer_sz; 137 : 138 : ulong evict_conn_id; 139 : ulong evict_ws_conn_id; 140 : 141 : int epoll_fd; 142 : 143 : void * callback_ctx; 144 : fd_http_server_callbacks_t callbacks; 145 : 146 : struct fd_http_server_connection * conns; 147 : struct fd_http_server_ws_connection * ws_conns; 148 : struct pollfd * pollfds; 149 : 150 : void * conn_treap; 151 : void * ws_conn_treap; 152 : 153 : struct { 154 : ulong connection_cnt; 155 : ulong ws_connection_cnt; 156 : 157 : ulong bytes_written; 158 : ulong bytes_read; 159 : 160 : ulong frames_written; 161 : ulong frames_read; 162 : } metrics; 163 : 164 : ulong magic; /* ==FD_HTTP_SERVER_MAGIC */ 165 : 166 : /* The memory for conns and pollfds is placed at the end of the struct 167 : here... 168 : 169 : struct fd_http_server_connection conns[ ]; 170 : struct fd_http_server_ws_connection ws_conns[ ]; 171 : struct pollfd pollfds[ ]; */ 172 : }; 173 : 174 : #endif /* HEADER_fd_src_waltz_http_fd_http_server_private_h */