nTotalConnectionsDropped_++;
if (overloadAction_ == T_OVERLOAD_CLOSE_ON_ACCEPT) {
close(clientSocket);
- continue;
+ return;
} else if (overloadAction_ == T_OVERLOAD_DRAIN_TASK_QUEUE) {
if (!drainPendingTask()) {
// Nothing left to discard, so we drop connection instead.
close(clientSocket);
- continue;
+ return;
}
}
}
GlobalOutput.perror("TNonblockingServer::createNotificationPipe ", errno);
throw TException("can't create notification pipe");
}
+ int flags;
+ if ((flags = fcntl(notificationPipeFDs_[0], F_GETFL, 0)) < 0 ||
+ fcntl(notificationPipeFDs_[0], F_SETFL, flags | O_NONBLOCK) < 0) {
+ close(notificationPipeFDs_[0]);
+ close(notificationPipeFDs_[1]);
+ throw TException("TNonblockingServer::createNotificationPipe() O_NONBLOCK");
+ }
}
/**
*/
static void taskHandler(int fd, short /* which */, void* /* v */) {
TConnection* connection;
- if (read(fd, (void*)&connection, sizeof(TConnection*))
- != sizeof(TConnection*)) {
+ ssize_t nBytes;
+ while ((nBytes = read(fd, (void*)&connection, sizeof(TConnection*)))
+ == sizeof(TConnection*)) {
+ connection->transition();
+ }
+ if (nBytes > 0) {
+ throw TException("TConnection::taskHandler unexpected partial read");
+ }
+ if (errno != EWOULDBLOCK && errno != EAGAIN) {
GlobalOutput.perror("TConnection::taskHandler read failed, resource leak", errno);
- return;
}
-
- connection->transition();
}
/**