Skip to content

Commit

Permalink
Remove string option functions from sockets and contexts.
Browse files Browse the repository at this point in the history
These are not needed anymore, and the semantics of string accessors
is brittle, so we want to eliminate these as much as possible.
  • Loading branch information
gdamore committed Nov 24, 2024
1 parent cc3b5fe commit 569ef3e
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 58 deletions.
8 changes: 0 additions & 8 deletions docs/man/nng_ctx_get.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ int nng_ctx_get_ms(nng_ctx ctx, const char *opt, nng_duration *durp);
int nng_ctx_get_size(nng_ctx ctx, const char *opt, size_t *zp);
int nng_ctx_get_string(nng_ctx ctx, const char *opt, char **strp);
int nng_ctx_get_uint64(nng_ctx ctx, const char *opt, uint64_t *u64p);
----
Expand Down Expand Up @@ -70,12 +68,6 @@ the special value ((`NNG_DURATION_DEFAULT`)) means a context-specific default.)
This function is used to retrieve a size into the pointer _zp_,
typically for buffer sizes, message maximum sizes, and similar options.

`nng_ctx_get_string()`::
This function is used to retrieve a string into _strp_.
This string is created from the source using xref:nng_strdup.3.adoc[`nng_strdup()`]
and consequently must be freed by the caller using
xref:nng_strfree.3.adoc[`nng_strfree()`] when it is no longer needed.

`nng_ctx_get_uint64()`::
This function is used to retrieve a 64-bit unsigned value into the value
referenced by _u64p_.
Expand Down
2 changes: 0 additions & 2 deletions docs/man/nng_ctx_set.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ int nng_ctx_set_ms(nng_ctx ctx, const char *opt, nng_duration dur);
int nng_ctx_set_size(nng_ctx ctx, const char *opt, size_t z);
int nng_ctx_set_string(nng_ctx ctx, const char *opt, const char *str);
int nng_ctx_set_uint64(nng_ctx ctx, const char *opt, uint64_t u64);
----

Expand Down
8 changes: 0 additions & 8 deletions docs/man/nng_socket_get.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ int nng_socket_get_size(nng_socket s, const char *opt, size_t *zp);
int nng_socket_get_uint64(nng_socket s, const char *opt, uint64_t *u64p);
int nng_socket_get_string(nng_socket s, const char *opt, char **strp);
int nng_socket_get_ms(nng_socket s, const char *opt, nng_duration *durp);
int nng_socket_get_addr(nng_socket s, const char *opt, nng_sockaddr *addrp);
Expand Down Expand Up @@ -71,12 +69,6 @@ the special value ((`NNG_DURATION_DEFAULT`)) means a context-specific default.)
This function is used to retrieve a size into the pointer _zp_,
typically for buffer sizes, message maximum sizes, and similar options.

`nng_socket_get_string()`::
This function is used to retrieve a string into _strp_.
This string is created from the source using xref:nng_strdup.3.adoc[`nng_strdup()`]
and consequently must be freed by the caller using
xref:nng_strfree.3.adoc[`nng_strfree()`] when it is no longer needed.

`nng_socket_get_uint64()`::
This function is used to retrieve a 64-bit unsigned value into the value
referenced by _u64p_.
Expand Down
9 changes: 0 additions & 9 deletions docs/man/nng_socket_set.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ int nng_socket_set_ms(nng_socket s, const char *opt, nng_duration dur);
int nng_socket_set_size(nng_socket s, const char *opt, size_t z);
int nng_socket_set_string(nng_socket s, const char *opt, const char *str);
int nng_socket_set_uint64(nng_socket s, const char *opt, uint64_t u64);
----

Expand Down Expand Up @@ -64,13 +62,6 @@ The duration _dur_ is an integer number of milliseconds.
This function is used to configure a size, _z_, typically for buffer sizes,
message maximum sizes, and similar options.

`nng_socket_set_string()`::
This function is used to pass configure a string, _str_.
Strings passed this way must be legal UTF-8 or ASCII strings, terminated
with a `NUL` (`\0`) byte.
(Other constraints may apply as well, see the documentation for each option
for details.)

`nng_socket_set_uint64()`::
This function is used to configure a 64-bit unsigned value, _u64_.
This is typically used for options related to identifiers, network numbers,
Expand Down
4 changes: 4 additions & 0 deletions docs/ref/migrate/nng1.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ should be sufficient in most cases.
The following functions served no useful purpose (after other changes described in this document),
and are thus removed:

- `nng_ctx_get_string`
- `nng_ctx_set_string`
- `nng_socket_get_ptr`
- `nng_socket_set_ptr`
- `nng_socket_get_string`
- `nng_socket_set_string`
- `nng_ctx_get_ptr` (not documented)
- `nng_ctx_set_ptr` (not documented)

