Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gdamore/no untyped pipe get #1910

Merged
merged 2 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions docs/man/nng_stream_dialer_get.3str.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ nng_stream_dialer_get - get option from byte stream dialer
----
#include <nng/nng.h>

int nng_stream_dialer_get(nng_stream_dialer *d, const char *opt, void *val, size_t *sizep);

int nng_stream_dialer_get_bool(nng_stream_dialer *d, const char *opt, bool *valp);

int nng_stream_dialer_get_int(nng_stream_dialer *d, const char *opt, int *valp);
Expand All @@ -42,7 +40,7 @@ int nng_stream_dialer_get_uint64(nng_stream_dialer *d, const char *opt, uint64_t
== DESCRIPTION


The `nng_stream_dialer_get()` functions are used to retrieve option values for the
The `nng_stream_dialer_get()` functions are used to retrieve option values for the
xref:nng_stream_dialer.5.adoc[byte stream dialer] _d_.

The actual options that may be retrieved in this way vary.
Expand All @@ -58,26 +56,6 @@ The forms vary based on the type of the option they take.
The details of the type, size, and semantics of the option will depend
on the actual option, and will be documented with the option itself.

`nng_stream_dialer_get()`::
This function is untyped and can be used to retrieve the value of any option.
The caller must store a pointer to a buffer to receive the value in _val_,
and the size of the buffer shall be stored at the location referenced by
_sizep_.
+
When the function returns, the actual size of the data copied (or that
would have been copied if sufficient space were present) is stored at
the location referenced by _sizep_.
If the caller's buffer is not large enough to hold the entire object,
then the copy is truncated.
Therefore the caller should check for truncation by verifying that the
returned size in _sizep_ does not exceed the original buffer size.
+
It is acceptable to pass `NULL` for _val_ if the value in _sizep_ is zero.
This can be used to determine the size of the buffer needed to receive
the object.
+
TIP: It may be easier to use one of the typed forms of this function.

`nng_stream_dialer_get_bool()`::
This function is for options which take a Boolean (`bool`).

Expand Down
15 changes: 3 additions & 12 deletions docs/man/nng_stream_dialer_set.3str.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= nng_stream_dialer_set(3str)
//
// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
Expand All @@ -20,8 +20,6 @@ nng_stream_dialer_set - set option on byte stream dialer
----
#include <nng/nng.h>

int nng_stream_dialer_set(nng_stream_dialer *d, const char *name, const void *data, size_t size);

int nng_stream_dialer_set_bool(nng_stream_dialer *d, const char *opt, bool val);

int nng_stream_dialer_set_int(nng_stream_dialer *d, const char *opt, int val);
Expand All @@ -42,7 +40,7 @@ int nng_stream_dialer_set_addr(nng_stream_dialer *d, const char *opt, const nng_

== DESCRIPTION

The `nng_stream_dialer_set()` functions are used to configure options for the
The `nng_stream_dialer_set` functions are used to configure options for the
xref:nng_stream.5.adoc[byte stream dialer] _d_.
The actual options that may be configured in this way vary, and are
specified by _opt_.
Expand All @@ -57,13 +55,6 @@ documented with the transports and protocols themselves.
The details of the type, size, and semantics of the option will depend
on the actual option, and will be documented with the option itself.

`nng_stream_dialer_set()`::
This function is untyped, and can be used to configure any arbitrary data.
The _val_ pointer addresses the data to copy, and _size_ is the
size of the objected located at _val_.
+
TIP: It may be easier to use one of the typed forms of this function.

`nng_stream_dialer_set_bool()`::
This function is for options which take a Boolean (`bool`).

Expand Down Expand Up @@ -130,4 +121,4 @@ xref:nng_options.5.adoc[nng_options(5)],
xref:nng_ipc_options.5.adoc[nng_ipc_options(5)],
xref:nng_tcp_options.5.adoc[nng_tcp_options(5)],
xref:nng_tls_options.5.adoc[nng_tls_options(5)],
xref:nng_stream_dialer.5.adoc[nng_stream_dialer(5)]
xref:nng_stream_dialer.5.adoc[nng_stream_dialer(5)]
27 changes: 2 additions & 25 deletions docs/man/nng_stream_get.3str.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= nng_stream_get(3str)
//
// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
Expand All @@ -20,8 +20,6 @@ nng_stream_get - get option from byte stream
----
#include <nng/nng.h>

int nng_stream_get(nng_stream *s, const char *opt, void *val, size_t *sizep);

int nng_stream_get_bool(nng_stream *s, const char *opt, bool *valp);

int nng_stream_get_int(nng_stream *s, const char *opt, int *valp);
Expand All @@ -37,12 +35,11 @@ int nng_stream_get_addr(nng_stream *s, const char *opt, nng_sockaddr *valp);
int nng_stream_get_string(nng_stream *s, const char *opt, char **valp);

int nng_stream_get_uint64(nng_stream *s, const char *opt, uint64_t *valp);

----

== DESCRIPTION

The `nng_stream_get()` functions are used to retrieve option values for the
The `nng_stream_get` functions are used to retrieve option values for the
xref:nng_stream.5.adoc[byte stream] _conn_.

The actual options that may be retrieved in this way vary.
Expand All @@ -58,26 +55,6 @@ The forms vary based on the type of the option they take.
The details of the type, size, and semantics of the option will depend
on the actual option, and will be documented with the option itself.

`nng_stream_get()`::
This function is untyped and can be used to retrieve the value of any option.
The caller must store a pointer to a buffer to receive the value in _val_,
and the size of the buffer shall be stored at the location referenced by
_sizep_.
+
When the function returns, the actual size of the data copied (or that
would have been copied if sufficient space were present) is stored at
the location referenced by _sizep_.
If the caller's buffer is not large enough to hold the entire object,
then the copy is truncated.
Therefore the caller should check for truncation by verifying that the
returned size in _sizep_ does not exceed the original buffer size.
+
It is acceptable to pass `NULL` for _val_ if the value in _sizep_ is zero.
This can be used to determine the size of the buffer needed to receive
the object.
+
TIP: It may be easier to use one of the typed forms of this function.

`nng_stream_get_bool()`::
This function is for options which take a Boolean (`bool`).

Expand Down
28 changes: 3 additions & 25 deletions docs/man/nng_stream_listener_get.3str.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= nng_stream_listener_get(3str)
//
// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
Expand All @@ -20,8 +20,6 @@ nng_stream_listener_get - get option from byte stream listener
----
#include <nng/nng.h>

int nng_stream_listener_get(nng_stream_listener *l, const char *opt, void *val, size_t *sizep);

int nng_stream_listener_get_bool(nng_stream_listener *l, const char *opt, bool *valp);

int nng_stream_listener_get_int(nng_stream_listener *l, const char *opt, int *valp);
Expand All @@ -42,8 +40,8 @@ int nng_stream_listener_get_uint64(nng_stream_listener *l, const char *opt, uint
== DESCRIPTION


The `nng_stream_listener_get()` functions are used to retrieve option values
for the
The `nng_stream_listener_get` functions are used to retrieve option values
for the
xref:nng_stream_listener.5.adoc[byte stream listener] _l_.

The actual options that may be retrieved in this way vary.
Expand All @@ -59,26 +57,6 @@ The forms vary based on the type of the option they take.
The details of the type, size, and semantics of the option will depend
on the actual option, and will be documented with the option itself.

`nng_stream_listener_get()`::
This function is untyped and can be used to retrieve the value of any option.
The caller must store a pointer to a buffer to receive the value in _val_,
and the size of the buffer shall be stored at the location referenced by
_sizep_.
+
When the function returns, the actual size of the data copied (or that
would have been copied if sufficient space were present) is stored at
the location referenced by _sizep_.
If the caller's buffer is not large enough to hold the entire object,
then the copy is truncated.
Therefore the caller should check for truncation by verifying that the
returned size in _sizep_ does not exceed the original buffer size.
+
It is acceptable to pass `NULL` for _val_ if the value in _sizep_ is zero.
This can be used to determine the size of the buffer needed to receive
the object.
+
TIP: It may be easier to use one of the typed forms of this function.

`nng_stream_listener_get_bool()`::
This function is for options which take a Boolean (`bool`).

Expand Down
15 changes: 3 additions & 12 deletions docs/man/nng_stream_listener_set.3str.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= nng_stream_listener_set(3str)
//
// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
Expand All @@ -20,8 +20,6 @@ nng_stream_listener_set - set option on byte stream listener
----
#include <nng/nng.h>

int nng_stream_listener_set(nng_stream_listener *l, const char *name, const void *data, size_t size);

int nng_stream_listener_set_bool(nng_stream_listener *l, const char *opt, bool val);

int nng_stream_listener_set_int(nng_stream_listener *l, const char *opt, int val);
Expand All @@ -42,7 +40,7 @@ int nng_stream_listener_set_addr(nng_stream_listener *l, const char *opt, const

== DESCRIPTION

The `nng_stream_listener_set()` functions are used to configure options for the
The `nng_stream_listener_set` functions are used to configure options for the
xref:nng_stream.5.adoc[byte stream listener] _l_.
The actual options that may be configured in this way vary, and are
specified by _opt_.
Expand All @@ -57,13 +55,6 @@ documented with the transports and protocols themselves.
The details of the type, size, and semantics of the option will depend
on the actual option, and will be documented with the option itself.

`nng_stream_listener_set()`::
This function is untyped, and can be used to configure any arbitrary data.
The _val_ pointer addresses the data to copy, and _size_ is the
size of the objected located at _val_.
+
TIP: It may be easier to use one of the typed forms of this function.

`nng_stream_listener_set_bool()`::
This function is for options which take a Boolean (`bool`).

Expand Down Expand Up @@ -130,4 +121,4 @@ xref:nng_options.5.adoc[nng_options(5)],
xref:nng_ipc_options.5.adoc[nng_ipc_options(5)],
xref:nng_tcp_options.5.adoc[nng_tcp_options(5)],
xref:nng_tls_options.5.adoc[nng_tls_options(5)],
xref:nng_stream_listener.5.adoc[nng_stream_listener(5)]
xref:nng_stream_listener.5.adoc[nng_stream_listener(5)]
13 changes: 13 additions & 0 deletions docs/ref/migrate/nng1.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ The `_getopt` and `_setopt` functions for contexts, listeners, and dialers are n
present. Simply changing `_getopt` to `_get` or `_setopt` to `_set` in the function name
should be sufficient in most cases.

## Untyped Option Functions Removed

The following functions are removed. To access options, use a proper typed access function,
such as one ending in a suffix like `_bool` (to access a `bool` typed option).

- `nng_pipe_get`
- `nng_stream_get`
- `nng_stream_set`
- `nng_stream_dialer_get`
- `nng_stream_dialer_set`
- `nng_stream_listener_get`
- `nng_stream_listener_set`

## Stream Options

The ability to set options on streams after they have been created is no longer present.
Expand Down
17 changes: 4 additions & 13 deletions include/nng/nng.h
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,6 @@ NNG_DECL nng_pipe nng_msg_get_pipe(const nng_msg *);
// we do permit an application to close a pipe. This can be useful, for
// example during a connection notification, to disconnect a pipe that
// is associated with an invalid or untrusted remote peer.
NNG_DECL int nng_pipe_get(nng_pipe, const char *, void *, size_t *);
NNG_DECL int nng_pipe_get_bool(nng_pipe, const char *, bool *);
NNG_DECL int nng_pipe_get_int(nng_pipe, const char *, int *);
NNG_DECL int nng_pipe_get_ms(nng_pipe, const char *, nng_duration *);
Expand Down Expand Up @@ -1166,12 +1165,8 @@ NNG_DECL int nng_stream_dialer_alloc_url(
NNG_DECL void nng_stream_dialer_free(nng_stream_dialer *);
NNG_DECL void nng_stream_dialer_close(nng_stream_dialer *);
NNG_DECL void nng_stream_dialer_dial(nng_stream_dialer *, nng_aio *);
NNG_DECL int nng_stream_dialer_set(
nng_stream_dialer *, const char *, const void *, size_t);
NNG_DECL int nng_stream_dialer_get(
nng_stream_dialer *, const char *, void *, size_t *);
NNG_DECL int nng_stream_dialer_get_bool(
nng_stream_dialer *, const char *, bool *);
NNG_DECL int nng_stream_dialer_get_bool(
nng_stream_dialer *, const char *, bool *);
NNG_DECL int nng_stream_dialer_get_int(
nng_stream_dialer *, const char *, int *);
NNG_DECL int nng_stream_dialer_get_ms(
Expand Down Expand Up @@ -1209,12 +1204,8 @@ NNG_DECL void nng_stream_listener_free(nng_stream_listener *);
NNG_DECL void nng_stream_listener_close(nng_stream_listener *);
NNG_DECL int nng_stream_listener_listen(nng_stream_listener *);
NNG_DECL void nng_stream_listener_accept(nng_stream_listener *, nng_aio *);
NNG_DECL int nng_stream_listener_set(
nng_stream_listener *, const char *, const void *, size_t);
NNG_DECL int nng_stream_listener_get(
nng_stream_listener *, const char *, void *, size_t *);
NNG_DECL int nng_stream_listener_get_bool(
nng_stream_listener *, const char *, bool *);
NNG_DECL int nng_stream_listener_get_bool(
nng_stream_listener *, const char *, bool *);
NNG_DECL int nng_stream_listener_get_int(
nng_stream_listener *, const char *, int *);
NNG_DECL int nng_stream_listener_get_ms(
Expand Down
20 changes: 3 additions & 17 deletions src/core/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,26 +204,12 @@ nni_copyin_u64(uint64_t *up, const void *v, size_t sz, nni_type t)
}

int
nni_copyin_sockaddr(nng_sockaddr *ap, const void *v, size_t sz, nni_type t)
nni_copyin_sockaddr(nng_sockaddr *ap, const void *v, nni_type t)
{
nng_sockaddr a;

switch (t) {
case NNI_TYPE_SOCKADDR:
a = *(nng_sockaddr *) v;
break;
case NNI_TYPE_OPAQUE:
if (sz != sizeof(nng_sockaddr)) {
return (NNG_EINVAL);
}
memcpy(&a, v, sz);
break;
default:
if (t != NNI_TYPE_SOCKADDR) {
return (NNG_EBADTYPE);
}
if (ap != NULL) {
*ap = a;
}
*ap = *(nng_sockaddr *) v;
return (0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern int nni_copyin_size(
extern int nni_copyin_str(char *, const void *, size_t, size_t, nni_type);
extern int nni_copyin_ptr(void **, const void *, size_t, nni_type);
extern int nni_copyin_u64(uint64_t *, const void *, size_t, nni_type);
extern int nni_copyin_sockaddr(nng_sockaddr *, const void *, size_t, nni_type);
extern int nni_copyin_sockaddr(nng_sockaddr *, const void *, nni_type);

// nni_copyout_xxx copies out a type of the named value. It assumes that
// the type is aligned and the size correct, unless NNI_TYPE_OPAQUE is passed.
Expand Down
Loading
Loading