diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-04-30 13:15:41 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-04-30 13:34:04 -0700 |
| commit | 264ed002f15645193ad53d4ba51218365d979699 (patch) | |
| tree | c4ed06d8ffd65bbdf9d94f994c96cecb17f56c81 | |
| parent | 2b0d31553e542c130e2595ff9a3ac9756a2c1619 (diff) | |
| download | nng-264ed002f15645193ad53d4ba51218365d979699.tar.gz nng-264ed002f15645193ad53d4ba51218365d979699.tar.bz2 nng-264ed002f15645193ad53d4ba51218365d979699.zip | |
fixes #384 Add NN_PROTOCOL and related
| -rw-r--r-- | docs/man/nn_getsockopt.3compat.adoc | 7 | ||||
| -rw-r--r-- | docs/man/nn_setsockopt.3compat.adoc | 5 | ||||
| -rw-r--r-- | docs/man/nng_compat.3compat.adoc | 6 | ||||
| -rw-r--r-- | docs/man/nng_options.5.adoc | 27 | ||||
| -rw-r--r-- | src/compat/nanomsg/nn.c | 5 | ||||
| -rw-r--r-- | src/core/socket.c | 48 | ||||
| -rw-r--r-- | src/nng.h | 4 | ||||
| -rw-r--r-- | tests/reqrep.c | 30 |
8 files changed, 121 insertions, 11 deletions
diff --git a/docs/man/nn_getsockopt.3compat.adoc b/docs/man/nn_getsockopt.3compat.adoc index f4988093..24e13861 100644 --- a/docs/man/nn_getsockopt.3compat.adoc +++ b/docs/man/nn_getsockopt.3compat.adoc @@ -137,11 +137,12 @@ NOTE: Not all protocols offer this protection, so care should still be used in configuring device forwarding. `NN_DOMAIN`:: -This contains either the value `AF_SP` or `AF_SP_RAW`, corresponding -to the value that the socket was created with. +This option of type `int` represents either the value `AF_SP` or `AF_SP_RAW`, +corresponding to the value that the socket was created with. `NN_PROTOCOL`:: -This option is not supported at this time. +This option option of type `int` contains the numeric protocol number +that the socket is used with. `NN_RCVFD`:: This option returns a file descriptor suitable for use in with `poll()` or diff --git a/docs/man/nn_setsockopt.3compat.adoc b/docs/man/nn_setsockopt.3compat.adoc index 076ebec6..7869c832 100644 --- a/docs/man/nn_setsockopt.3compat.adoc +++ b/docs/man/nn_setsockopt.3compat.adoc @@ -130,11 +130,6 @@ This value, if positive, provides some protection against forwarding loops in NOTE: Not all protocols offer this protection, so care should still be used in configuring device forwarding. -// NN_DOMAIN is readonly. -// NN_PROTOCOL is not supported. -// NN_RCVFD is read-only. -// NN_SNDFD is read-only. - The following option is available for `NN_REQ` sockets using the `NN_REQ` level: diff --git a/docs/man/nng_compat.3compat.adoc b/docs/man/nng_compat.3compat.adoc index 9029fb05..f46fc7df 100644 --- a/docs/man/nng_compat.3compat.adoc +++ b/docs/man/nng_compat.3compat.adoc @@ -115,9 +115,9 @@ 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_. +`NN_IPC_INBUFSZ`, `NN_OUTBUFSZ`, `NN_SNDPRIO`, `NN_RCVPRIO`, `NN_IPV4ONLY`. +Some of these may be supported in the future when the relevant support +is added to _nng_. NOTE: Access to statistics using this legacy API (`<<nn_get_statistic.3compat#,nn_get_statistic()>>`) is unsupported. diff --git a/docs/man/nng_options.5.adoc b/docs/man/nng_options.5.adoc index e6ed1f7b..9db3d660 100644 --- a/docs/man/nng_options.5.adoc +++ b/docs/man/nng_options.5.adoc @@ -21,6 +21,10 @@ nng_options - socket, dialer, listener, and pipe options #define NNG_OPT_SOCKNAME "socket-name" #define NNG_OPT_RAW "raw" +#define NNG_OPT_PROTO "protocol" +#define NNG_OPT_PROTONAME "protocol-name" +#define NNG_OPT_PEER "peer" +#define NNG_OPT_PEERNAME "peer-name" #define NNG_OPT_RECVBUF "recv-buffer" #define NNG_OPT_SENDBUF "send-buffer" #define NNG_OPT_RECVFD "recv-fd" @@ -288,6 +292,29 @@ Accordingly it can only be used with dialers, listeners, and pipes. NOTE: Some transports will canonify URLs before returning them to the application. +[[NNG_OPT_PROTO]] +((`NNG_OPT_PROTO`)):: +(`int`) +This read-only option is used to obtain the 16-bit number for the socket's protocol. + +[[NNG_OPT_PEER]] +((`NNG_OPT_PEER`)):: +(`int`) +This read-only option is used to obtain the 16-bit number of the +peer protocol for the socket. + + +[[NNG_OPT_PROTONAME]] +((`NNG_OPT_PROTONAME`)):: +(string) +This read-only option is used to obtain the name of the socket's protocol. + +[[NNG_OPT_PEERNAME]] +((`NNG_OPT_PEERNAME`)):: +(string) +This read-only option is used to obtain the name of the peer protocol for +the socket. + [[NNG_OPT_TCP_NODELAY]] ((`NNG_OPT_TCP_NODELAY`)):: (`bool``) diff --git a/src/compat/nanomsg/nn.c b/src/compat/nanomsg/nn.c index 0eb97298..03df279b 100644 --- a/src/compat/nanomsg/nn.c +++ b/src/compat/nanomsg/nn.c @@ -884,6 +884,11 @@ static const struct { }, { .nnlevel = NN_SOL_SOCKET, + .nnopt = NN_PROTOCOL, + .opt = NNG_OPT_PROTO, + }, + { + .nnlevel = NN_SOL_SOCKET, .nnopt = NN_SOCKET_NAME, .opt = NNG_OPT_SOCKNAME, }, diff --git a/src/core/socket.c b/src/core/socket.c index 5a581cd3..f5acd941 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -251,6 +251,30 @@ nni_sock_setopt_sockname(nni_sock *s, const void *buf, size_t sz, int typ) return (nni_copyin_str(s->s_name, buf, sizeof(s->s_name), sz, typ)); } +static int +nni_sock_getopt_proto(nni_sock *s, void *buf, size_t *szp, int typ) +{ + return (nni_copyout_int(nni_sock_proto(s), buf, szp, typ)); +} + +static int +nni_sock_getopt_peer(nni_sock *s, void *buf, size_t *szp, int typ) +{ + return (nni_copyout_int(nni_sock_peer(s), buf, szp, typ)); +} + +static int +nni_sock_getopt_protoname(nni_sock *s, void *buf, size_t *szp, int typ) +{ + return (nni_copyout_str(nni_sock_proto_name(s), buf, szp, typ)); +} + +static int +nni_sock_getopt_peername(nni_sock *s, void *buf, size_t *szp, int typ) +{ + return (nni_copyout_str(nni_sock_peer_name(s), buf, szp, typ)); +} + static const nni_socket_option nni_sock_options[] = { { .so_name = NNG_OPT_RECVTIMEO, @@ -312,6 +336,30 @@ static const nni_socket_option nni_sock_options[] = { .so_getopt = nni_sock_getopt_raw, .so_setopt = NULL, }, + { + .so_name = NNG_OPT_PROTO, + .so_type = NNI_TYPE_INT32, + .so_getopt = nni_sock_getopt_proto, + .so_setopt = NULL, + }, + { + .so_name = NNG_OPT_PEER, + .so_type = NNI_TYPE_INT32, + .so_getopt = nni_sock_getopt_peer, + .so_setopt = NULL, + }, + { + .so_name = NNG_OPT_PROTONAME, + .so_type = NNI_TYPE_STRING, + .so_getopt = nni_sock_getopt_protoname, + .so_setopt = NULL, + }, + { + .so_name = NNG_OPT_PEERNAME, + .so_type = NNI_TYPE_STRING, + .so_getopt = nni_sock_getopt_peername, + .so_setopt = NULL, + }, // terminate list { .so_name = NULL, @@ -583,6 +583,10 @@ enum nng_flag_enum { // Options. #define NNG_OPT_SOCKNAME "socket-name" #define NNG_OPT_RAW "raw" +#define NNG_OPT_PROTO "protocol" +#define NNG_OPT_PROTONAME "protocol-name" +#define NNG_OPT_PEER "peer" +#define NNG_OPT_PEERNAME "peer-name" #define NNG_OPT_RECVBUF "recv-buffer" #define NNG_OPT_SENDBUF "send-buffer" #define NNG_OPT_RECVFD "recv-fd" diff --git a/tests/reqrep.c b/tests/reqrep.c index 76cf279c..b5a32dcf 100644 --- a/tests/reqrep.c +++ b/tests/reqrep.c @@ -27,6 +27,21 @@ TestMain("REQ/REP pattern", { Reset({ nng_close(req); }); + Convey("Protocol & peer options match", { + int p; + char *s; + So(nng_getopt_int(req, NNG_OPT_PROTO, &p) == 0); + So(p == 48); + So(nng_getopt_string(req, NNG_OPT_PROTONAME, &s) == 0); + So(strcmp(s, "req") == 0); + nng_strfree(s); + So(nng_getopt_int(req, NNG_OPT_PEER, &p) == 0); + So(p == 49); + So(nng_getopt_string(req, NNG_OPT_PEERNAME, &s) == 0); + So(strcmp(s, "rep") == 0); + nng_strfree(s); + }); + Convey("Resend time option id works", { // Set timeout. @@ -50,6 +65,21 @@ TestMain("REQ/REP pattern", { Reset({ nng_close(rep); }); + Convey("Protocol & peer options match", { + int p; + char *s; + So(nng_getopt_int(rep, NNG_OPT_PROTO, &p) == 0); + So(p == 49); + So(nng_getopt_string(rep, NNG_OPT_PROTONAME, &s) == 0); + So(strcmp(s, "rep") == 0); + nng_strfree(s); + So(nng_getopt_int(rep, NNG_OPT_PEER, &p) == 0); + So(p == 48); + So(nng_getopt_string(rep, NNG_OPT_PEERNAME, &s) == 0); + So(strcmp(s, "req") == 0); + nng_strfree(s); + }); + Convey("Send with no recv fails", { nng_msg *msg; rv = nng_msg_alloc(&msg, 0); |
