18#define WS_BUFFER_SEGMENTS 4
20#define WS_BUFFER_MIN 10
21#define WS_ACCUM_DLY ((TICKS_PER_SECOND / 4) + 1)
22#define WS_FLUSH_TIMEOUT 0
24#define WS_FIN_BIT 0x80
29#define WS_OP_CLOSE 0x8
40 struct WS_Client_Short
46 } __attribute__((packed));
54 } __attribute__((packed));
63 } __attribute__((packed));
64 struct WS_Server_Short
69 } __attribute__((packed));
76 } __attribute__((packed));
84 } __attribute__((packed));
100 static const char *WS_StateStr(WS_State state);
103 WS_STAT_NORM_CLOSE = 1000,
104 WS_STAT_GOING_AWAY = 1001,
105 WS_STAT_PROT_ERROR = 1002,
106 WS_STAT_UNACCEPT_TYPE = 1003,
108 WS_STAT_NONE_ABNORMAL = 1006,
109 WS_STAT_NOT_CONSISTENT = 1007,
110 WS_STAT_POLICY_VIOLATION = 1008,
111 WS_STAT_MSG_TOO_BIG = 1009,
112 WS_STAT_EXPECTED_EXTENSION = 1010,
113 WS_STAT_UNEXPECTED_COND = 1011,
114 WS_STAT_TLS_FAILURE = 1015,
117 fifo_buffer_storage rxBuffer;
118 fifo_buffer_storage ctlBuffer;
119 fifo_buffer_storage txBuffer;
131 bool m_serverNotClient;
133 volatile bool m_CtlBlock;
134 uint32_t m_currentIndex;
137 uint8_t m_frameHeadBuf[14];
138 uint8_t m_frameHeadNext;
140 uint32_t m_currentMask;
141 uint32_t m_remainingLen;
143 uint8_t m_txFrameHeadBuf[14];
144 uint8_t m_txFrameHeadNext;
145 uint8_t m_txFrameHeadLen;
146 uint32_t m_txCurrMask;
148 int m_txFlushInProgress;
149 bool m_txCtlSendInProgress;
151 struct PendingCtlWait {
153 PendingCtlWait *pNext;
155 PendingCtlWait *m_ctlWait;
161 uint32_t m_txBufferMin;
163 void ServerRxFromTCP();
164 bool ReadRemainingHeader();
165 void ProcessCtlFrame();
166 bool ValidatePong(uint32_t seed, uint32_t len);
167 void Close(
bool closedAfterSend, uint16_t code = 0,
const char *reason = NULL,
int len = 0);
171 void Init(
int fd_tcp,
int fd_ws,
bool serverNotClient);
172 void Flush_Header(uint8_t *buf, uint32_t mask, uint32_t len);
174 void AddCtlWait(PendingCtlWait *pWait);
175 void PostToCtlWait();
177 static uint32_t s_flushTick;
178 static fd_set s_pendingCtlSocks;
180 static bool s_bFinishedInit;
182 static void StaticInit();
183 static int GetNewSocket(
int fd_tcp,
bool serverNotClient);
185 static WebSocket *GetRecordFromTCP(
int fd);
187 static int CoreConnect(
IPADDR ip,
const char *host,
const char *resource,
const char *protocol,
int portnum,
bool useSSL =
false);
190 int WriteData(
const char *buf,
int nbytes);
191 int ReadData(
char *buf,
int nbytes);
193 void Pong(uint32_t len);
194 inline WS_State GetState() {
return m_state; }
195 int Ping(uint32_t len, uint32_t *sentTick);
196 int WaitForPingReply(uint32_t timeout);
197 int GetPingReplyTick(uint32_t *replyTick);
199 int setoption(
int option);
200 int clroption(
int option);
203 inline int GetWriteSpace() {
return txBuffer.SpaceAvail(); }
205 static int s_openSocketCount;
206 static WebSocket WSSockStructs[WS_MAX_SOCKS];
208 static int ws_readwto(
int fd,
char *buf,
int nbytes,
int timeout);
209 static int ws_read(
int fd,
char *buf,
int nbytes);
210 static int ws_write(
int fd,
const char *buf,
int nbytes);
211 static int ws_externalclose(
int fd);
212 static void ws_flush(
int fd);
213 static int ws_setoption(
int fd,
int option);
214 static int ws_clroption(
int fd,
int option);
215 static int ws_getoption(
int fd);
217 static WebSocket *GetWebSocketRecord(
int fd);
218 static int promote_tcp_ws(
int tcp_fd);
219 static void ws_read_notify(
int fd);
220 static void ws_write_notify(
int fd);
221 static void GetFlushTime();
223 static void RunSkippedCallBack();
225 static int Connect(
const char * host,
const char * resource,
const char * protocol,
int portnum = 80,
bool useSSL =
false);
226 static inline int Connect(
const char * host,
const char * resource,
int portnum = 80,
bool useSSL =
false)
227 {
return Connect(host, resource, NULL, portnum, useSSL); }
228 static int Connect(
IPADDR host,
const char * resource,
const char * protocol,
int portnum = 80,
bool useSSL =
false);
229 static inline int Connect(
IPADDR host,
const char * resource,
int portnum = 80,
bool useSSL =
false)
230 {
return Connect(host, resource, NULL, portnum, useSSL); }
233 static void DumpSockets();
234 static int GetFreeWebSocketCount();
239int WSPing(
int fd, uint32_t len, uint32_t *sentTick);
240int WSGetPingReplyTick(
int fd, uint32_t *replyTick);
241int WSWaitForPingReply(
int fd, uint32_t timeout);
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
NetBurner HTTP Web Server Header File.
NetBurner I/O System Library API.
NetBurner Real-Time Operating System (NBRTOS) API.
NetBurner IPADDR4 Class. See the IPADDR4 Class page for complete documentation.
HTTP Request Structure.
Definition http.h:69
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at ...
Definition nbrtos.h:1084
Semaphores are used to control access to shared resources or or to communicate between tasks in a mul...
Definition nbrtos.h:386