Skip to content

Commit

Permalink
api: pipes should use nng_err
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Jan 14, 2025
1 parent 6dc7573 commit 7dce06b
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 42 deletions.
16 changes: 8 additions & 8 deletions include/nng/nng.h
Original file line number Diff line number Diff line change
Expand Up @@ -740,14 +740,14 @@ 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_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 *);
NNG_DECL int nng_pipe_get_size(nng_pipe, const char *, size_t *);
NNG_DECL int nng_pipe_get_string(nng_pipe, const char *, char **);
NNG_DECL int nng_pipe_get_addr(nng_pipe, const char *, nng_sockaddr *);

NNG_DECL int nng_pipe_close(nng_pipe);
NNG_DECL nng_err nng_pipe_get_bool(nng_pipe, const char *, bool *);
NNG_DECL nng_err nng_pipe_get_int(nng_pipe, const char *, int *);
NNG_DECL nng_err nng_pipe_get_ms(nng_pipe, const char *, nng_duration *);
NNG_DECL nng_err nng_pipe_get_size(nng_pipe, const char *, size_t *);
NNG_DECL nng_err nng_pipe_get_string(nng_pipe, const char *, char **);
NNG_DECL nng_err nng_pipe_get_addr(nng_pipe, const char *, nng_sockaddr *);

NNG_DECL nng_err nng_pipe_close(nng_pipe);
NNG_DECL int nng_pipe_id(nng_pipe);
NNG_DECL nng_socket nng_pipe_socket(nng_pipe);
NNG_DECL nng_dialer nng_pipe_dialer(nng_pipe);
Expand Down
10 changes: 5 additions & 5 deletions src/core/pipe.c
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]>
// Copyright 2018 Devolutions <[email protected]>
//
Expand Down Expand Up @@ -75,7 +75,7 @@ pipe_reap(void *arg)
nni_pipe_rele(p);
}

int
nng_err
nni_pipe_find(nni_pipe **pp, uint32_t id)
{
nni_pipe *p;
Expand All @@ -90,7 +90,7 @@ nni_pipe_find(nni_pipe **pp, uint32_t id)
*pp = p;
}
nni_mtx_unlock(&pipes_lk);
return (p == NULL ? NNG_ENOENT : 0);
return (p == NULL ? NNG_ENOENT : NNG_OK);
}

void
Expand Down Expand Up @@ -330,11 +330,11 @@ nni_pipe_alloc_listener(void **datap, nni_listener *l)
return (0);
}

int
nng_err
nni_pipe_getopt(
nni_pipe *p, const char *name, void *val, size_t *szp, nni_opt_type t)
{
int rv;
nng_err rv;

rv = p->p_tran_ops.p_getopt(p->p_tran_data, name, val, szp, t);
if (rv != NNG_ENOTSUP) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ extern void nni_pipe_close(nni_pipe *);
extern uint16_t nni_pipe_peer(nni_pipe *);

// nni_pipe_getopt looks up the option.
extern int nni_pipe_getopt(
extern nng_err nni_pipe_getopt(
nni_pipe *, const char *, void *, size_t *, nni_opt_type);

// nni_pipe_find finds a pipe given its ID. It places a hold on the
// pipe, which must be released by the caller when it is done.
extern int nni_pipe_find(nni_pipe **, uint32_t);
extern nng_err nni_pipe_find(nni_pipe **, uint32_t);

// nni_pipe_sock_id returns the socket id for the pipe (used by public API).
extern uint32_t nni_pipe_sock_id(nni_pipe *);
Expand Down
26 changes: 13 additions & 13 deletions src/nng.c
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 @@ -1301,51 +1301,51 @@ nng_strerror(nng_err num)
return (unknownerrbuf);
}

static int
static nng_err
pipe_get(nng_pipe p, const char *name, void *val, size_t *szp, nni_type t)
{
int rv;
nng_err rv;
nni_pipe *pipe;

if ((rv = nni_pipe_find(&pipe, p.id)) != 0) {
return (rv);
}
rv = nni_pipe_getopt(pipe, name, val, szp, t);
nni_pipe_rele(pipe);
return (rv);
return (NNG_OK);
}

int
nng_err
nng_pipe_get_int(nng_pipe id, const char *n, int *v)
{
return (pipe_get(id, n, v, NULL, NNI_TYPE_INT32));
}

int
nng_err
nng_pipe_get_bool(nng_pipe id, const char *n, bool *v)
{
return (pipe_get(id, n, v, NULL, NNI_TYPE_BOOL));
}

int
nng_err
nng_pipe_get_size(nng_pipe id, const char *n, size_t *v)
{
return (pipe_get(id, n, v, NULL, NNI_TYPE_SIZE));
}

int
nng_err
nng_pipe_get_string(nng_pipe id, const char *n, char **v)
{
return (pipe_get(id, n, v, NULL, NNI_TYPE_STRING));
}

int
nng_err
nng_pipe_get_ms(nng_pipe id, const char *n, nng_duration *v)
{
return (pipe_get(id, n, v, NULL, NNI_TYPE_DURATION));
}

int
nng_err
nng_pipe_get_addr(nng_pipe id, const char *n, nng_sockaddr *v)
{
return (pipe_get(id, n, v, NULL, NNI_TYPE_SOCKADDR));
Expand Down Expand Up @@ -1388,18 +1388,18 @@ nng_pipe_listener(nng_pipe p)
return (l);
}

int
nng_err
nng_pipe_close(nng_pipe p)
{
int rv;
nng_err rv;
nni_pipe *pipe;

if ((rv = nni_pipe_find(&pipe, p.id)) != 0) {
return (rv);
}
nni_pipe_close(pipe);
nni_pipe_rele(pipe);
return (0);
return (NNG_OK);
}

int
Expand Down
2 changes: 1 addition & 1 deletion src/sp/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ struct nni_sp_pipe_ops {

// p_getopt is used to obtain an option. Pipes don't implement
// option setting.
int (*p_getopt)(void *, const char *, void *, size_t *, nni_type);
nng_err (*p_getopt)(void *, const char *, void *, size_t *, nni_type);
};

// Transport implementation details. Transports must implement the
Expand Down
4 changes: 2 additions & 2 deletions src/sp/transport/inproc/inproc.c
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]>
// Copyright 2018 Devolutions <[email protected]>
//
Expand Down Expand Up @@ -577,7 +577,7 @@ static const nni_option inproc_pipe_options[] = {
},
};

