code cleanup & fix compile with pico-sdk 2.2.0
This commit is contained in:
+23
-1
@@ -22,6 +22,21 @@ static tWSOpenHandler ws_open_cb = NULL;
|
||||
static struct ws_state * ws_connections;
|
||||
static uint8_t ws_num_conns = 0;
|
||||
|
||||
static struct ws_state* ws_state_alloc(void);
|
||||
static void ws_state_init(struct ws_state *wss);
|
||||
static void ws_state_free(struct ws_state *wss);
|
||||
static void ws_server_init_pcb( struct altcp_pcb *pcb, uint16_t port);
|
||||
static err_t ws_accept(void *arg, struct altcp_pcb *pcb, err_t err);
|
||||
static err_t ws_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t err);
|
||||
static err_t ws_sent(void *arg, struct altcp_pcb *pcb, uint16_t len);
|
||||
static void ws_err (void *arg, err_t err);
|
||||
static err_t ws_close_conn(struct altcp_pcb *pcb, struct ws_state *wss);
|
||||
static err_t ws_close_or_abort_conn(struct altcp_pcb *pcb, struct ws_state *wss, uint8_t abort_conn);
|
||||
static err_t ws_poll(void *arg, struct altcp_pcb *pcb);
|
||||
static err_t ws_handshake(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p);
|
||||
static err_t ws_read(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p);
|
||||
static err_t ws_send(struct ws_state *wss, uint8_t *data, uint16_t len);
|
||||
|
||||
// allocate memory for ws_state instance
|
||||
static struct ws_state * ws_state_alloc(void) {
|
||||
struct ws_state *ret = WS_ALLOC_WS_STATE();
|
||||
@@ -338,6 +353,7 @@ static err_t ws_read(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p
|
||||
uint8_t masked = data[1] & 0x80;
|
||||
uint16_t msg_len = data[1] & 0x7F;
|
||||
uint8_t *msg;
|
||||
|
||||
switch (msg_len) {
|
||||
case 126: // next two bytes are length
|
||||
memcpy(&msg_len, &data[2], 2);
|
||||
@@ -347,7 +363,8 @@ static err_t ws_read(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p
|
||||
break;
|
||||
case 127: // next four bytes are length
|
||||
// lwIP's pbuf only handles 16-bit lengths, so error
|
||||
return ERR_ARG;
|
||||
LWIP_DEBUGF(WS_DEBUG, ("ws_read: received 64-bit length %u\n", msg_len));
|
||||
return ERR_MEM;
|
||||
|
||||
//memcpy(&msg_len, &data[2], 4);
|
||||
//if (len >= 10) {
|
||||
@@ -387,6 +404,11 @@ static err_t ws_read(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
}
|
||||
|
||||
if (buf_len + msg_len > WS_BUFFER_SIZE) {
|
||||
LWIP_DEBUGF(WS_DEBUG, ("ws_read: message exceeds buffer size %u+%u\n", buf_len, msg_len));
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
memcpy(&buf[buf_len], msg, msg_len);
|
||||
buf_len += msg_len;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user