18 #define WS_BUFFER_SEGMENTS 4 19 #define WS_MAX_SOCKS 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 26 #define WS_OP_CONT 0x0 27 #define WS_OP_TEXT 0x1 29 #define WS_OP_CLOSE 0x8 30 #define WS_OP_PING 0x9 31 #define WS_OP_PONG 0xA 33 #define WS_SO_TEXT 0x8 39 struct WS_Client_Short
45 } __attribute__((packed));
53 } __attribute__((packed));
62 } __attribute__((packed));
63 struct WS_Server_Short
68 } __attribute__((packed));
75 } __attribute__((packed));
83 } __attribute__((packed));
99 static const char * WS_StateStr(WS_State state);
102 WS_STAT_NORM_CLOSE = 1000,
103 WS_STAT_GOING_AWAY = 1001,
104 WS_STAT_PROT_ERROR = 1002,
105 WS_STAT_UNACCEPT_TYPE = 1003,
107 WS_STAT_NONE_ABNORMAL = 1006,
108 WS_STAT_NOT_CONSISTENT = 1007,
109 WS_STAT_POLICY_VIOLATION = 1008,
110 WS_STAT_MSG_TOO_BIG = 1009,
111 WS_STAT_EXPECTED_EXTENSION = 1010,
112 WS_STAT_UNEXPECTED_COND = 1011,
113 WS_STAT_TLS_FAILURE = 1015,
116 fifo_buffer_storage rxBuffer;
117 fifo_buffer_storage ctlBuffer;
118 fifo_buffer_storage txBuffer;
129 bool m_serverNotClient;
131 volatile bool m_CtlBlock;
132 uint32_t m_currentIndex;
135 uint8_t m_frameHeadBuf[14];
136 uint8_t m_frameHeadNext;
138 uint32_t m_currentMask;
139 uint32_t m_remainingLen;
141 uint8_t m_txFrameHeadBuf[14];
142 uint8_t m_txFrameHeadNext;
143 uint8_t m_txFrameHeadLen;
144 uint32_t m_txCurrMask;
146 bool m_txFlushInProgress;
147 bool m_txCtlSendInProgress;
150 uint32_t m_txBufferMin;
152 void ServerRxFromTCP();
153 bool ReadRemainingHeader();
154 void ProcessCtlFrame();
155 void Close(
bool closedAfterSend, uint16_t code = 0,
const char *reason =
NULL,
int len = 0);
159 void Init(
int fd_tcp,
int fd_ws,
bool serverNotClient);
160 void Flush_Header(uint8_t *buf, uint32_t mask, uint32_t len);
162 static uint32_t s_flushTick;
163 static fd_set s_pendingCtlSocks;
165 static bool s_bFinishedInit;
167 static void StaticInit();
168 static int GetNewSocket(
int fd_tcp,
bool serverNotClient);
170 static WebSocket *GetRecordFromTCP(
int fd);
172 static int CoreConnect(
IPADDR ip,
const char *host,
const char *resource,
int portnum,
bool useSSL =
false);
175 int WriteData(
const char *buf,
int nbytes);
176 int ReadData(
char *buf,
int nbytes);
178 void Pong(uint32_t len);
179 inline WS_State GetState() {
return m_state; }
181 int setoption(
int option);
182 int clroption(
int option);
185 inline int GetWriteSpace() {
return txBuffer.SpaceAvail(); }
187 static int s_openSocketCount;
188 static WebSocket WSSockStructs[WS_MAX_SOCKS];
190 static int ws_readwto(
int fd,
char *buf,
int nbytes,
int timeout);
191 static int ws_read(
int fd,
char *buf,
int nbytes);
192 static int ws_write(
int fd,
const char *buf,
int nbytes);
193 static int ws_externalclose(
int fd);
194 static void ws_flush(
int fd);
195 static int ws_setoption(
int fd,
int option);
196 static int ws_clroption(
int fd,
int option);
197 static int ws_getoption(
int fd);
199 static WebSocket *GetWebSocketRecord(
int fd);
200 static int promote_tcp_ws(
int tcp_fd);
201 static void ws_read_notify(
int fd);
202 static void ws_write_notify(
int fd);
203 static void GetFlushTime();
205 static void RunSkippedCallBack();
207 static int Connect(
const char *host,
const char *resource,
int portnum = 80,
bool useSSL =
false);
208 static int Connect(
IPADDR host,
const char *resource,
int portnum = 80,
bool useSSL =
false);
211 static void DumpSockets();
216 int WSUpgrade(HTTP_Request *req,
int sock);
NetBurner Real-Time Operating System API.
NetBurner I/O System Library API.
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition: ipv6_addr.h:28
Semaphores are used to control access to shared resource critical section, or to communicate between ...
Definition: nbrtos.h:318
NetBurner HTTP Web Server Header File.
Definition: dhcpv6_internal.h:34
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at ...
Definition: nbrtos.h:893
#define NULL
Definition: nm_bsp.h:76
void WriteData(int fd, const char *c, int siz)
Definition: gifCompress.cpp:142