Fixed connection removal

This commit is contained in:
2022-07-10 04:43:49 -05:00
parent 2e69b3126d
commit 9d17ad73fe

View File

@@ -98,14 +98,22 @@ void runServer(int connfd, Sitefile *site, volatile int *pending, int id) {
} }
continue; continue;
remove: remove:
freeConnection(connections + i); {
--connCount; int remove, replace;
memcpy(fds + i, fds + connCount - 1, remove = i;
replace = connCount - 1;
freeConnection(connections + remove);
memcpy(fds + remove, fds + replace,
sizeof(struct pollfd)); sizeof(struct pollfd));
memcpy(connections + i, fds + connCount, memcpy(connections + remove, fds + replace,
sizeof(struct pollfd)); sizeof(struct pollfd));
--pending[id]; --pending[id];
--i; --i;
--connCount;
}
} }
if (fds[0].revents & POLLIN) { if (fds[0].revents & POLLIN) {
@@ -123,6 +131,7 @@ remove:
if (newstream == NULL) { if (newstream == NULL) {
createLog( createLog(
"Stream couldn't be created from file descriptor"); "Stream couldn't be created from file descriptor");
shutdown(newfd, SHUT_RDWR);
close(newfd); close(newfd);
continue; continue;
} }