fix(server): check kill_recv in accept() loop to prevent hang on stop
If server_stop() is called before any client connects, the accept() loop would spin forever since kill_recv was never checked, causing pthread_join() to block indefinitely. Add kill_recv check at the top of the accept() polling loop so the thread can exit cleanly when server_stop() is called during the pre-connection phase.
This commit is contained in:
@@ -436,8 +436,12 @@ _start_server_cb(void* userdata)
|
|||||||
int c = sizeof(struct sockaddr_in);
|
int c = sizeof(struct sockaddr_in);
|
||||||
int client_socket;
|
int client_socket;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
// DEBUG removed
|
|
||||||
while ((client_socket = accept(listen_socket, (struct sockaddr *)&client_addr, (socklen_t*)&c)) == -1) {
|
while ((client_socket = accept(listen_socket, (struct sockaddr *)&client_addr, (socklen_t*)&c)) == -1) {
|
||||||
|
if (kill_recv) {
|
||||||
|
log_println(STBBR_LOGINFO, "Accept loop interrupted by stop request");
|
||||||
|
_shutdown();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||||
log_println(STBBR_LOGERROR, "Accept failed: %s", strerror(errno));
|
log_println(STBBR_LOGERROR, "Accept failed: %s", strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user