From e136d923b7060ef64d44264f88e49057e6638f31 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Tue, 22 Sep 2009 11:52:35 +0200 Subject: ZMQ-specific error codes added --- src/dispatcher.cpp | 2 +- src/err.cpp | 5 +++++ src/pub.cpp | 2 +- src/rep.cpp | 6 +++--- src/req.cpp | 8 ++++---- src/socket_base.cpp | 10 +++++----- src/sub.cpp | 4 ++-- src/zmq.cpp | 15 +++++++++++++++ 8 files changed, 36 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/dispatcher.cpp b/src/dispatcher.cpp index ef2f7c1..1f6b4f0 100644 --- a/src/dispatcher.cpp +++ b/src/dispatcher.cpp @@ -163,7 +163,7 @@ zmq::app_thread_t *zmq::dispatcher_t::choose_app_thread () return app_threads [i]; // Thread limit was exceeded. - errno = EMFILE; + errno = EMTHREAD; return NULL; } diff --git a/src/err.cpp b/src/err.cpp index bca0c03..ef5b987 100644 --- a/src/err.cpp +++ b/src/err.cpp @@ -24,11 +24,16 @@ const char *zmq::wsa_error() { + + int errcode = WSAGetLastError (); // TODO: This is not a generic way to handle this... if (errcode == WSAEWOULDBLOCK) return NULL; + // TODO: It seems that list of Windows socket errors is longer than this. + // Investigate whether there's a way to convert it into the string + // automatically (wsaError->HRESULT->string?). return (errcode == WSABASEERR) ? "No Error" : diff --git a/src/pub.cpp b/src/pub.cpp index faaa9aa..a403157 100644 --- a/src/pub.cpp +++ b/src/pub.cpp @@ -152,7 +152,7 @@ int zmq::pub_t::xflush () int zmq::pub_t::xrecv (struct zmq_msg_t *msg_, int flags_) { - errno = EFAULT; + errno = ENOTSUP; return -1; } diff --git a/src/rep.cpp b/src/rep.cpp index fcf8058..7ebbc6d 100644 --- a/src/rep.cpp +++ b/src/rep.cpp @@ -137,7 +137,7 @@ int zmq::rep_t::xsetsockopt (int option_, const void *optval_, int zmq::rep_t::xsend (struct zmq_msg_t *msg_, int flags_) { if (!waiting_for_reply) { - errno = EFAULT; + errno = EFSM; return -1; } @@ -161,7 +161,7 @@ int zmq::rep_t::xsend (struct zmq_msg_t *msg_, int flags_) int zmq::rep_t::xflush () { - errno = EFAULT; + errno = ENOTSUP; return -1; } @@ -171,7 +171,7 @@ int zmq::rep_t::xrecv (struct zmq_msg_t *msg_, int flags_) zmq_msg_close (msg_); if (waiting_for_reply) { - errno = EFAULT; + errno = EFSM; return -1; } diff --git a/src/req.cpp b/src/req.cpp index 9b4dffa..3fd9b38 100644 --- a/src/req.cpp +++ b/src/req.cpp @@ -120,12 +120,12 @@ int zmq::req_t::xsend (struct zmq_msg_t *msg_, int flags_) // If we've sent a request and we still haven't got the reply, // we can't send another request. if (waiting_for_reply) { - errno = EFAULT; + errno = EFSM; return -1; } if (out_pipes.empty ()) { - errno = EFAULT; + errno = EAGAIN; return -1; } @@ -166,7 +166,7 @@ int zmq::req_t::xsend (struct zmq_msg_t *msg_, int flags_) int zmq::req_t::xflush () { - errno = EFAULT; + errno = ENOTSUP; return -1; } @@ -178,7 +178,7 @@ int zmq::req_t::xrecv (struct zmq_msg_t *msg_, int flags_) // If request wasn't send, we can't wait for reply. if (!waiting_for_reply) { zmq_msg_init (msg_); - errno = EFAULT; + errno = EFSM; return -1; } diff --git a/src/socket_base.cpp b/src/socket_base.cpp index 0452993..6763167 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -100,8 +100,8 @@ int zmq::socket_base_t::bind (const char *addr_) } #endif - // Unknown address type. - errno = EFAULT; + // Unknown protocol. + errno = EPROTONOSUPPORT; return -1; } @@ -185,7 +185,7 @@ int zmq::socket_base_t::connect (const char *addr_) // If the socket type requires bi-directional communication // multicast is not an option (it is uni-directional). if (options.requires_in && options.requires_out) { - errno = EFAULT; + errno = ENOCOMPATPROTO; return -1; } @@ -235,8 +235,8 @@ int zmq::socket_base_t::connect (const char *addr_) } #endif - // Unknown address type. - errno = EFAULT; + // Unknown protoco. + errno = EPROTONOSUPPORT; return -1; } diff --git a/src/sub.cpp b/src/sub.cpp index 66aa8fd..abd9deb 100644 --- a/src/sub.cpp +++ b/src/sub.cpp @@ -124,13 +124,13 @@ int zmq::sub_t::xsetsockopt (int option_, const void *optval_, int zmq::sub_t::xsend (struct zmq_msg_t *msg_, int flags_) { - errno = EFAULT; + errno = ENOTSUP; return -1; } int zmq::sub_t::xflush () { - errno = EFAULT; + errno = ENOTSUP; return -1; } diff --git a/src/zmq.cpp b/src/zmq.cpp index e831046..d6f7023 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -19,6 +19,7 @@ #include "../bindings/c/zmq.h" +#include #include #include #include @@ -35,6 +36,20 @@ #include #endif +const char *zmq_strerror (int errnum_) +{ + switch (errnum_) { + case EMTHREAD: + return "Number of preallocated application threads exceeded"; + case EFSM: + return "Operation cannot be accomplished in current state"; + case ENOCOMPATPROTO: + return "The protocol is not compatible with the socket type"; + default: + return strerror (errnum_); + } +} + int zmq_msg_init (zmq_msg_t *msg_) { msg_->content = (zmq::msg_content_t*) ZMQ_VSM; -- cgit v1.2.3