aboutsummaryrefslogtreecommitdiff
path: root/src/nng.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2016-12-23 11:04:57 -0800
committerGarrett D'Amore <garrett@damore.org>2016-12-23 11:05:36 -0800
commita12baf41fb17ef51a8b1d0c82e31113454c5beae (patch)
tree9e9368ae235a08ff4f9a1738d9e9148f567442e1 /src/nng.c
parent6f5f10fd56da48aa7d95f80e5f3f03c4097f8132 (diff)
downloadnng-a12baf41fb17ef51a8b1d0c82e31113454c5beae.tar.gz
nng-a12baf41fb17ef51a8b1d0c82e31113454c5beae.tar.bz2
nng-a12baf41fb17ef51a8b1d0c82e31113454c5beae.zip
nng_setopt works (rcvtimeout, etc.) External API adjustments.
The external API now uses simpler names for various things, notably we ditch the whole nng_socket_xx prefix. For example, intstead of nng_socket_create, we just use nng_open(). There are no more nng_socket_xxx calls.
Diffstat (limited to 'src/nng.c')
-rw-r--r--src/nng.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/nng.c b/src/nng.c
index 6363636d..fc57c037 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -18,7 +18,7 @@
// Pretty much every function calls the nni_platform_init to check against
// fork related activity.
int
-nng_socket_create(nng_socket **s, uint16_t proto)
+nng_open(nng_socket **s, uint16_t proto)
{
int rv;
@@ -30,7 +30,7 @@ nng_socket_create(nng_socket **s, uint16_t proto)
int
-nng_socket_close(nng_socket *s)
+nng_close(nng_socket *s)
{
int rv;
@@ -42,7 +42,7 @@ nng_socket_close(nng_socket *s)
uint16_t
-nng_socket_protocol(nng_socket *s)
+nng_protocol(nng_socket *s)
{
nni_init();
return (nni_socket_proto(s));
@@ -53,21 +53,36 @@ int
nng_recvmsg(nng_socket *s, nng_msg **msgp, int flags)
{
int rv;
- nni_duration expire;
+ nni_time expire;
if ((rv = nni_init()) != 0) {
return (rv);
}
- if (flags == NNG_FLAG_NONBLOCK) {
- expire = 0;
+
+ if ((flags == NNG_FLAG_NONBLOCK) || (s->s_rcvtimeo == 0)) {
+ expire = NNI_TIME_ZERO;
+ } else if (s->s_rcvtimeo < 0) {
+ expire = NNI_TIME_NEVER;
} else {
- // XXX: revise this timeout from socket option!!
- expire = 1000000;
+ expire = nni_clock() + s->s_rcvtimeo;
}
+
return (nni_socket_recvmsg(s, msgp, expire));
}
+int
+nng_setopt(nng_socket *s, int opt, const void *val, size_t sz)
+{
+ int rv;
+
+ if ((rv = nni_init()) != 0) {
+ return (rv);
+ }
+ return (nni_socket_setopt(s, opt, val, sz));
+}
+
+
// Misc.
const char *
nng_strerror(int num)
@@ -75,7 +90,7 @@ nng_strerror(int num)
nni_init();
switch (num) {
case 0:
- return ("Hunky dory"); /* what did you expect? */
+ return ("Hunky dory"); // What did you expect?
case NNG_EINTR:
return ("Interrupted");