Last active
December 26, 2015 20:28
-
-
Save ulikoehler/7208431 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
L23 binds instead of connects.
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
What's the point of using the
unlikely()
macro when there are no branches? Also that macro isn't even defined here.