summaryrefslogtreecommitdiff
path: root/blabouncer.c
diff options
context:
space:
mode:
Diffstat (limited to 'blabouncer.c')
-rw-r--r--blabouncer.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/blabouncer.c b/blabouncer.c
index 9604ba3..982d504 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -764,6 +764,14 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
debugprint(DEBUG_FULL, "checking client socket %d out of %d.\n", i, fdmax);
if (FD_ISSET(i, &rfds)) {
debugprint(DEBUG_FULL, "fd %d is FD_ISSET and it is a...\n", i);
+
+ // Index of client fd in clients array for use later
+ int clientindex = arrindex(clients, i);
+ if (clientindex < 0 && i != *clientsockfd) {
+ debugprint(DEBUG_CRIT, "dochat(): error: arrindex() returned '%d', exiting!\n", clientindex);
+ exit(1);
+ }
+
// if value of clientsockfd then must be a new connection, if greater must be an existing connection
if (i == *clientsockfd) {
debugprint(DEBUG_SOME, "...new connection!\n");
@@ -845,15 +853,15 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
debugprint(DEBUG_FULL, "bouncer-client: total client connections: %d\n", numclients(clients));
}
// If using client TLS and still pending SSL_accept() then re-try SSL_accept() (it can't be real client data yet)
- } else if (clients[arrindex(clients, i)].pendingsslaccept) {
+ } else if (clients[clientindex].pendingsslaccept) {
debugprint(DEBUG_FULL, "...previous connection pending SSL_accept!\n");
// Try to SSL_accept(), not interested in return code here since openssl_accept() does the right thing.
- openssl_accept(clients[arrindex(clients, i)].fd, clients, &ircdstate, settings, clientcodes);
+ openssl_accept(clients[clientindex].fd, clients, &ircdstate, settings, clientcodes);
} else {
debugprint(DEBUG_FULL, "...previous connection!\n");
// handle data from a client
- if ((clientnumbytes = sockread(clients[arrindex(clients, i)].ssl, clientbuf, MAXRCVSIZE - 1, settings->clienttls)) <= 0) {
+ if ((clientnumbytes = sockread(clients[clientindex].ssl, clientbuf, MAXRCVSIZE - 1, settings->clienttls)) <= 0) {
// got error or connection closed by client
if (clientnumbytes == 0) {
// connection closed