static int
static nng_err
inproc_pipe_getopt(
void *arg, const char *name, void *v, size_t *szp, nni_type t)
{
Expand Down
2 changes: 1 addition & 1 deletion src/sp/transport/ipc/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ ipc_ep_accept(void *arg, nni_aio *aio)
nni_mtx_unlock(&ep->mtx);
}

static int
static nng_err
ipc_pipe_get(void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
ipc_pipe *p = arg;
Expand Down
4 changes: 2 additions & 2 deletions src/sp/transport/socket/sockfd.c
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]>
// Copyright 2019 Devolutions <[email protected]>
//
Expand Down Expand Up @@ -546,7 +546,7 @@ sfd_tran_pipe_peer(void *arg)
return (p->peer);
}

static int
static nng_err
sfd_tran_pipe_getopt(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
Expand Down
2 changes: 1 addition & 1 deletion src/sp/transport/tcp/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ tcptran_pipe_peer(void *arg)
return (p->peer);
}

static int
static nng_err
tcptran_pipe_getopt(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
Expand Down
6 changes: 3 additions & 3 deletions src/sp/transport/tls/tls.c
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]>
// Copyright 2019 Devolutions <[email protected]>
//
Expand Down Expand Up @@ -938,12 +938,12 @@ static const nni_option tlstran_pipe_opts[] = {
},
};

static int
static nng_err
tlstran_pipe_getopt(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
tlstran_pipe *p = arg;
int rv;
nng_err rv;

if ((rv = nni_stream_get(p->tls, name, buf, szp, t)) == NNG_ENOTSUP) {
rv = nni_getopt(tlstran_pipe_opts, name, p, buf, szp, t);
Expand Down
4 changes: 2 additions & 2 deletions src/sp/transport/udp/udp.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
Expand Down Expand Up @@ -1082,7 +1082,7 @@ static nni_option udp_pipe_options[] = {
},
};

static int
static nng_err
udp_pipe_getopt(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
Expand Down
4 changes: 2 additions & 2 deletions src/sp/transport/ws/websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ static const nni_option ws_pipe_options[] = {
}
};

static int
static nng_err
wstran_pipe_getopt(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
ws_pipe *p = arg;
int rv;
nng_err rv;

if ((rv = nni_stream_get(p->ws, name, buf, szp, t)) == NNG_ENOTSUP) {
rv = nni_getopt(ws_pipe_options, name, p, buf, szp, t);
Expand Down

0 comments on commit 7dce06b

Please sign in to comment.