Commit e136d923 authored by Martin Sustrik's avatar Martin Sustrik

ZMQ-specific error codes added

parent cc813689
......@@ -35,6 +35,21 @@ extern "C" {
#define ZMQ_EXPORT
#endif
////////////////////////////////////////////////////////////////////////////////
// 0MQ errors.
////////////////////////////////////////////////////////////////////////////////
// A number random anough not to collide with different errno ranges on
// different OSes. The assumption is that error_t is at least 32-bit type.
#define ZMQ_HAUSNUMERO 156384712
#define EMTHREAD (ZMQ_HAUSNUMERO + 1)
#define EFSM (ZMQ_HAUSNUMERO + 2)
#define ENOCOMPATPROTO (ZMQ_HAUSNUMERO + 3)
// Resolves system errors and 0MQ errors to human-readable string.
ZMQ_EXPORT const char *zmq_strerror (int errnum);
////////////////////////////////////////////////////////////////////////////////
// 0MQ message definition.
////////////////////////////////////////////////////////////////////////////////
......@@ -154,7 +169,7 @@ ZMQ_EXPORT int zmq_term (void *context);
// Open a socket. 'type' is one of the socket types defined above.
//
// Errors: EINVAL - invalid socket type.
// EMFILE - the number of application threads entitled to hold open
// EMTHREAD - the number of application threads entitled to hold open
// sockets at the same time was exceeded.
ZMQ_EXPORT void *zmq_socket (void *context, int type);
......@@ -276,9 +291,15 @@ ZMQ_EXPORT int zmq_setsockopt (void *s, int option, const void *optval,
// "udp://192.168.0.111;224.1.1.1:5555".
// Bind the socket to a particular address.
//
// Errors: EPROTONOSUPPORT - unsupported protocol.
// ENOCOMPATPROTO - protocol is not compatible with the socket type.
ZMQ_EXPORT int zmq_bind (void *s, const char *addr);
// Connect the socket to a particular address.
//
// Errors: EPROTONOSUPPORT - unsupported protocol.
// ENOCOMPATPROTO - protocol is not compatible with the socket type.
ZMQ_EXPORT int zmq_connect (void *s, const char *addr);
// Sending and receiving messages.
......@@ -303,12 +324,14 @@ ZMQ_EXPORT int zmq_connect (void *s, const char *addr);
//
// Errors: EAGAIN - message cannot be sent at the moment (applies only to
// non-blocking send).
// EFAULT - function isn't supported by particular socket type.
// ENOTSUP - function isn't supported by particular socket type.
// EFSM - function cannot be called at the moment.
ZMQ_EXPORT int zmq_send (void *s, struct zmq_msg_t *msg, int flags);
// Flush the messages that were send using ZMQ_NOFLUSH flag down the stream.
//
// Errors: FAULT - function isn't supported by particular socket type.
// Errors: ENOTSUP - function isn't supported by particular socket type.
// EFSM - function cannot be called at the moment.
ZMQ_EXPORT int zmq_flush (void *s);
// Send a message from the socket 's'. 'flags' argument can be combination
......@@ -316,7 +339,8 @@ ZMQ_EXPORT int zmq_flush (void *s);
//
// Errors: EAGAIN - message cannot be received at the moment (applies only to
// non-blocking receive).
// EFAULT - function isn't supported by particular socket type.
// ENOTSUP - function isn't supported by particular socket type.
// EFSM - function cannot be called at the moment.
ZMQ_EXPORT int zmq_recv (void *s, struct zmq_msg_t *msg, int flags);
////////////////////////////////////////////////////////////////////////////////
......
......@@ -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;
}
......
......@@ -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" :
......
......@@ -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;
}
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -19,6 +19,7 @@
#include "../bindings/c/zmq.h"
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <new>
......@@ -35,6 +36,20 @@
#include <sys/time.h>
#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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment