Add socket recv/send timeouts after connect to prevent websocket poll hangs on half-broken connections
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user