[zeromq-dev] accept() and EMFILE/ENFILE
Martin Sustrik
sustrik at fastmq.com
Fri May 22 08:42:34 CEST 2009
Hi Dhammika,
> 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.
Hm, what about DoS attacks? If the client intentionally keeps the
connection open rather than timeouting it it can starve the server out
of file descriptors, no?
Martin
More information about the zeromq-dev
mailing list