WebSocket: some clean-up
This commit is contained in:
parent
2b8f52ac72
commit
efc663a178
@ -1624,8 +1624,7 @@ start:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static enum ws_read_result
|
static enum ws_read_result
|
||||||
backend_ws_fill_read_buffer
|
backend_ws_fill_read_buffer (struct ws_context *self, void *buf, size_t *len)
|
||||||
(struct ws_context *self, void *buf, size_t *len)
|
|
||||||
{
|
{
|
||||||
ssize_t n_read;
|
ssize_t n_read;
|
||||||
start:
|
start:
|
||||||
@ -1776,46 +1775,36 @@ backend_ws_on_fd_ready (EV_P_ ev_io *handle, int revents)
|
|||||||
(void) revents;
|
(void) revents;
|
||||||
|
|
||||||
struct ws_context *self = handle->data;
|
struct ws_context *self = handle->data;
|
||||||
|
uint8_t buf[BUFSIZ];
|
||||||
|
size_t n_read;
|
||||||
|
|
||||||
enum ws_read_result (*fill_buffer)(struct ws_context *, void *, size_t *)
|
restart:
|
||||||
= self->ssl
|
n_read = sizeof buf;
|
||||||
? backend_ws_fill_read_buffer_tls
|
|
||||||
: backend_ws_fill_read_buffer;
|
|
||||||
bool close_connection = false;
|
|
||||||
|
|
||||||
uint8_t buf[8192];
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
// Try to read some data in a non-blocking manner
|
// Try to read some data in a non-blocking manner
|
||||||
size_t n_read = sizeof buf;
|
|
||||||
(void) set_blocking (self->server_fd, false);
|
(void) set_blocking (self->server_fd, false);
|
||||||
enum ws_read_result result = fill_buffer (self, buf, &n_read);
|
enum ws_read_result result = self->ssl
|
||||||
|
? backend_ws_fill_read_buffer_tls (self, buf, &n_read)
|
||||||
|
: backend_ws_fill_read_buffer (self, buf, &n_read);
|
||||||
(void) set_blocking (self->server_fd, true);
|
(void) set_blocking (self->server_fd, true);
|
||||||
|
|
||||||
switch (result)
|
switch (result)
|
||||||
{
|
{
|
||||||
case WS_READ_AGAIN:
|
case WS_READ_AGAIN:
|
||||||
goto end;
|
return;
|
||||||
case WS_READ_ERROR:
|
case WS_READ_ERROR:
|
||||||
print_error ("reading from the server failed");
|
print_error ("reading from the server failed");
|
||||||
close_connection = true;
|
break;
|
||||||
goto end;
|
|
||||||
case WS_READ_EOF:
|
case WS_READ_EOF:
|
||||||
print_status ("the server closed the connection");
|
print_status ("the server closed the connection");
|
||||||
close_connection = true;
|
break;
|
||||||
goto end;
|
|
||||||
case WS_READ_OK:
|
case WS_READ_OK:
|
||||||
if (backend_ws_on_data (self, buf, n_read))
|
if (backend_ws_on_data (self, buf, n_read))
|
||||||
break;
|
goto restart;
|
||||||
|
|
||||||
// XXX: maybe we should wait until we receive an EOF
|
// XXX: maybe we should wait until we receive an EOF
|
||||||
close_connection = true;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
|
||||||
if (close_connection)
|
|
||||||
backend_ws_close_connection (self);
|
backend_ws_close_connection (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user