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

Stable ep url sock send recv #2070

Merged
merged 2 commits into from
Jan 5, 2025
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
5 changes: 5 additions & 0 deletions docs/man/nng_dialer_get.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ int nng_dialer_get_string(nng_dialer d, const char *opt, char **strp);

int nng_dialer_get_uint64(nng_dialer d, const char *opt, uint64_t *u64p);

int nng_dialer_get_url(nng_dialer d, const nng_url **url);

----

== DESCRIPTION
Expand Down Expand Up @@ -117,6 +119,9 @@ referenced by _u64p_.
This is typically used for options related to identifiers, network
numbers, and similar.

`nng_dialer_get_url()`::
This function is used to obtain the URL that dialer is configured for.

== RETURN VALUES

These functions returns 0 on success, and non-zero otherwise.
Expand Down
11 changes: 10 additions & 1 deletion docs/man/nng_listener_get.3.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= nng_listener_get(3)
//
// Copyright 2020 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
//
// This document is supplied under the terms of the MIT License, a
Expand Down Expand Up @@ -37,6 +37,8 @@ int nng_listener_get_string(nng_listener l, const char *opt, char **strp);

int nng_listener_get_uint64(nng_listener l, const char *opt, uint64_t *u64p);

int nng_listener_get_url(nng_listener l, const nng_url **url);

----

== DESCRIPTION
Expand Down Expand Up @@ -115,6 +117,13 @@ referenced by _u64p_.
This is typically used for options related to identifiers, network
numbers, and similar.

`nng_listener_get_url()`::
This function is used to obtain the URL that listener is configured for.
This is the actual URL, and may different that what was requested.
For example, when using TCP, if port 0 was requested, but then the listener
was started, a real port will have been chosen by the operating system.
This URL will reflect that final port, so it can be used for dialing.

== RETURN VALUES

These functions return 0 on success, and non-zero otherwise.
Expand Down
20 changes: 15 additions & 5 deletions include/nng/nng.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand Down Expand Up @@ -420,18 +420,24 @@ NNG_DECL int nng_sendmsg(nng_socket, nng_msg *, int);
// can be passed off directly to nng_sendmsg.
NNG_DECL int nng_recvmsg(nng_socket, nng_msg **, int);

// nng_send_aio sends data on the socket asynchronously. As with nng_send,
// nng_sock_send sends data on the socket asynchronously. As with nng_send,
// the completion may be executed before the data has actually been delivered,
// but only when it is accepted for delivery. The supplied AIO must have
// been initialized, and have an associated message. The message will be
// "owned" by the socket if the operation completes successfully. Otherwise,
// the caller is responsible for freeing it.
NNG_DECL void nng_sock_send(nng_socket, nng_aio *);

// Compatible alias for nng_sock_send.
NNG_DECL void nng_send_aio(nng_socket, nng_aio *);

// nng_recv_aio receives data on the socket asynchronously. On a successful
// nng_sock_recv receives data on the socket asynchronously. On a successful
// result, the AIO will have an associated message, that can be obtained
// with nng_aio_get_msg(). The caller takes ownership of the message at
// this point.
NNG_DECL void nng_sock_recv(nng_socket, nng_aio *);

// Compatible alias for nng_sock_recv.
NNG_DECL void nng_recv_aio(nng_socket, nng_aio *);

// Context support. User contexts are not supported by all protocols,
Expand All @@ -456,7 +462,7 @@ NNG_DECL int nng_ctx_close(nng_ctx);
// A valid context is not necessarily an *open* context.
NNG_DECL int nng_ctx_id(nng_ctx);

// nng_ctx_recv receives asynchronously. It works like nng_recv_aio, but
// nng_ctx_recv receives asynchronously. It works like nng_sock_recv, but
// uses a local context instead of the socket global context.
NNG_DECL void nng_ctx_recv(nng_ctx, nng_aio *);

Expand All @@ -465,7 +471,7 @@ NNG_DECL void nng_ctx_recv(nng_ctx, nng_aio *);
// on a context instead of a socket.
NNG_DECL int nng_ctx_recvmsg(nng_ctx, nng_msg **, int);

// nng_ctx_send sends asynchronously. It works like nng_send_aio, but
// nng_ctx_send sends asynchronously. It works like nng_sock_send, but
// uses a local context instead of the socket global context.
NNG_DECL void nng_ctx_send(nng_ctx, nng_aio *);

Expand Down Expand Up @@ -1700,6 +1706,10 @@ NNG_DECL void nng_cv_wake(nng_cv *);
// that no waiter starves forever.
NNG_DECL void nng_cv_wake1(nng_cv *);

// New URL accessors for endpoints - from NNG 2.0.
NNG_DECL int nng_dialer_get_url(nng_dialer, const nng_url **);
NNG_DECL int nng_listener_get_url(nng_listener, const nng_url **);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 6 additions & 0 deletions src/core/dialer.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,12 @@
return (nni_sock_getopt(d->d_sock, name, valp, szp, t));
}

const nng_url *
nni_dialer_url(nni_dialer *d)

Check warning on line 562 in src/core/dialer.c

