Skip to content

Commit

Permalink
remove NNG_OPT_SOCKNAME (and socket names altogether)
Browse files Browse the repository at this point in the history
This functionality was provided principally for libnanomsg compatibility.
This saves some memory and eliminates some pointless functionality.

While here, updated the socket options documentation to remove references
to options already removed.
  • Loading branch information
gdamore committed Nov 17, 2024
1 parent 84ea0ee commit 48d0c03
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 234 deletions.
101 changes: 0 additions & 101 deletions docs/man/nng_options.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,8 @@ nng_options - socket, dialer, listener, and pipe options
----
#include <nng/nng.h>
#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"
#define NNG_OPT_SENDFD "send-fd"
#define NNG_OPT_RECVTIMEO "recv-timeout"
#define NNG_OPT_SENDTIMEO "send-timeout"
#define NNG_OPT_LOCADDR "local-address"
Expand Down Expand Up @@ -153,36 +145,6 @@ This value must be an integer between 0 and 8192, inclusive.
NOTE: Not all protocols support buffering received messages.
For example xref:nng_req.7.adoc[_req_] can only deal with a single reply at a time.

[[NNG_OPT_RECVFD]]
((`NNG_OPT_RECVFD`))::
(((poll)))
(((select)))
(((receive, polling)))
(`int`)
This read-only option is used to obtain an integer file descriptor suitable
for use with
http://pubs.opengroup.org/onlinepubs/7908799/xsh/poll.html[`poll()`],
http://pubs.opengroup.org/onlinepubs/7908799/xsh/select.html[`select()`],
(or on Windows systems
https://msdn.microsoft.com/en-us/library/windows/desktop/ms741669(v=vs.85).aspx[`WSAPoll()`])
and similar functions.
This descriptor will be *readable* when a message is available for receiving
on the socket.
When no message is ready for receiving, then this file descriptor will *not*
be readable.
+
IMPORTANT: Applications should never attempt to read or write to the
returned file descriptor.
+
IMPORTANT: This option is incompatible with
xref:nng_ctx.5.adoc[`nng_ctx`] contexts and should not be used on a socket
where they are in use.
+
TIP: While this option may help applications integrate into existing polling
loops, it is more efficient, and often easier, to use the asynchronous I/O
objects instead.
See xref:nng_aio_alloc.3.adoc[`nng_aio_alloc()`].

[[NNG_OPT_RECVMAXSZ]]
((`NNG_OPT_RECVMAXSZ`))::
(((receive, maximum size)))
Expand Down Expand Up @@ -240,37 +202,6 @@ NOTE: Not all protocols support buffering sent messages.
For example, xref:nng_req.7.adoc[_req_] can only have a single request
outstanding at a time (per context).

[[NNG_OPT_SENDFD]]
((`NNG_OPT_SENDFD`))::
(((poll)))
(((select)))
(((send, polling)))
(`int`)
This read-only option is used to obtain an integer file descriptor suitable
for use with
http://pubs.opengroup.org/onlinepubs/7908799/xsh/poll.html[`poll()`],
http://pubs.opengroup.org/onlinepubs/7908799/xsh/select.html[`select()`],
(or on Windows systems
https://msdn.microsoft.com/en-us/library/windows/desktop/ms741669(v=vs.85).aspx[`WSAPoll()`])
and similar functions.
+
This descriptor will be *readable* when the socket is able to accept a
message for sending without blocking.
When the socket is no longer able to accept such messages without blocking,
the descriptor will *not* be readable.
+
IMPORTANT: Applications should never attempt to read or write to the
returned file descriptor; use should be limited to polling system calls only.
+
IMPORTANT: This option is incompatible with
xref:nng_ctx.5.adoc[`nng_ctx`] contexts and should not be used on a socket
where they are in use.
+
TIP: While this option may help applications integrate into existing polling
loops, it is more efficient, and often easier, to use the asynchronous I/O
objects instead.
See xref:nng_aio_alloc.3.adoc[`nng_aio_alloc()`].

[[NNG_OPT_SENDTIMEO]]
((`NNG_OPT_SENDTIMEO`))::
(((send, timeout)))
Expand All @@ -281,17 +212,6 @@ When a message cannot be queued for delivery by the socket for this period of
time (such as if send buffers are full), the operation will fail with a
return value of `NNG_ETIMEDOUT`.

[[NNG_OPT_SOCKNAME]]
((`NNG_OPT_SOCKNAME`))::
(((name, socket)))
(string)
This the socket name.
By default, this is a string corresponding to the value of the socket.
The string must fit within 64-bytes, including the terminating
`NUL` byte.
The value is intended for application use, and is not used for anything
in the library itself.

[[NNG_OPT_MAXTTL]]
((`NNG_OPT_MAXTTL`))::
(`int`)
Expand Down Expand Up @@ -321,17 +241,6 @@ 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_PEER_GID]]
((`NNG_OPT_PEER_GID`))::
(`uint64_t`)
Expand Down Expand Up @@ -365,16 +274,6 @@ This option is generally only available on POSIX systems, on certain transports.
This read-only option provides a connected peer's the zone id.
Zones (and this option) are only supported on Solaris and illumos systems, on select transports.

