Skip to content

Commit

Permalink
Fix building with libxs or libzmq only
Browse files Browse the repository at this point in the history
  • Loading branch information
tailhook committed Apr 17, 2012
1 parent c074a06 commit ba019b2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/handle_xs.c
Expand Up @@ -4,19 +4,18 @@
#include <assert.h>
#include <stdlib.h>

#include <xs.h>

#include "handle_xs.h"

#ifndef HAVE_XS


int open_xs_socket(context *ctx, config_socket_t *sock) {
fprintf(stderr, "Paperjam was compiled without libxs support\n");
errno = ENOTSUP;
return -1;
}

#else
#else // HAVE_XS

#define XS_MORENWAIT (XS_DONTWAIT|XS_SNDMORE)

Expand Down
14 changes: 11 additions & 3 deletions src/handle_xs.h
Expand Up @@ -18,15 +18,23 @@
#define XS_SOCKETERR(sock, val) if((val) == -1) { \
fprintf(stderr, "Error on ``%s.%s'' at %s:%d: %s\n", \
(sock)->_name, (sock)->_type, __FILE__, __LINE__, \
zmq_strerror(errno)); \
xs_strerror(errno)); \
abort(); \
}


#else

#define XS_ASSERTERR(val) assert(0);
#define XS_SOCKETERR(sock, val) assert(0);
#define XS_ASSERTERR(val) if((val) == -1) { \
fprintf(stderr, "Assertion error" #val ": %s\n", strerror(errno)); \
abort(); \
}
#define XS_SOCKETERR(sock, val) if((val) == -1) { \
fprintf(stderr, "Error on ``%s.%s'' at %s:%d: %s\n", \
(sock)->_name, (sock)->_type, __FILE__, __LINE__, \
strerror(errno)); \
abort(); \
}

#endif

Expand Down
2 changes: 0 additions & 2 deletions src/handle_zmq.c
Expand Up @@ -5,8 +5,6 @@
#include <stdlib.h>
#include <stdint.h>

#include <zmq.h>

#include "handle_zmq.h"

#ifndef HAVE_ZMQ
Expand Down
14 changes: 12 additions & 2 deletions src/handle_zmq.h
Expand Up @@ -25,8 +25,18 @@

#else

#define ZMQ_ASSERTERR(val) assert(0);
#define ZMQ_SOCKETERR(sock, val) assert(0);
#define ZMQ_SOCKETERR(sock, val) if((val) == -1) { \
fprintf(stderr, "Error on ``%s.%s'' at %s:%d: %s\n", \
(sock)->_name, (sock)->_type, __FILE__, __LINE__, \
strerror(errno)); \
abort(); \
}
#define ZMQ_ASSERTERR(val) if((val) == -1) { \
fprintf(stderr, "Assertion error at %s:%d: %s\n", \
__FILE__, __LINE__, \
strerror(errno)); \
abort(); \
}

#endif

Expand Down
10 changes: 5 additions & 5 deletions src/main.c
Expand Up @@ -12,7 +12,7 @@
#define ASSERTERR(val) if((val) == -1) { \
fprintf(stderr, "Assertion error at %s:%d: %s\n", \
__FILE__, __LINE__, \
zmq_strerror(errno)); \
strerror(errno)); \
abort(); \
}

Expand Down Expand Up @@ -43,7 +43,7 @@ static int close_message(message *msg) {
#endif
}
if(msg->xs) {
#ifdef HAVE_ZMQ
#ifdef HAVE_XS
XS_ASSERTERR(xs_msg_close(&msg->xs_msg));
#else
assert(0);
Expand Down Expand Up @@ -202,7 +202,7 @@ int main(int argc, char **argv) {
open_xs_socket(&ctx, &item->value.frontend));
} else {
zmq_socks += 1;
XS_SOCKETERR(&item->value.frontend,
ZMQ_SOCKETERR(&item->value.frontend,
open_zmq_socket(&ctx, &item->value.frontend));
}

Expand All @@ -214,7 +214,7 @@ int main(int argc, char **argv) {
open_xs_socket(&ctx, &item->value.backend));
} else {
zmq_socks += 1;
XS_SOCKETERR(&item->value.backend,
ZMQ_SOCKETERR(&item->value.backend,
open_zmq_socket(&ctx, &item->value.backend));
}
device_check(&item->value.frontend, &item->value.backend);
Expand All @@ -228,7 +228,7 @@ int main(int argc, char **argv) {
open_xs_socket(&ctx, &item->value.monitor));
} else {
zmq_socks += 1;
XS_SOCKETERR(&item->value.monitor,
ZMQ_SOCKETERR(&item->value.monitor,
open_zmq_socket(&ctx, &item->value.monitor));
}
monitor_check(&item->value.monitor);
Expand Down
3 changes: 2 additions & 1 deletion test/base.py
Expand Up @@ -10,6 +10,7 @@ class Wrapper(object):

def __init__(self, sock):
self.sock = sock
sock.setsockopt(zmq.LINGER, 0)

def send_multipart(self, data):
self.sock.send_multipart(data, zmq.DONTWAIT)
Expand Down Expand Up @@ -39,6 +40,6 @@ def setUp(self):

def socket(self, kind, addr):
res = self.ctx.socket(getattr(zmq, kind.upper()))
res.connect(addr)
self.addCleanup(res.close)
res.connect(addr)
return Wrapper(res)
4 changes: 2 additions & 2 deletions wscript
Expand Up @@ -27,8 +27,8 @@ def configure(conf):
conf.check(header_name='xs.h',
define_name='HAVE_XS',
mandatory=False)
conf.check(lib='xs', uselib_store='XS')
conf.check(lib='zmq', uselib_store='XS')
conf.check(lib='xs', uselib_store='XS', mandatory=False)
conf.check(lib='zmq', uselib_store='XS', mandatory=False)
if not conf.env['HAVE_ZMQ'] and not conf.env['HAVE_XS']:
raise Errors.ConfigurationError(
"Either libzmq or libxs is required, none found")
Expand Down

0 comments on commit ba019b2

Please sign in to comment.