diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-08-08 00:33:19 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-08-08 00:33:19 -0700 |
| commit | 50532054c0bee3a1ff3324db10f3cdf7b44041e4 (patch) | |
| tree | 6e924d21e7eb188865d98e9daa203a045cc928c5 /src/nng_compat.c | |
| parent | 702fe1d0af4b08a8b53172aaca57394b181d58b2 (diff) | |
| download | nng-50532054c0bee3a1ff3324db10f3cdf7b44041e4.tar.gz nng-50532054c0bee3a1ff3324db10f3cdf7b44041e4.tar.bz2 nng-50532054c0bee3a1ff3324db10f3cdf7b44041e4.zip | |
Added nn_compat code for option handling, fixed other bugs.
Hop counts for REQ were busted (bad TTL), and imported the
compat_reqtll test. At the same time, added code to nn_term
to shut down completely, discarding sockets. (Note that some
things, such as globals, may still be left around; that's ok.)
Diffstat (limited to 'src/nng_compat.c')
| -rw-r--r-- | src/nng_compat.c | 139 |
1 files changed, 133 insertions, 6 deletions
diff --git a/src/nng_compat.c b/src/nng_compat.c index 160fd33d..88e2f69c 100644 --- a/src/nng_compat.c +++ b/src/nng_compat.c @@ -60,7 +60,7 @@ nn_strerror(int err) return ("Unknown I/O error"); } - // Arguablye we could use strerror() here, but we should only + // Arguably we could use strerror() here, but we should only // be getting errnos we understand at this point. (void) snprintf(msgbuf, sizeof(msgbuf), "Unknown error %d", err); return (msgbuf); @@ -536,6 +536,133 @@ nn_sendmsg(int s, const struct nn_msghdr *mh, int flags) } int +nn_getsockopt(int s, int nnlevel, int nnopt, void *valp, size_t *szp) +{ + int opt = 0; + int mscvt = 0; + uint64_t usec; + int * msecp; + 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_SURVEYOR_DEADLINE: + opt = NNG_OPT_SURVEYTIME; + mscvt = 1; + break; + default: + errno = ENOPROTOOPT; + return (-1); + } + break; + default: + errno = ENOPROTOOPT; + return (-1); + } + + if (mscvt) { + if (*szp != sizeof(int)) { + errno = EINVAL; + return (-1); + } + + msecp = valp; + valp = &usec; + *szp = sizeof(uint64_t); + } + + if ((rv = nng_getopt((nng_socket) s, opt, valp, szp)) != 0) { + nn_seterror(rv); + return (-1); + } + + if (mscvt) { + // We have to convert value to ms... + *msecp = (usec / 1000); + *szp = sizeof(int); + } + + return (0); +} + +int nn_setsockopt(int s, int nnlevel, int nnopt, const void *valp, size_t sz) { int opt = 0; @@ -703,11 +830,11 @@ nn_device(int s1, int s2) void nn_term(void) { - // XXX: Implement something to do something. Probably we - // should go through the nni_sockets idhash and clobber all - // of the sockets. This function is relatively toxic, since - // it can affect all sockets in the process, including those - // in use by libraries, etc. + // This function is relatively toxic, since it can affect + // all sockets in the process, including those + // in use by libraries, etc. Accordingly, do not use this + // in a library -- only e.g. atexit() and similar. + nng_closeall(); } // Internal test support routines. |
