Bug fixes

This commit is contained in:
2025-11-03 18:32:14 +01:00
parent e135d871c1
commit 31a4b2cc32
5 changed files with 38 additions and 31 deletions
+5 -3
View File
@@ -224,25 +224,25 @@ int tcp_translate_events(TCP *tcp, Event *events, void **contexts, struct pollfd
} else {
if (polled[i].revents & POLLIN) {
byte_queue_write_setmincap(&conn->input, 1<<9);
ByteView buf = byte_queue_write_buf(&conn->input);
int num = sys_recv(conn->fd, (char*) buf.ptr, buf.len, 0);
if (num == 0)
defer_close = true;
else if (num < 0) {
if (errno != EINTR && errno != EWOULDBLOCK && errno != EAGAIN)
if (errno != EINTR && errno != EWOULDBLOCK && errno != EAGAIN) // TODO: does Windows return these error codes or not?
defer_close = true;
num = 0;
}
byte_queue_write_ack(&conn->input, num);
ByteView msg = byte_queue_read_buf(&conn->input);
int ret = message_peek(msg, NULL, NULL);
byte_queue_read_ack(&conn->input, 0);
if (ret < 0) {
// Invalid message
byte_queue_read_ack(&conn->input, 0);
defer_close = true;
} else if (ret == 0) {
// Still buffering
byte_queue_read_ack(&conn->input, 0);
if (byte_queue_full(&conn->input))
defer_close = true;
} else {
@@ -266,6 +266,8 @@ int tcp_translate_events(TCP *tcp, Event *events, void **contexts, struct pollfd
}
}
// TODO: byte_queue_error here?
removed[i] = defer_close;
if (0) {}
else if (defer_close) events[num_events++] = (Event) { EVENT_DISCONNECT, conn - tcp->conns };