Add socket recv/send timeouts after connect to prevent websocket poll hangs on half-broken connections

This commit is contained in:
Your Name
2026-03-05 10:39:51 -04:00
parent 23e68bdc83
commit 481bf3158d
3 changed files with 10 additions and 3 deletions

View File

@@ -1 +1 @@
0.4.10
0.4.11

View File

@@ -2,10 +2,10 @@
#define NOSTR_CORE_H
// Version information (auto-updated by increment_and_push.sh)
#define VERSION "v0.4.10"
#define VERSION "v0.4.11"
#define VERSION_MAJOR 0
#define VERSION_MINOR 4
#define VERSION_PATCH 10
#define VERSION_PATCH 11
/*
* NOSTR Core Library - Complete API Reference

View File

@@ -453,6 +453,13 @@ static int tcp_connect(void* ctx, const char* host, int port) {
tcp->socket_fd = -1;
return -1;
}
// Safety timeout: prevent indefinite blocking in recv/send on half-broken sockets.
struct timeval io_timeout;
io_timeout.tv_sec = 5;
io_timeout.tv_usec = 0;
(void)setsockopt(tcp->socket_fd, SOL_SOCKET, SO_RCVTIMEO, &io_timeout, sizeof(io_timeout));
(void)setsockopt(tcp->socket_fd, SOL_SOCKET, SO_SNDTIMEO, &io_timeout, sizeof(io_timeout));
return 0;
}