mirror of
https://github.com/zeromq/libzmq.git
synced 2025-02-21 22:56:22 +01:00
ZMQ-specific error codes added
This commit is contained in:
parent
cc8136896d
commit
e136d923b7
@ -35,6 +35,21 @@ extern "C" {
|
|||||||
#define ZMQ_EXPORT
|
#define ZMQ_EXPORT
|
||||||
#endif
|
#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.
|
// 0MQ message definition.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -154,8 +169,8 @@ ZMQ_EXPORT int zmq_term (void *context);
|
|||||||
// Open a socket. 'type' is one of the socket types defined above.
|
// Open a socket. 'type' is one of the socket types defined above.
|
||||||
//
|
//
|
||||||
// Errors: EINVAL - invalid socket type.
|
// 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.
|
// sockets at the same time was exceeded.
|
||||||
ZMQ_EXPORT void *zmq_socket (void *context, int type);
|
ZMQ_EXPORT void *zmq_socket (void *context, int type);
|
||||||
|
|
||||||
// Destroying the socket.
|
// Destroying the socket.
|
||||||
@ -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".
|
// "udp://192.168.0.111;224.1.1.1:5555".
|
||||||
|
|
||||||
// Bind the socket to a particular address.
|
// 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);
|
ZMQ_EXPORT int zmq_bind (void *s, const char *addr);
|
||||||
|
|
||||||
// Connect the socket to a particular address.
|
// 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);
|
ZMQ_EXPORT int zmq_connect (void *s, const char *addr);
|
||||||
|
|
||||||
// Sending and receiving messages.
|
// 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
|
// Errors: EAGAIN - message cannot be sent at the moment (applies only to
|
||||||
// non-blocking send).
|
// 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);
|
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.
|
// 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);
|
ZMQ_EXPORT int zmq_flush (void *s);
|
||||||
|
|
||||||
// Send a message from the socket 's'. 'flags' argument can be combination
|
// 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
|
// Errors: EAGAIN - message cannot be received at the moment (applies only to
|
||||||
// non-blocking receive).
|
// 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);
|
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];
|
return app_threads [i];
|
||||||
|
|
||||||
// Thread limit was exceeded.
|
// Thread limit was exceeded.
|
||||||
errno = EMFILE;
|
errno = EMTHREAD;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,11 +24,16 @@
|
|||||||
|
|
||||||
const char *zmq::wsa_error()
|
const char *zmq::wsa_error()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
int errcode = WSAGetLastError ();
|
int errcode = WSAGetLastError ();
|
||||||
// TODO: This is not a generic way to handle this...
|
// TODO: This is not a generic way to handle this...
|
||||||
if (errcode == WSAEWOULDBLOCK)
|
if (errcode == WSAEWOULDBLOCK)
|
||||||
return NULL;
|
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
|
return
|
||||||
(errcode == WSABASEERR) ?
|
(errcode == WSABASEERR) ?
|
||||||
"No Error" :
|
"No Error" :
|
||||||
|
@ -152,7 +152,7 @@ int zmq::pub_t::xflush ()
|
|||||||
|
|
||||||
int zmq::pub_t::xrecv (struct zmq_msg_t *msg_, int flags_)
|
int zmq::pub_t::xrecv (struct zmq_msg_t *msg_, int flags_)
|
||||||
{
|
{
|
||||||
errno = EFAULT;
|
errno = ENOTSUP;
|
||||||
return -1;
|
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_)
|
int zmq::rep_t::xsend (struct zmq_msg_t *msg_, int flags_)
|
||||||
{
|
{
|
||||||
if (!waiting_for_reply) {
|
if (!waiting_for_reply) {
|
||||||
errno = EFAULT;
|
errno = EFSM;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ int zmq::rep_t::xsend (struct zmq_msg_t *msg_, int flags_)
|
|||||||
|
|
||||||
int zmq::rep_t::xflush ()
|
int zmq::rep_t::xflush ()
|
||||||
{
|
{
|
||||||
errno = EFAULT;
|
errno = ENOTSUP;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ int zmq::rep_t::xrecv (struct zmq_msg_t *msg_, int flags_)
|
|||||||
zmq_msg_close (msg_);
|
zmq_msg_close (msg_);
|
||||||
|
|
||||||
if (waiting_for_reply) {
|
if (waiting_for_reply) {
|
||||||
errno = EFAULT;
|
errno = EFSM;
|
||||||
return -1;
|
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,
|
// If we've sent a request and we still haven't got the reply,
|
||||||
// we can't send another request.
|
// we can't send another request.
|
||||||
if (waiting_for_reply) {
|
if (waiting_for_reply) {
|
||||||
errno = EFAULT;
|
errno = EFSM;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out_pipes.empty ()) {
|
if (out_pipes.empty ()) {
|
||||||
errno = EFAULT;
|
errno = EAGAIN;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ int zmq::req_t::xsend (struct zmq_msg_t *msg_, int flags_)
|
|||||||
|
|
||||||
int zmq::req_t::xflush ()
|
int zmq::req_t::xflush ()
|
||||||
{
|
{
|
||||||
errno = EFAULT;
|
errno = ENOTSUP;
|
||||||
return -1;
|
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 request wasn't send, we can't wait for reply.
|
||||||
if (!waiting_for_reply) {
|
if (!waiting_for_reply) {
|
||||||
zmq_msg_init (msg_);
|
zmq_msg_init (msg_);
|
||||||
errno = EFAULT;
|
errno = EFSM;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,8 +100,8 @@ int zmq::socket_base_t::bind (const char *addr_)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Unknown address type.
|
// Unknown protocol.
|
||||||
errno = EFAULT;
|
errno = EPROTONOSUPPORT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ int zmq::socket_base_t::connect (const char *addr_)
|
|||||||
// If the socket type requires bi-directional communication
|
// If the socket type requires bi-directional communication
|
||||||
// multicast is not an option (it is uni-directional).
|
// multicast is not an option (it is uni-directional).
|
||||||
if (options.requires_in && options.requires_out) {
|
if (options.requires_in && options.requires_out) {
|
||||||
errno = EFAULT;
|
errno = ENOCOMPATPROTO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,8 +235,8 @@ int zmq::socket_base_t::connect (const char *addr_)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Unknown address type.
|
// Unknown protoco.
|
||||||
errno = EFAULT;
|
errno = EPROTONOSUPPORT;
|
||||||
return -1;
|
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_)
|
int zmq::sub_t::xsend (struct zmq_msg_t *msg_, int flags_)
|
||||||
{
|
{
|
||||||
errno = EFAULT;
|
errno = ENOTSUP;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::sub_t::xflush ()
|
int zmq::sub_t::xflush ()
|
||||||
{
|
{
|
||||||
errno = EFAULT;
|
errno = ENOTSUP;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
src/zmq.cpp
15
src/zmq.cpp
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "../bindings/c/zmq.h"
|
#include "../bindings/c/zmq.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <new>
|
#include <new>
|
||||||
@ -35,6 +36,20 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#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_)
|
int zmq_msg_init (zmq_msg_t *msg_)
|
||||||
{
|
{
|
||||||
msg_->content = (zmq::msg_content_t*) ZMQ_VSM;
|
msg_->content = (zmq::msg_content_t*) ZMQ_VSM;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user