Skip to content

Commit

Permalink
slightly better backends error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ghedo committed Jul 3, 2011
1 parent fe32a40 commit 7f518f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/backend/evhttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ void tofu_backend_evhttp_loop(tofu_ctx_t *ctx) {
base = event_base_new();

if (!base) {
fprintf(stderr, "Couldn't create an event_base: exiting\n");
fprintf(stderr, "Err: couldn't create an event_base\n");
exit(-1);
}

http = evhttp_new(base);

if (!http) {
fprintf(stderr, "couldn't create evhttp. Exiting.\n");
fprintf(stderr, "Err: couldn't create evhttp.\n");
exit(-1);
}

Expand All @@ -85,7 +85,7 @@ void tofu_backend_evhttp_loop(tofu_ctx_t *ctx) {
handle = evhttp_bind_socket_with_handle(http, listen, port);

if (!handle) {
fprintf(stderr, "couldn't bind to port %d. Exiting.\n", port);
fprintf(stderr, "Err: couldn't bind to port %d.\n", port);
exit(-1);
}

Expand Down
17 changes: 16 additions & 1 deletion src/backend/zmq.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,31 @@ void tofu_backend_zmq_loop(tofu_ctx_t *ctx) {
zmq_pollitem_t items[1];
void *zmq_ctx = zmq_init(1);

if (!zmq_ctx) {
fprintf(stderr, "Err: couldn't create zmq context.\n");
exit(-1);
}

char *recv_spec = ctx -> backend_opts[0];
char *recv_ident = ctx -> backend_opts[1];

char *send_spec = ctx -> backend_opts[2];
char *send_ident = ctx -> backend_opts[3];

void *recv = zmq_socket(zmq_ctx, ZMQ_PULL);

if (!recv) {
fprintf(stderr, "Err: couldn't create zmq socket recv.\n");
exit(-1);
}

void *send = zmq_socket(zmq_ctx, ZMQ_PUB);

if (!send) {
fprintf(stderr, "Err: couldn't create zmq socket send.\n");
exit(-1);
}

zmq_connect(recv, recv_spec);
zmq_setsockopt(recv, ZMQ_IDENTITY, recv_ident, strlen(recv_ident));

Expand Down Expand Up @@ -107,7 +123,6 @@ void tofu_backend_zmq_loop(tofu_ctx_t *ctx) {
tofu_rep_free(rep);
tofu_req_free(req);

/*free(tnetstr);*/
zmq_msg_close(&msg);
}
}
Expand Down

0 comments on commit 7f518f5

Please sign in to comment.