decouple-service-from-fd-array-index.patch
This patch removes the relationship between position in the
pollfd[] array and any meaning about the type of socket.
It also refactors the service loop so there is a per-fd
function that detects the mode of the connection and services
it accordingly.
The context wsi * array is removed and a hashtable introduced
allowing fast wsi lookup from just the fd that it is
associated with
Signed-off-by: Andy Green <andy@warmcat.com>
diff --git a/lib/client-handshake.c b/lib/client-handshake.c
index 70b6c81..e3a6efc 100644
--- a/lib/client-handshake.c
+++ b/lib/client-handshake.c
@@ -50,11 +50,10 @@
clients = wsi->protocol->owning_server;
if (clients)
for (n = 0; n < clients->fds_count; n++) {
- if (clients->wsi[n] != wsi)
+ if (clients->fds[n].fd != wsi->sock)
continue;
while (n < clients->fds_count - 1) {
clients->fds[n] = clients->fds[n + 1];
- clients->wsi[n] = clients->wsi[n + 1];
n++;
}
/* we only have to deal with one */
@@ -150,8 +149,6 @@
return NULL;
}
- this->wsi[this->fds_count] = wsi;
-
/* -1 means just use latest supported */
if (ietf_version_or_minus_one == -1)
@@ -225,6 +222,7 @@
goto bail1;
}
+ insert_wsi(this, wsi);
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(port);