Compare commits
3 Commits
308534b883
...
490c8a2ae0
Author | SHA1 | Date | |
---|---|---|---|
490c8a2ae0
|
|||
f87fb74ced
|
|||
7b9844e267
|
@@ -152,6 +152,8 @@ void async_free(void) {
|
||||
void async_thread(void) {
|
||||
evt_listen_t *local = list_create(sizeof(evt_listen_t), 16);
|
||||
|
||||
// TODO use epoll instead of poll
|
||||
|
||||
thread = pthread_self();
|
||||
|
||||
// main event loop
|
||||
|
@@ -162,35 +162,6 @@ int sock_has_pending(sock *s) {
|
||||
return ret == 1;
|
||||
}
|
||||
|
||||
int sock_poll(sock *sockets[], sock *ready[], sock *error[], int n_sock, int *n_ready, int *n_error, short events, int timeout_ms) {
|
||||
struct pollfd fds[n_sock];
|
||||
for (int i = 0; i < n_sock; i++) {
|
||||
fds[i].fd = sockets[i]->socket;
|
||||
fds[i].events = events;
|
||||
}
|
||||
|
||||
int ret = poll(fds, n_sock, timeout_ms);
|
||||
if (ret < 0 || ready == NULL || error == NULL) return ret;
|
||||
|
||||
*n_ready = 0, *n_error = 0;
|
||||
for (int i = 0; i < n_sock; i++) {
|
||||
if (fds[i].revents & events)
|
||||
ready[(*n_ready)++] = sockets[i];
|
||||
if (fds[i].revents & (POLLERR | POLLHUP | POLLNVAL))
|
||||
error[(*n_error)++] = sockets[i];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sock_poll_read(sock *sockets[], sock *readable[], sock *error[], int n_sock, int *n_readable, int *n_error, int timeout_ms) {
|
||||
return sock_poll(sockets, readable, error, n_sock, n_readable, n_error, POLLIN, timeout_ms);
|
||||
}
|
||||
|
||||
int sock_poll_write(sock *sockets[], sock *writable[], sock *error[], int n_sock, int *n_writable, int *n_error, int timeout_ms) {
|
||||
return sock_poll(sockets, writable, error, n_sock, n_writable, n_error, POLLOUT, timeout_ms);
|
||||
}
|
||||
|
||||
long sock_parse_chunk_header(const char *buf, long len, long *ret_len) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
char ch = buf[i];
|
||||
|
@@ -48,12 +48,6 @@ int sock_close(sock *s);
|
||||
|
||||
int sock_has_pending(sock *s);
|
||||
|
||||
int sock_poll(sock *sockets[], sock *ready[], sock *error[], int n_sock, int *n_ready, int *n_error, short events, int timeout_ms);
|
||||
|
||||
int sock_poll_read(sock *sockets[], sock *readable[], sock *error[], int n_sock, int *n_readable, int *n_error, int timeout_ms);
|
||||
|
||||
int sock_poll_write(sock *sockets[], sock *writable[], sock *error[], int n_sock, int *n_writable, int *n_error, int timeout_ms);
|
||||
|
||||
long sock_parse_chunk_header(const char *buf, long len, long *ret_len);
|
||||
|
||||
long sock_get_chunk_header(sock *s);
|
||||
|
@@ -57,7 +57,7 @@ static int ws_frame_handler(ws_ctx_t *ctx) {
|
||||
if (ws_recv_frame_header(socket, &frame) != 0)
|
||||
return -1;
|
||||
|
||||
debug("WebSocket: Peer %s, Opcode=0x%X, Len=%li", (ctx->socket == &ctx->client->socket) ? "1" : "2", frame.opcode, frame.len);
|
||||
debug("WebSocket: Peer %s, Opcode=0x%X, Len=%li", (ctx->socket == &ctx->client->socket) ? "client" : "server", frame.opcode, frame.len);
|
||||
|
||||
if (frame.opcode == 0x8) {
|
||||
ctx->client->ws_close |= (ctx->socket == &ctx->client->socket) ? 1 : 2;
|
||||
|
Reference in New Issue
Block a user