[[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_PROTONAME]]
((`NNG_OPT_PROTONAME`))::
(string)
This read-only option is used to obtain the name of the socket's protocol.

== SEE ALSO

[.text-left]
Expand Down
2 changes: 1 addition & 1 deletion docs/ref/migrate/nanomsg.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The following options are changed.
| `NN_DOMAIN` | None | NNG options are not divided by domain or protocol. |
| `NN_PROTOCOL` | [`nng_socket_proto_id`] | No longer an option. See also `nng_socket_proto_name`. |
| `NN_IPV4ONLY` | None | Use URL such as `tcp4://` to obtain this functionality. |
| `NN_SOCKET_NAME` | `NNG_OPT_SOCKNAME` |
| `NN_SOCKET_NAME` | None | Removed from NNG. |
| `NN_MAXTTL` | `NNG_OPT_MAXTTL` |
| `NN_SUB_SUBSCRIBE` | [`nng_sub0_socket_subscribe`] | No longer an option, use a function call. |
| `NN_SUB_UNSUBSCRIBE` | [`nng_sub0_socket_unsubscribe`] | No longer an option, use a function call. |
Expand Down
3 changes: 3 additions & 0 deletions docs/ref/migrate/nng1.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ The `NNG_OPT_RAW` option has aso been replaced by a function, [`nng_socket_raw`]
The `NNG_OPT_SENDFD` and `NNG_OPT_RECVFD` options have been replaced by
[`nng_socket_get_send_poll_fd`] and [`nng_socket_get_recv_poll_fd`] respectively.

The `NNG_OPT_SOCKNAME` function is removed. This was provided for application use, and never used internally by NNG.
Applications should keep track of this information separately.

## Subscriptions

The `NNG_OPT_SUB_SUBSCRIBE` and `NNG_OPT_SUB_UNSUBCRIBE` options have been replaced by
Expand Down
1 change: 0 additions & 1 deletion include/nng/nng.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,6 @@ NNG_DECL nng_listener nng_pipe_listener(nng_pipe);
#define NNG_FLAG_NONBLOCK 2u // Non-blocking operations

// Options.
#define NNG_OPT_SOCKNAME "socket-name"
#define NNG_OPT_RECVBUF "recv-buffer"
#define NNG_OPT_SENDBUF "send-buffer"
#define NNG_OPT_RECVTIMEO "recv-timeout"
Expand Down
81 changes: 0 additions & 81 deletions src/core/sock_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,76 +93,6 @@ test_socket_base(void)
NUTS_CLOSE(s1);
}