Expand Down
5 changes: 0 additions & 5 deletions include/nng/nng.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,12 @@ NNG_DECL int nng_socket_set_bool(nng_socket, const char *, bool);
NNG_DECL int nng_socket_set_int(nng_socket, const char *, int);
NNG_DECL int nng_socket_set_size(nng_socket, const char *, size_t);
NNG_DECL int nng_socket_set_uint64(nng_socket, const char *, uint64_t);
NNG_DECL int nng_socket_set_string(nng_socket, const char *, const char *);
NNG_DECL int nng_socket_set_ms(nng_socket, const char *, nng_duration);

NNG_DECL int nng_socket_get_bool(nng_socket, const char *, bool *);
NNG_DECL int nng_socket_get_int(nng_socket, const char *, int *);
NNG_DECL int nng_socket_get_size(nng_socket, const char *, size_t *);
NNG_DECL int nng_socket_get_uint64(nng_socket, const char *, uint64_t *);
NNG_DECL int nng_socket_get_string(nng_socket, const char *, char **);
NNG_DECL int nng_socket_get_ms(nng_socket, const char *, nng_duration *);

// These functions are used to obtain a file descriptor that will poll
Expand Down Expand Up @@ -485,16 +483,13 @@ NNG_DECL int nng_ctx_get_bool(nng_ctx, const char *, bool *);
NNG_DECL int nng_ctx_get_int(nng_ctx, const char *, int *);
NNG_DECL int nng_ctx_get_size(nng_ctx, const char *, size_t *);
NNG_DECL int nng_ctx_get_uint64(nng_ctx, const char *, uint64_t *);
NNG_DECL int nng_ctx_get_string(nng_ctx, const char *, char **);
NNG_DECL int nng_ctx_get_ms(nng_ctx, const char *, nng_duration *);

NNG_DECL int nng_ctx_set(nng_ctx, const char *, const void *, size_t);
NNG_DECL int nng_ctx_set_bool(nng_ctx, const char *, bool);
NNG_DECL int nng_ctx_set_int(nng_ctx, const char *, int);
NNG_DECL int nng_ctx_set_size(nng_ctx, const char *, size_t);
NNG_DECL int nng_ctx_set_uint64(nng_ctx, const char *, uint64_t);
NNG_DECL int nng_ctx_set_string(nng_ctx, const char *, const char *);
NNG_DECL int nng_ctx_set_ptr(nng_ctx, const char *, void *);
NNG_DECL int nng_ctx_set_ms(nng_ctx, const char *, nng_duration);

// nng_alloc is used to allocate memory. It's intended purpose is for
Expand Down
26 changes: 0 additions & 26 deletions src/nng.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,6 @@ nng_ctx_get_uint64(nng_ctx id, const char *n, uint64_t *v)
return (ctx_get(id, n, v, NULL, NNI_TYPE_UINT64));
}

int
nng_ctx_get_string(nng_ctx id, const char *n, char **v)
{
return (ctx_get(id, n, v, NULL, NNI_TYPE_STRING));
}

int
nng_ctx_get_ms(nng_ctx id, const char *n, nng_duration *v)
{
Expand Down Expand Up @@ -491,13 +485,6 @@ nng_ctx_set_ms(nng_ctx id, const char *n, nng_duration v)
return (ctx_set(id, n, &v, sizeof(v), NNI_TYPE_DURATION));
}

int
nng_ctx_set_string(nng_ctx id, const char *n, const char *v)
{
return (
ctx_set(id, n, v, v == NULL ? 0 : strlen(v) + 1, NNI_TYPE_STRING));
}

int
nng_dial(nng_socket sid, const char *addr, nng_dialer *dp, int flags)
{
Expand Down Expand Up @@ -1133,13 +1120,6 @@ nng_socket_set_ms(nng_socket id, const char *n, nng_duration v)
return (socket_set(id, n, &v, sizeof(v), NNI_TYPE_DURATION));
}

int
nng_socket_set_string(nng_socket id, const char *n, const char *v)
{
return (socket_set(
id, n, v, v == NULL ? 0 : strlen(v) + 1, NNI_TYPE_STRING));
}

static int
socket_get(nng_socket s, const char *name, void *val, size_t *szp, nni_type t)
{
Expand Down Expand Up @@ -1178,12 +1158,6 @@ nng_socket_get_uint64(nng_socket id, const char *n, uint64_t *v)
return (socket_get(id, n, v, NULL, NNI_TYPE_UINT64));
}

int
nng_socket_get_string(nng_socket id, const char *n, char **v)
{
return (socket_get(id, n, v, NULL, NNI_TYPE_STRING));
}

int
nng_socket_get_ms(nng_socket id, const char *n, nng_duration *v)
{
Expand Down

0 comments on commit 569ef3e

Please sign in to comment.