[zeromq-dev] accept() and EMFILE/ENFILE
Dhammika Pathirana
dhammika at gmail.com
Fri May 22 08:09:13 CEST 2009
Hi All,
Can we handle this in client side with a timeout?
1. Server sends ZMQ_SYN cookie on accept()
sock = accept (listen_sock, ...);
if (sock > 0) {
send (sock, zmq_syn, 1, 0);
} else {
switch (errno) {
case EMFILE :
case ENFILE :
temporarily_disable_polling ();
break;
case EAGAIN :
case EWOULDBLOCK :
continue;
default:
return errno;
}
}
2. Client waits for ZMQ_SYN cookie on connect()
if (connect (sock, ..) == 0) {
fd_set rfds;
int ready;
FD_ZERO (&rfds);
FD_SET (sock, &rfds)
struct timeval time_out = {zmq_timeout, 0};
ready = select (sock + 1, &rfds, NULL, NULL, &time_out);
if (ready == 1 && FD_ISSET (sock, &rfds)) {
/* Sweet zmq cookie */
} else if (ready == 0) {
/* Timeout */
shutdown (sock, SHUT_RDWR);
}
}
We don't have to tweak TCP flags or need well known ports for this.
Also zmq transport is opaque, so we can do this without API changes.
Dhammika
More information about the zeromq-dev
mailing list