diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-03-17 17:21:43 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-03-17 17:21:43 -0700 |
| commit | 2e6f76636e2adbc5e2bc4659a0639d83eb3f2d59 (patch) | |
| tree | 9c4e71aba9f8209e052362be6a32d6bebcff48b8 | |
| parent | 48bda13b2f3f985389bd3caba923eea77d49c6be (diff) | |
| download | nng-2e6f76636e2adbc5e2bc4659a0639d83eb3f2d59.tar.gz nng-2e6f76636e2adbc5e2bc4659a0639d83eb3f2d59.tar.bz2 nng-2e6f76636e2adbc5e2bc4659a0639d83eb3f2d59.zip | |
fixes #287 remove NNG_OPT_DOMAIN, NNG_OPT_PROTOCOL, and NNG_OPT_TRANSPORT
While here we documented that certain options are not supported in the
compatibility layer.
| -rw-r--r-- | docs/man/nng_compat.3compat.adoc | 45 | ||||
| -rw-r--r-- | src/compat/nanomsg/nn.c | 21 | ||||
| -rw-r--r-- | src/core/socket.c | 17 | ||||
| -rw-r--r-- | src/nng.h | 3 | ||||
| -rw-r--r-- | tests/sock.c | 16 |
5 files changed, 71 insertions, 31 deletions
diff --git a/docs/man/nng_compat.3compat.adoc b/docs/man/nng_compat.3compat.adoc index cc6271f4..a0ac64c2 100644 --- a/docs/man/nng_compat.3compat.adoc +++ b/docs/man/nng_compat.3compat.adoc @@ -79,6 +79,51 @@ supplied here later. In the meantime it can be found online at the http://nanomsg.org[nanomsg site]. +There are a few caveats, that should be kept in mind. + +NOTE: Socket numbers can be quite large. +The legacy _libnanomsg_ attempted to reuse socket numbers, like +file descriptors in UNIX systems. +The _nng_ library avoids this to prevent accidental reuse or +collision after a descriptor is closed. +Consequently, socket numbers can become quite large, and should +probably not be used for array indices. + +NOTE: The following options (`nn_getsockopt`) are unsupported: +`NN_PROTOCOL`, `NN_SNDPRIO`, `NN_RCVPRIO`, `NN_IPV4ONLY`. +Some of these will probably be added back in the future when +the relevant support is added to _nng_. + +NOTE: Statistics (`nn_get_statistic`) are unsupported. +The plan is to support statistics in the native _nng_ API, but +we think there is no need for this in a compatibility layer. +Hence, this function returns `ENOTSUP`. + +NOTE: Some transports can support longer URLs than legacy _libnanomsg_ can. +It is a good idea to use short pathnames in URLs if interoperability +is a concern. + +NOTE: Some transports are unusable from this mode. +In particular, this legacy API offers no way to configure +TLS parameters that are required for use. + +NOTE: ABI versioning is not supported. +We don't offer the `NN_VERSION_` macros. Sorry. + +NOTE: Runtime symbol information is not implemented. +Specifically, there is no `nn_symbol()` function yet. +(This may be addressed later if there is a need.) + +IMPORTANT: The `nn_term()` function is destructive and should be avoided. +This function closes down all sockets, and really there is no good +reason to ever use it. +Removal from existing code is advised. +(Keep track of sockets and close them explicitly if necessary.) + +IMPORTANT: It *is* possible at present to intermix sockets between the new and +the old APIs, but this is not a guaranteed feature, and should only +be used temporarily to facilitate transitioning code to the new APIs. + // === Common Functions // // The following common functions exist in _libnng_. diff --git a/src/compat/nanomsg/nn.c b/src/compat/nanomsg/nn.c index 1d5bcfbb..01b51503 100644 --- a/src/compat/nanomsg/nn.c +++ b/src/compat/nanomsg/nn.c @@ -613,7 +613,6 @@ static const struct { { NN_SOL_SOCKET, NN_MAXTTL, NNG_OPT_MAXTTL }, { NN_SOL_SOCKET, NN_RCVTIMEO, NNG_OPT_RECVTIMEO }, { NN_SOL_SOCKET, NN_SNDTIMEO, NNG_OPT_SENDTIMEO }, - { NN_SOL_SOCKET, NN_DOMAIN, NNG_OPT_DOMAIN }, { NN_SOL_SOCKET, NN_SOCKET_NAME, NNG_OPT_SOCKNAME }, { NN_REQ, NN_REQ_RESEND_IVL, NNG_OPT_REQ_RESENDTIME }, { NN_SUB, NN_SUB_SUBSCRIBE, NNG_OPT_SUB_SUBSCRIBE }, @@ -622,6 +621,22 @@ static const struct { // XXX: IPV4ONLY, SNDPRIO, RCVPRIO }; +static int +nn_getdomain(int s, void *valp, size_t *szp) +{ + int i; + int rv; + + if ((rv = nng_getopt_int((nng_socket) s, NNG_OPT_RAW, &i)) != 0) { + nn_seterror(rv); + return (-1); + } + i = i ? AF_SP_RAW : AF_SP; + memcpy(valp, &i, *szp < sizeof(int) ? *szp : sizeof(int)); + *szp = sizeof(int); + return (0); +} + int nn_getsockopt(int s, int nnlevel, int nnopt, void *valp, size_t *szp) { @@ -637,6 +652,10 @@ nn_getsockopt(int s, int nnlevel, int nnopt, void *valp, size_t *szp) } if (name == NULL) { + if (nnlevel == NN_SOL_SOCKET && nnopt == NN_DOMAIN) { + return (nn_getdomain(s, valp, szp)); + } + errno = ENOPROTOOPT; return (-1); } diff --git a/src/core/socket.c b/src/core/socket.c index bf97ef8d..440f1bbf 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -37,7 +37,6 @@ struct nni_socket { nni_mtx s_mx; nni_cv s_cv; nni_cv s_close_cv; - int s_raw; uint64_t s_id; uint32_t s_flags; @@ -249,12 +248,6 @@ nni_sock_setopt_sockname(nni_sock *s, const void *buf, size_t sz) return (0); } -static int -nni_sock_getopt_domain(nni_sock *s, void *buf, size_t *szp) -{ - return (nni_getopt_int(s->s_raw + 1, buf, szp)); -} - static const nni_socket_option nni_sock_options[] = { { .so_name = NNG_OPT_RECVTIMEO, @@ -301,11 +294,6 @@ static const nni_socket_option nni_sock_options[] = { .so_getopt = nni_sock_getopt_sockname, .so_setopt = nni_sock_setopt_sockname, }, - { - .so_name = NNG_OPT_DOMAIN, - .so_getopt = nni_sock_getopt_domain, - .so_setopt = NULL, - }, // terminate list { NULL, NULL, NULL }, }; @@ -886,11 +874,6 @@ nni_sock_setopt(nni_sock *s, const char *name, const void *val, size_t size) return (NNG_EREADONLY); } rv = pso->pso_setopt(s->s_data, val, size); - if ((rv == 0) && (strcmp(name, NNG_OPT_RAW) == 0) && - (size >= sizeof(int))) { - // Save the raw option -- we use this for the DOMAIN. - memcpy(&s->s_raw, val, sizeof(int)); - } nni_mtx_unlock(&s->s_mx); return (rv); } @@ -408,7 +408,6 @@ enum nng_flag_enum { // Options. #define NNG_OPT_SOCKNAME "socket-name" -#define NNG_OPT_DOMAIN "compat:domain" // legacy compat only #define NNG_OPT_RAW "raw" #define NNG_OPT_LINGER "linger" #define NNG_OPT_RECVBUF "recv-buffer" @@ -421,8 +420,6 @@ enum nng_flag_enum { #define NNG_OPT_REMADDR "remote-address" #define NNG_OPT_URL "url" #define NNG_OPT_MAXTTL "ttl-max" -#define NNG_OPT_PROTOCOL "protocol" -#define NNG_OPT_TRANSPORT "transport" #define NNG_OPT_RECVMAXSZ "recv-size-max" #define NNG_OPT_RECONNMINT "reconnect-time-min" #define NNG_OPT_RECONNMAXT "reconnect-time-max" diff --git a/tests/sock.c b/tests/sock.c index 1f7567f8..f1570fd8 100644 --- a/tests/sock.c +++ b/tests/sock.c @@ -88,8 +88,6 @@ TestMain("Socket Operations", { NNG_EREADONLY); So(nng_setopt(s1, NNG_OPT_LOCADDR, "a", 1) == NNG_EREADONLY); - So(nng_setopt_int(s1, NNG_OPT_DOMAIN, 3) == - NNG_EREADONLY); }); Convey("Sockname option works", { @@ -121,15 +119,13 @@ TestMain("Socket Operations", { So(strcmp(name, "hello") == 0); }); - Convey("Domain option works", { - int dom; - So(nng_getopt_int(s1, NNG_OPT_DOMAIN, &dom) == - 0); - So(dom == 1); // NN_AF_SP + Convey("RAW option works", { + int raw; + So(nng_getopt_int(s1, NNG_OPT_RAW, &raw) == 0); + So(raw == 0); So(nng_setopt_int(s1, NNG_OPT_RAW, 1) == 0); - So(nng_getopt_int(s1, NNG_OPT_DOMAIN, &dom) == - 0); - So(dom == 2); // NN_AF_SP_RAW + So(nng_getopt_int(s1, NNG_OPT_RAW, &raw) == 0); + So(raw == 1); }); Convey("URL option works", { |
