Skip to content

Instantly share code, notes, and snippets.

@ulikoehler
Last active December 26, 2015 20:28
Show Gist options
  • Save ulikoehler/7208431 to your computer and use it in GitHub Desktop.
Save ulikoehler/7208431 to your computer and use it in GitHub Desktop.
void* zsocket_new_bind(zctx_t* context, int type, const char* endpoint) {
assert(context);
assert(endpoint);
void* sock = zsocket_new(context, type);
if(unlikely(!sock)) {
return NULL;
}
if(unlikely(zsocket_bind(sock, endpoint) == -1)) {
zsocket_destroy(context, sock);
return NULL;
}
return sock;
}
void* zsocket_new_connect(zctx_t* context, int type, const char* endpoint) {
assert(context);
assert(endpoint);
void* sock = zsocket_new(context, type);
if(unlikely(!sock)) {
return NULL;
}
if(unlikely(zsocket_bind(sock, endpoint) == -1)) {
zsocket_destroy(context, sock);
return NULL;
}
return sock;
}
void* zmq_socket_new_connect(void* context, int type, const char* endpoint) {
assert(context);
assert(endpoint);
void* sock = zmq_socket(context, type);
if(unlikely(!sock)) {
return NULL;
}
if(unlikely(zmq_connect(sock, endpoint) == -1) {
zmq_close(sock);
return NULL;
}
return sock;
}
void* zmq_socket_new_bind(void* context, int type, const char* endpoint) {
assert(context);
assert(endpoint);
void* sock = zmq_socket(context, type);
if(unlikely(!sock)) {
return NULL;
}
if(unlikely(zmq_bind(sock, endpoint) == -1) {
zmq_close(sock);
return NULL;
}
return sock;
}
Copy link

ghost commented Oct 29, 2013

What's the point of using the unlikely() macro when there are no branches? Also that macro isn't even defined here.

Copy link

ghost commented Oct 29, 2013

L23 binds instead of connects.

@hintjens
Copy link

I like the idea; you really do not need branch optimization here, this code is not on the critical path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment