Hacker News new | ask | show | jobs
by nuxi 5604 days ago
I've glanced at the 0mq sources a bit, and I'm curious about the error handling. For example, zmq::tcp_socket_t::read() handles following errnos from recv(): EAGAIN, EWOULDBLOCK, EINTR, ECONNRESET and EPIPE. If recv() fails for any other reason (e.g. ENOBUFS, ETIMEDOUT) and returns -1, the following is performed:

  errno_assert (nbytes != -1);
which translates to

  #define errno_assert(x) \
    do {\
        if (unlikely (!(x))) {\
            perror (NULL);\
            fprintf (stderr, "%s (%s:%d)\n", #x, __FILE__, __LINE__);\
            abort ();\
        }\
    } while (false)

The first thing I noticed is the use of perror() and fprintf() for error reporting. Any daemon that closed its stdin/out/err and not had them redirected to /dev/null will most likely output errors to other file descriptors (sockets, other open files etc.). Is this by design or something that was missed?

Secondly, the use of abort() in an API is probably also not the best choice. Say I'm writing a (robust) database server and an error happens on one connection - the error will bring the whole server down, which kind of defeats the purpose. Is this also by design?

[Edit: formatting]