$ git clone https://ion.nu/git/webchat
commit 7925509a2fc8f7acdf59dde4037e93e17d8b4284
Author: Alicia <...>
Date: Wed Dec 30 02:42:25 2015 +0100
Handle httpcam workaround users disconnecting properly
diff --git a/src/chat.c b/src/chat.c
index 2022ab3..ea02715 100644
--- a/src/chat.c
+++ b/src/chat.c
@@ -145,7 +145,13 @@ printf("New connection\n");
if(users[i]->httpcam) // httpcams shouldn't speak
{
char buf[128];
- read(users[i]->rawsocket, buf, 128); // Read it and ignore it
+ if(read(users[i]->rawsocket, buf, 128)<=0) // Read it and ignore it
+ {
+ freeuser(users[i]);
+ --usercount;
+ memmove(&users[i], &users[i+1], sizeof(struct user*)*(usercount-i));
+ memmove(&fds[i+1], &fds[i+2], sizeof(struct pollfd)*(usercount-i));
+ }
continue;
}
users[i]->handshake=websock_handshake_server(users[i]->socket, websocket_requirements, httpcam_cb, use_tls);