|
Lines 263-269
int ws_handshake_kvp(wsh_t *wsh, char *key, char *version, char *proto)
Link Here
|
| 263 |
|
263 |
|
| 264 |
} |
264 |
} |
| 265 |
|
265 |
|
| 266 |
issize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes) |
266 |
static issize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes, bool *timed_out) |
| 267 |
{ |
267 |
{ |
| 268 |
issize_t r; |
268 |
issize_t r; |
| 269 |
TConn *conn = wsh->tsession->connP; |
269 |
TConn *conn = wsh->tsession->connP; |
|
Lines 285-291
issize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes)
Link Here
|
| 285 |
printf("286 Read Error %d!\n", r); |
285 |
printf("286 Read Error %d!\n", r); |
| 286 |
return 0; |
286 |
return 0; |
| 287 |
} else if (r == 0) { |
287 |
} else if (r == 0) { |
| 288 |
ConnRead(conn, 2, NULL, NULL, &readError); |
288 |
ConnRead(conn, 2, NULL, timed_out, &readError); |
| 289 |
|
289 |
|
| 290 |
if (readError) { |
290 |
if (readError) { |
| 291 |
// printf("292 Read Error %s\n", readError); |
291 |
// printf("292 Read Error %s\n", readError); |
|
Lines 415-420
issize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data)
Link Here
|
| 415 |
|
415 |
|
| 416 |
issize_t need = 2; |
416 |
issize_t need = 2; |
| 417 |
char *maskp; |
417 |
char *maskp; |
|
|
418 |
bool timed_out; |
| 418 |
|
419 |
|
| 419 |
again: |
420 |
again: |
| 420 |
need = 2; |
421 |
need = 2; |
|
Lines 429-437
issize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data)
Link Here
|
| 429 |
return ws_close(wsh, WS_PROTO_ERR); |
430 |
return ws_close(wsh, WS_PROTO_ERR); |
| 430 |
} |
431 |
} |
| 431 |
|
432 |
|
| 432 |
if ((wsh->datalen = ws_raw_read(wsh, wsh->buffer, 14)) < need) { |
433 |
/* Idle between frames is normal; a stalled partial frame still fails. */ |
|
|
434 |
do { |
| 435 |
timed_out = false; |
| 436 |
wsh->datalen = ws_raw_read(wsh, wsh->buffer, 14, &timed_out); |
| 437 |
} while (timed_out && !wsh->down); |
| 438 |
|
| 439 |
if (wsh->down) { |
| 440 |
*oc = WSOC_CLOSE; |
| 441 |
return -1; |
| 442 |
} |
| 443 |
|
| 444 |
if (wsh->datalen < need) { |
| 433 |
while (!wsh->down && wsh->datalen < need) { |
445 |
while (!wsh->down && wsh->datalen < need) { |
| 434 |
issize_t r = ws_raw_read(wsh, wsh->buffer + wsh->datalen, 14 - wsh->datalen); |
446 |
issize_t r = ws_raw_read(wsh, wsh->buffer + wsh->datalen, 14 - wsh->datalen, NULL); |
| 435 |
|
447 |
|
| 436 |
if (r < 1) { |
448 |
if (r < 1) { |
| 437 |
/* invalid read - protocol err .. */ |
449 |
/* invalid read - protocol err .. */ |
|
Lines 536-542
issize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data)
Link Here
|
| 536 |
wsh->rplen = wsh->plen - need; |
548 |
wsh->rplen = wsh->plen - need; |
| 537 |
|
549 |
|
| 538 |
while(need) { |
550 |
while(need) { |
| 539 |
issize_t r = ws_raw_read(wsh, wsh->payload + wsh->rplen, need); |
551 |
issize_t r = ws_raw_read(wsh, wsh->payload + wsh->rplen, need, NULL); |
| 540 |
|
552 |
|
| 541 |
if (r < 1) { |
553 |
if (r < 1) { |
| 542 |
/* invalid read - protocol err .. */ |
554 |
/* invalid read - protocol err .. */ |