// Client linked list
struct client_data *clients = NULL;
// FDSET List
-fd_set readfds;
+fd_set readfds, writefds;
FILE *fchanlog = NULL;
// Main loop
while(is_running){
- FD_ZERO(&readfds);
+ FD_ZERO(&readfds);
+ FD_ZERO(&writefds);
// Add listening SOCKETS to FDSET
for (int i = 0; i < listener_count; i++)
FD_SET(listeners[i].sock, &readfds);
if (self_sock != INVALID_SOCKET)
FD_SET(self_sock, &readfds);
#endif
- for (struct client_data *cl = clients; cl; cl = cl->next)
+ for (struct client_data *cl = clients; cl; cl = cl->next) {
FD_SET(cl->FD, &readfds);
+ if (cl->want_write_for_read)
+ FD_SET(cl->FD, &writefds);
+ }
// Set highestFD
#ifdef _WIN32
highestFD = cl->FD;
#endif
// Wait until activity on sockets
- if(select(highestFD+1,&readfds,NULL,NULL,NULL) == -1) {
+ if(select(highestFD+1,&readfds,&writefds,NULL,NULL) == -1) {
#ifndef _WIN32
if (errno == EINTR)
continue;
// Respond to already connected clients
for (struct client_data *cl = clients; cl;) {
struct client_data *next = cl->next;
- if (FD_ISSET(cl->FD, &readfds))
+ if (FD_ISSET(cl->FD, &readfds) || (cl->want_write_for_read && FD_ISSET(cl->FD, &writefds)))
recvProc(cl);
cl = next;
}
ssize_t bytesRead;
char *x;
int packetReturn;
+ cl->want_write_for_read = 0;
while(1){
// I hate you
if(cl->bufLen == sizeof(cl->buf)) { killConnection(cl, false); return; }
return;
case TLS_WANT_POLLIN:
return;
- case TLS_WANT_POLLOUT: // FIXME: this blocks
- block(cl, 1);
- continue;
+ case TLS_WANT_POLLOUT:
+ cl->want_write_for_read = 1;
+ return;
}
}
else