diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-23 22:49:57 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-23 22:49:57 -0800 |
| commit | 7df0822d3ed58ee73918cac576c0b07363e84425 (patch) | |
| tree | 5cae69dc0dc3e609260e0bd99bb8743c1c1a28cc /src/nng_compat.c | |
| parent | 91a0b46b6a63f1c2345279b831a02c972e7b1781 (diff) | |
| download | nng-7df0822d3ed58ee73918cac576c0b07363e84425.tar.gz nng-7df0822d3ed58ee73918cac576c0b07363e84425.tar.bz2 nng-7df0822d3ed58ee73918cac576c0b07363e84425.zip | |
Added a bunch more compatibility stuff.
I implemented the reqrep compatibility test, which uncovered a few
semantic issues I had in the REQ/REP protocol, which I've fixed.
There are still missing things. and at least one portion of the req/rep
test suite cannot be enabled until I add tuning of the reconnect timeout,
which is currently way too long (1 sec) for the test suite to work.
Diffstat (limited to 'src/nng_compat.c')
| -rw-r--r-- | src/nng_compat.c | 138 |
1 files changed, 133 insertions, 5 deletions
diff --git a/src/nng_compat.c b/src/nng_compat.c index c9a36178..fd43af29 100644 --- a/src/nng_compat.c +++ b/src/nng_compat.c @@ -17,8 +17,8 @@ // avoid using these if at all possible, and instead use the new style APIs. static struct { - int perr; int nerr; + int perr; } nn_errnos[] = { { NNG_EINTR, EINTR }, @@ -82,6 +82,13 @@ nn_seterror(int err) int +nn_errno(void) +{ + return (errno); +} + + +int nn_socket(int domain, int protocol) { nng_socket sock; @@ -498,8 +505,8 @@ nn_sendmsg(int s, const struct nn_msghdr *mh, int flags) // because we have to copy the data, but we should // only free this message on success. So we save the // message now. - cdata = *(void **)cdata; - cmsg = *(nng_msg **)(cdata - sizeof (cmsg)); + cdata = *(void **) cdata; + cmsg = *(nng_msg **) (cdata - sizeof (cmsg)); clen = nng_msg_len(cmsg); } if ((rv = nng_msg_append_header(msg, cdata, clen)) != 0) { @@ -512,7 +519,7 @@ nn_sendmsg(int s, const struct nn_msghdr *mh, int flags) } sz = nng_msg_len(msg); - if ((rv = nng_sendmsg((nng_socket)s, msg, flags)) != 0) { + if ((rv = nng_sendmsg((nng_socket) s, msg, flags)) != 0) { if (!keep) { nng_msg_free(msg); } @@ -524,5 +531,126 @@ nn_sendmsg(int s, const struct nn_msghdr *mh, int flags) // We sent successfully, so free up the control message. nng_msg_free(cmsg); } - return ((int)sz); + return ((int) sz); +} + + +int +nn_setsockopt(int s, int nnlevel, int nnopt, const void *valp, size_t sz) +{ + int opt = 0; + int mscvt = 0; + uint64_t usec; + int rv; + + switch (nnlevel) { + case NN_SOL_SOCKET: + switch (nnopt) { + case NN_LINGER: + opt = NNG_OPT_LINGER; + break; + case NN_SNDBUF: + opt = NNG_OPT_SNDBUF; + break; + case NN_RCVBUF: + opt = NNG_OPT_RCVBUF; + break; + case NN_RECONNECT_IVL: + opt = NNG_OPT_RECONN_TIME; + mscvt = 1; + break; + case NN_RECONNECT_IVL_MAX: + opt = NNG_OPT_RECONN_MAXTIME; + mscvt = 1; + break; + case NN_SNDFD: + opt = NNG_OPT_SNDFD; + break; + case NN_RCVFD: + opt = NNG_OPT_RCVFD; + break; + case NN_RCVMAXSIZE: + opt = NNG_OPT_RCVMAXSZ; + break; + case NN_MAXTTL: + opt = NNG_OPT_MAXTTL; + break; + case NN_RCVTIMEO: + opt = NNG_OPT_RCVTIMEO; + mscvt = 1; + break; + case NN_SNDTIMEO: + opt = NNG_OPT_SNDTIMEO; + mscvt = 1; + break; + case NN_DOMAIN: + case NN_PROTOCOL: + case NN_IPV4ONLY: + case NN_SOCKET_NAME: + case NN_SNDPRIO: + case NN_RCVPRIO: + default: + errno = ENOPROTOOPT; + return (-1); + + break; + } + break; + case NN_REQ: + switch (nnopt) { + case NN_REQ_RESEND_IVL: + opt = NNG_OPT_RESENDTIME; + mscvt = 1; + break; + default: + errno = ENOPROTOOPT; + return (-1); + } + break; + case NN_SUB: + switch (nnopt) { + case NN_SUB_SUBSCRIBE: + opt = NNG_OPT_SUBSCRIBE; + break; + case NN_SUB_UNSUBSCRIBE: + opt = NNG_OPT_UNSUBSCRIBE; + break; + default: + errno = ENOPROTOOPT; + return (-1); + } + break; + case NN_SURVEYOR: + switch (nnopt) { + case NN_SURVEY_DEADLINE: + opt = NNG_OPT_SURVEYTIME; + mscvt = 1; + break; + default: + errno = ENOPROTOOPT; + return (-1); + } + default: + errno = ENOPROTOOPT; + return (-1); + } + + if (mscvt) { + // We have to convert value to ms... + + if (sz != sizeof (int)) { + errno = EINVAL; + return (-1); + } + usec = *(int *) valp; + usec *= 1000; + valp = &usec; + sz = sizeof (usec); + } + + if ((rv = nng_setopt((nng_socket) s, opt, valp, sz)) != 0) { + nn_seterror(rv); + return (-1); + } + return (0); } |