void
test_socket_name(void)
{
nng_socket s1;
char *str;
long id;
char *end;
char *name;

NUTS_OPEN(s1);
NUTS_PASS(nng_socket_get_string(s1, NNG_OPT_SOCKNAME, &name));
NUTS_TRUE(strlen(name) > 0);
NUTS_TRUE(strlen(name) < 64);
id = strtol(name, &end, 10);
NUTS_TRUE(id == (long) s1.id);
NUTS_TRUE(end != NULL && *end == '\0');
nng_strfree(name);

NUTS_PASS(nng_socket_set_string(s1, NNG_OPT_SOCKNAME, "hello"));
NUTS_PASS(nng_socket_get_string(s1, NNG_OPT_SOCKNAME, &name));
NUTS_MATCH(name, "hello");
nng_strfree(name);

char buf[128];
memset(buf, 'A', 128);
buf[127] = 0;

// strings must not be too long
NUTS_FAIL(
nng_socket_set_string(s1, NNG_OPT_SOCKNAME, buf), NNG_EINVAL);
memset(buf, 'A', 64);
buf[64] = 0;
NUTS_FAIL(
nng_socket_set_string(s1, NNG_OPT_SOCKNAME, buf), NNG_EINVAL);
buf[63] = 0;
NUTS_PASS(nng_socket_set_string(s1, NNG_OPT_SOCKNAME, buf));
NUTS_PASS(nng_socket_set_string(s1, NNG_OPT_SOCKNAME, "hello"));

NUTS_PASS(nng_socket_get_string(s1, NNG_OPT_SOCKNAME, &str));
NUTS_ASSERT(str != NULL);
NUTS_TRUE(strlen(str) == 5);
NUTS_MATCH(str, "hello");
nng_strfree(str);

NUTS_CLOSE(s1);
}

void
test_socket_name_oversize(void)
{
nng_socket s1;
char buf[256]; // 64 is max
size_t sz = sizeof(buf);
char *name;

memset(buf, 'A', sz);
NUTS_OPEN(s1);

buf[sz - 1] = '\0';
NUTS_FAIL(
nng_socket_set_string(s1, NNG_OPT_SOCKNAME, buf), NNG_EINVAL);

strcpy(buf, "hello");
NUTS_PASS(nng_socket_set_string(s1, NNG_OPT_SOCKNAME, buf));
NUTS_PASS(nng_socket_get_string(s1, NNG_OPT_SOCKNAME, &name));
NUTS_MATCH(name, "hello");
nng_strfree(name);
NUTS_CLOSE(s1);
}

void
test_send_recv(void)
{
Expand Down Expand Up @@ -402,12 +332,7 @@ test_listener_options(void)
nng_listener_set_bool(l, NNG_OPT_RECVMAXSZ, true), NNG_EBADTYPE);

// Cannot set inappropriate options
NUTS_FAIL(
nng_listener_set_string(l, NNG_OPT_SOCKNAME, "1"), NNG_ENOTSUP);

NUTS_FAIL(nng_listener_set_ms(l, NNG_OPT_RECONNMINT, 1), NNG_ENOTSUP);
NUTS_FAIL(nng_listener_set_string(l, NNG_OPT_SOCKNAME, "bogus"),
NNG_ENOTSUP);

// Read only options
NUTS_FAIL(nng_listener_set_string(l, NNG_OPT_URL, "inproc://junk"),
Expand Down Expand Up @@ -436,11 +361,7 @@ test_dialer_options(void)
nng_dialer_set_bool(d, NNG_OPT_RECVMAXSZ, true), NNG_EBADTYPE);

// Cannot set inappropriate options
NUTS_FAIL(
nng_dialer_set_string(d, NNG_OPT_SOCKNAME, "1"), NNG_ENOTSUP);
NUTS_FAIL(nng_dialer_set_ms(d, NNG_OPT_SENDTIMEO, 1), NNG_ENOTSUP);
NUTS_FAIL(
nng_dialer_set_string(d, NNG_OPT_SOCKNAME, "bogus"), NNG_ENOTSUP);