View check run for this annotation

Codecov / codecov/patch

src/core/dialer.c#L562

Added line #L562 was not covered by tests
{
return (d->d_url);

Check warning on line 564 in src/core/dialer.c

View check run for this annotation

Codecov / codecov/patch

src/core/dialer.c#L564

Added line #L564 was not covered by tests
}

void
nni_dialer_add_stat(nni_dialer *d, nni_stat_item *item)
{
Expand Down
3 changes: 2 additions & 1 deletion src/core/dialer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
// Copyright 2018 Devolutions <[email protected]>
//
Expand All @@ -25,6 +25,7 @@ extern int nni_dialer_setopt(
nni_dialer *, const char *, const void *, size_t, nni_type);
extern int nni_dialer_getopt(
nni_dialer *, const char *, void *, size_t *, nni_type);
extern const nng_url *nni_dialer_url(nni_dialer *);
extern void nni_dialer_add_stat(nni_dialer *, nni_stat_item *);
extern void nni_dialer_bump_error(nni_dialer *, int);

Expand Down
6 changes: 6 additions & 0 deletions src/core/listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,12 @@
return (nni_sock_getopt(l->l_sock, name, val, szp, t));
}

const nng_url *
nni_listener_url(nni_listener *l)

Check warning on line 511 in src/core/listener.c

View check run for this annotation

Codecov / codecov/patch

src/core/listener.c#L511

Added line #L511 was not covered by tests
{
return (l->l_url);

Check warning on line 513 in src/core/listener.c

View check run for this annotation

Codecov / codecov/patch

src/core/listener.c#L513

Added line #L513 was not covered by tests
}

void
nni_listener_add_stat(nni_listener *l, nni_stat_item *item)
{
Expand Down
3 changes: 2 additions & 1 deletion src/core/listener.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
// Copyright 2018 Devolutions <[email protected]>
//
Expand All @@ -25,6 +25,7 @@ extern int nni_listener_setopt(
nni_listener *, const char *, const void *, size_t, nni_type);
extern int nni_listener_getopt(
nni_listener *, const char *, void *, size_t *, nni_type);
extern const nng_url *nni_listener_url(nni_listener *);
extern void nni_listener_add_stat(nni_listener *, nni_stat_item *);
extern void nni_listener_bump_error(nni_listener *, int);

Expand Down
43 changes: 41 additions & 2 deletions src/nng.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
}

void
nng_recv_aio(nng_socket s, nng_aio *aio)
nng_sock_recv(nng_socket s, nng_aio *aio)
{
nni_sock *sock;
int rv;
Expand All @@ -235,7 +235,13 @@
}

void
nng_send_aio(nng_socket s, nng_aio *aio)
nng_recv_aio(nng_socket s, nng_aio *aio)
{
nng_sock_recv(s, aio);
}

void
nng_sock_send(nng_socket s, nng_aio *aio)
{
nni_sock *sock;
int rv;
Expand All @@ -256,6 +262,12 @@
nni_sock_rele(sock);
}

void
nng_send_aio(nng_socket s, nng_aio *aio)
{
nng_sock_send(s, aio);
}

int
nng_ctx_open(nng_ctx *cp, nng_socket s)
{
Expand Down Expand Up @@ -2302,3 +2314,30 @@
return (
nni_plat_udp_multicast_membership((nni_plat_udp *) udp, sa, join));
}


int
nng_dialer_get_url(nng_dialer id, const nng_url **urlp)

Check warning on line 2320 in src/nng.c

View check run for this annotation

Codecov / codecov/patch

src/nng.c#L2320

Added line #L2320 was not covered by tests
{
int rv;
nni_dialer *d;
if ((rv = nni_dialer_find(&d, id.id)) != 0) {
return (rv);

Check warning on line 2325 in src/nng.c

View check run for this annotation

Codecov / codecov/patch

src/nng.c#L2324-L2325

Added lines #L2324 - L2325 were not covered by tests
}
*urlp = nni_dialer_url(d);
nni_dialer_rele(d);
return (0);

Check warning on line 2329 in src/nng.c

View check run for this annotation

Codecov / codecov/patch

src/nng.c#L2327-L2329

Added lines #L2327 - L2329 were not covered by tests
}

int
nng_listener_get_url(nng_listener id, const nng_url **urlp)

Check warning on line 2333 in src/nng.c

View check run for this annotation

Codecov / codecov/patch

src/nng.c#L2333

Added line #L2333 was not covered by tests
{
int rv;
nni_listener *l;
if ((rv = nni_listener_find(&l, id.id)) != 0) {
return (rv);

Check warning on line 2338 in src/nng.c

View check run for this annotation

Codecov / codecov/patch

src/nng.c#L2337-L2338

Added lines #L2337 - L2338 were not covered by tests
}
*urlp = nni_listener_url(l);
nni_listener_rele(l);
return (0);

Check warning on line 2342 in src/nng.c

View check run for this annotation

Codecov / codecov/patch

src/nng.c#L2340-L2342

Added lines #L2340 - L2342 were not covered by tests
}
Loading