// Read only options
NUTS_FAIL(nng_dialer_set_string(d, NNG_OPT_URL, "inproc://junk"),
Expand Down Expand Up @@ -542,8 +463,6 @@ NUTS_TESTS = {
{ "send timeout", test_send_timeout },
{ "send non-block", test_send_nonblock },
{ "socket base", test_socket_base },
{ "socket name", test_socket_name },
{ "socket name oversize", test_socket_name_oversize },
{ "send recv", test_send_recv },
{ "send recv zero length", test_send_recv_zero_length },
{ "connection refused", test_connection_refused },
Expand Down
40 changes: 0 additions & 40 deletions src/core/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ struct nni_socket {
nni_duration s_reconn; // reconnect time
nni_duration s_reconnmax; // max reconnect time
size_t s_rcvmaxsz; // max receive size
char s_name[64]; // socket name (legacy compat)

nni_list s_listeners; // active listeners
nni_list s_dialers; // active dialers
Expand All @@ -109,7 +108,6 @@ struct nni_socket {
#ifdef NNG_ENABLE_STATS
nni_stat_item st_root; // socket scope
nni_stat_item st_id; // socket id
nni_stat_item st_name; // socket name
nni_stat_item st_protocol; // socket protocol
nni_stat_item st_dialers; // number of dialers
nni_stat_item st_listeners; // number of listeners
Expand Down Expand Up @@ -255,27 +253,6 @@ sock_get_sendbuf(void *s, void *buf, size_t *szp, nni_type t)
return (nni_copyout_int(len, buf, szp, t));
}

static int
sock_get_sockname(void *s, void *buf, size_t *szp, nni_type t)
{
return (nni_copyout_str(SOCK(s)->s_name, buf, szp, t));
}

static int
sock_set_sockname(void *s, const void *buf, size_t sz, nni_type t)
{
int rv;
NNI_ARG_UNUSED(sz);
rv =
(nni_copyin_str(SOCK(s)->s_name, buf, sizeof(SOCK(s)->s_name), t));
#ifdef NNG_ENABLE_STATS
if (rv == 0) {
nni_stat_set_string(&SOCK(s)->st_name, SOCK(s)->s_name);
}
#endif
return (rv);
}

static const nni_option sock_options[] = {
{
.o_name = NNG_OPT_RECVTIMEO,
Expand All @@ -297,11 +274,6 @@ static const nni_option sock_options[] = {
.o_get = sock_get_sendbuf,
.o_set = sock_set_sendbuf,
},
{
.o_name = NNG_OPT_SOCKNAME,
.o_get = sock_get_sockname,
.o_set = sock_set_sockname,
},
{
.o_name = NNG_OPT_RECONNMINT,
.o_get = sock_get_reconnmint,
Expand Down Expand Up @@ -423,12 +395,6 @@ sock_stats_init(nni_sock *s)
.si_desc = "socket identifier",
.si_type = NNG_STAT_ID,
};
static const nni_stat_info name_info = {
.si_name = "name",
.si_desc = "socket name",
.si_type = NNG_STAT_STRING,
.si_alloc = true,
};
static const nni_stat_info protocol_info = {
.si_name = "protocol",
.si_desc = "socket protocol",
Expand Down Expand Up @@ -492,7 +458,6 @@ sock_stats_init(nni_sock *s)

nni_stat_init(&s->st_root, &root_info);
sock_stat_init(s, &s->st_id, &id_info);
sock_stat_init(s, &s->st_name, &name_info);
sock_stat_init(s, &s->st_protocol, &protocol_info);
sock_stat_init(s, &s->st_dialers, &dialers_info);
sock_stat_init(s, &s->st_listeners, &listeners_info);
Expand All @@ -504,7 +469,6 @@ sock_stats_init(nni_sock *s)
sock_stat_init(s, &s->st_rx_bytes, &rx_bytes_info);

nni_stat_set_id(&s->st_id, (int) s->s_id);
nni_stat_set_string(&s->st_name, s->s_name);
nni_stat_set_string(&s->st_protocol, nni_sock_proto_name(s));
}
#endif
Expand Down Expand Up @@ -634,15 +598,11 @@ nni_sock_open(nni_sock **sockp, const nni_proto *proto)
}
nni_mtx_unlock(&sock_lk);

// Set the socket name.
(void) snprintf(s->s_name, sizeof(s->s_name), "%u", s->s_id);

#ifdef NNG_ENABLE_STATS
// Set up basic stat values. The socket id wasn't
// known at stat creation time, so we set it now.
nni_stat_set_id(&s->st_id, (int) s->s_id);
nni_stat_set_id(&s->st_root, (int) s->s_id);
nni_stat_set_string(&s->st_name, s->s_name);

// Add our stats chain.
nni_stat_register(&s->st_root);
Expand Down
Loading

0 comments on commit 48d0c03

Please sign in to comment.