diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-02 12:08:44 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-02 12:08:44 -0800 |
| commit | 546c0d6ecc4267b9178f6eecb134e45c16b839cf (patch) | |
| tree | 230b95a73300b4df32d352f01d6e7841875f3c1b | |
| parent | 9eb080db1c450228169cc58f14d946211378fcf7 (diff) | |
| download | nng-546c0d6ecc4267b9178f6eecb134e45c16b839cf.tar.gz nng-546c0d6ecc4267b9178f6eecb134e45c16b839cf.tar.bz2 nng-546c0d6ecc4267b9178f6eecb134e45c16b839cf.zip | |
Rename nni_socket to nni_sock.
| -rw-r--r-- | src/core/defs.h | 7 | ||||
| -rw-r--r-- | src/core/endpt.c | 6 | ||||
| -rw-r--r-- | src/core/endpt.h | 4 | ||||
| -rw-r--r-- | src/core/pipe.c | 6 | ||||
| -rw-r--r-- | src/core/pipe.h | 2 | ||||
| -rw-r--r-- | src/core/protocol.h | 25 | ||||
| -rw-r--r-- | src/core/socket.c | 38 | ||||
| -rw-r--r-- | src/core/socket.h | 34 | ||||
| -rw-r--r-- | src/nng.c | 20 | ||||
| -rw-r--r-- | src/protocol/pair/pair.c | 8 | ||||
| -rw-r--r-- | src/protocol/reqrep/rep.c | 14 | ||||
| -rw-r--r-- | src/protocol/reqrep/req.c | 14 |
12 files changed, 85 insertions, 93 deletions
diff --git a/src/core/defs.h b/src/core/defs.h index 0fe894b1..7c9090d0 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -18,11 +18,14 @@ #define NNI_ARG_UNUSED(x) ((void) x); // These types are common but have names shared with user space. -typedef struct nng_socket nni_socket; -typedef struct nng_endpt nni_endpt; +typedef struct nng_socket nni_sock; +typedef struct nng_endpt nni_ep; typedef struct nng_pipe nni_pipe; typedef struct nng_msg nni_msg; +// REMOVE THESE +typedef struct nng_endpt nni_endpt; + // These are our own names. typedef struct nni_transport nni_transport; typedef struct nni_endpt_ops nni_endpt_ops; diff --git a/src/core/endpt.c b/src/core/endpt.c index 034e1a3d..0ff31380 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -16,7 +16,7 @@ // Functionality realited to end points. int -nni_endpt_create(nni_endpt **epp, nni_socket *sock, const char *addr) +nni_endpt_create(nni_endpt **epp, nni_sock *sock, const char *addr) { nni_transport *tran; nni_endpt *ep; @@ -47,7 +47,7 @@ nni_endpt_create(nni_endpt **epp, nni_socket *sock, const char *addr) (void) snprintf(ep->ep_addr, sizeof (ep->ep_addr), "%s", addr); ep->ep_ops = *tran->tran_ep_ops; - rv = ep->ep_ops.ep_create(&ep->ep_data, addr, nni_socket_proto(sock)); + rv = ep->ep_ops.ep_create(&ep->ep_data, addr, nni_sock_proto(sock)); if (rv != 0) { nni_cv_fini(&ep->ep_cv); NNI_FREE_STRUCT(ep); @@ -133,7 +133,7 @@ nni_dial_once(nni_endpt *ep) } -// nni_socket_dialer is the thread worker that dials in the background. +// nni_dialer is the thread worker that dials in the background. static void nni_dialer(void *arg) { diff --git a/src/core/endpt.h b/src/core/endpt.h index 28a52e81..695ef79a 100644 --- a/src/core/endpt.h +++ b/src/core/endpt.h @@ -19,7 +19,7 @@ struct nng_endpt { nni_endpt_ops ep_ops; void * ep_data; // Transport private nni_list_node ep_node; // Per socket list - nni_socket * ep_sock; + nni_sock * ep_sock; char ep_addr[NNG_MAXADDRLEN]; nni_thr ep_thr; int ep_mode; @@ -33,7 +33,7 @@ struct nng_endpt { #define NNI_EP_MODE_DIAL 1 #define NNI_EP_MODE_LISTEN 2 -extern int nni_endpt_create(nni_endpt **, nni_socket *, const char *); +extern int nni_endpt_create(nni_endpt **, nni_sock *, const char *); extern int nni_endpt_accept(nni_endpt *, nni_pipe **); extern void nni_endpt_close(nni_endpt *); extern int nni_endpt_dial(nni_endpt *, int); diff --git a/src/core/pipe.c b/src/core/pipe.c index 177216bd..8cf83179 100644 --- a/src/core/pipe.c +++ b/src/core/pipe.c @@ -42,7 +42,7 @@ nni_pipe_recv(nni_pipe *p, nng_msg **msgp) void nni_pipe_close(nni_pipe *p) { - nni_socket *sock = p->p_sock; + nni_sock *sock = p->p_sock; if (p->p_trandata != NULL) { p->p_ops.p_close(p->p_trandata); @@ -87,7 +87,7 @@ int nni_pipe_create(nni_pipe **pp, nni_endpt *ep) { nni_pipe *p; - nni_socket *sock = ep->ep_sock; + nni_sock *sock = ep->ep_sock; nni_protocol *proto = &sock->s_ops; int rv; @@ -144,7 +144,7 @@ nni_pipe_start(nni_pipe *pipe) { int rv; int collide; - nni_socket *sock = pipe->p_sock; + nni_sock *sock = pipe->p_sock; nni_mtx_lock(&sock->s_mx); if (sock->s_closing) { diff --git a/src/core/pipe.h b/src/core/pipe.h index 3c2c1166..193fd6c2 100644 --- a/src/core/pipe.h +++ b/src/core/pipe.h @@ -23,7 +23,7 @@ struct nng_pipe { void * p_pdata; // protocol specific data size_t p_psize; // size of protocol data nni_list_node p_node; - nni_socket * p_sock; + nni_sock * p_sock; nni_endpt * p_ep; int p_reap; int p_active; diff --git a/src/core/protocol.h b/src/core/protocol.h index 6fd48b40..301782b4 100644 --- a/src/core/protocol.h +++ b/src/core/protocol.h @@ -26,7 +26,7 @@ struct nni_protocol { size_t proto_pipe_size; // pipe private data size //Create protocol instance, which will be stored on the socket. - int (*proto_create)(void **, nni_socket *); + int (*proto_create)(void **, nni_sock *); // Destroy the protocol instance. void (*proto_destroy)(void *); @@ -57,29 +57,6 @@ struct nni_protocol { nni_msg * (*proto_send_filter)(void *, nni_msg *); }; -// These are socket methods that protocol operations can expect to call. -// Note that each of these should be called without any locks held, since -// the socket can reenter the protocol. - -// nni_socket_sendq obtains the upper writeq. The protocol should -// recieve messages from this, and place them on the appropriate pipe. -extern nni_msgq *nni_socket_sendq(nni_socket *); - -// nni_socket_recvq obtains the upper readq. The protocol should -// inject incoming messages from pipes to it. -extern nni_msgq *nni_socket_recvq(nni_socket *); - -// nni_socket_recv_err sets an error code to be returned to clients -// rather than waiting for a message. Set it to 0 to resume normal -// receive operation. -extern void nni_socket_recv_err(nni_socket *, int); - -// nni_socket_send_err sets an error code to be returned to clients -// when they try to send, so that they don't have to timeout waiting -// for their message to be accepted for send. Set it to 0 to resume -// normal send operations. -extern void nni_socket_send_err(nni_socket *, int); - // These functions are not used by protocols, but rather by the socket // core implementation. The lookups can be used by transports as well. extern nni_protocol *nni_protocol_find(uint16_t); diff --git a/src/core/socket.c b/src/core/socket.c index c64ba5ef..77e68733 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -13,17 +13,17 @@ // Socket implementation. -// nni_socket_sendq and nni_socket_recvq are called by the protocol to obtain +// nni_sock_sendq and nni_sock_recvq are called by the protocol to obtain // the upper read and write queues. nni_msgq * -nni_socket_sendq(nni_socket *s) +nni_sock_sendq(nni_sock *s) { return (s->s_uwq); } nni_msgq * -nni_socket_recvq(nni_socket *s) +nni_sock_recvq(nni_sock *s) { return (s->s_urq); } @@ -35,7 +35,7 @@ nni_socket_recvq(nni_socket *s) static void nni_reaper(void *arg) { - nni_socket *sock = arg; + nni_sock *sock = arg; for (;;) { nni_pipe *pipe; @@ -84,11 +84,11 @@ nni_reaper(void *arg) } -// nn_socket_create creates the underlying socket. +// nn_sock_open creates the underlying socket. int -nni_socket_create(nni_socket **sockp, uint16_t proto) +nni_sock_open(nni_sock **sockp, uint16_t proto) { - nni_socket *sock; + nni_sock *sock; nni_protocol *ops; int rv; @@ -157,9 +157,9 @@ nni_socket_create(nni_socket **sockp, uint16_t proto) } -// nni_socket_close closes the underlying socket. +// nni_sock_close closes the underlying socket. int -nni_socket_close(nni_socket *sock) +nni_sock_close(nni_sock *sock) { nni_pipe *pipe; nni_endpt *ep; @@ -241,7 +241,7 @@ nni_socket_close(nni_socket *sock) int -nni_socket_sendmsg(nni_socket *sock, nni_msg *msg, nni_time expire) +nni_sock_sendmsg(nni_sock *sock, nni_msg *msg, nni_time expire) { int rv; int besteffort; @@ -284,7 +284,7 @@ nni_socket_sendmsg(nni_socket *sock, nni_msg *msg, nni_time expire) int -nni_socket_recvmsg(nni_socket *sock, nni_msg **msgp, nni_time expire) +nni_sock_recvmsg(nni_sock *sock, nni_msg **msgp, nni_time expire) { int rv; nni_msg *msg; @@ -319,16 +319,16 @@ nni_socket_recvmsg(nni_socket *sock, nni_msg **msgp, nni_time expire) } -// nni_socket_protocol returns the socket's 16-bit protocol number. +// nni_sock_protocol returns the socket's 16-bit protocol number. uint16_t -nni_socket_proto(nni_socket *sock) +nni_sock_proto(nni_sock *sock) { return (sock->s_ops.proto_self); } int -nni_socket_dial(nni_socket *sock, const char *addr, nni_endpt **epp, int flags) +nni_sock_dial(nni_sock *sock, const char *addr, nni_endpt **epp, int flags) { nni_endpt *ep; int rv; @@ -349,7 +349,7 @@ nni_socket_dial(nni_socket *sock, const char *addr, nni_endpt **epp, int flags) int -nni_socket_listen(nni_socket *sock, const char *addr, nni_endpt **epp, +nni_sock_listen(nni_sock *sock, const char *addr, nni_endpt **epp, int flags) { nni_endpt *ep; @@ -371,21 +371,21 @@ nni_socket_listen(nni_socket *sock, const char *addr, nni_endpt **epp, void -nni_socket_recverr(nni_socket *sock, int err) +nni_sock_recverr(nni_sock *sock, int err) { sock->s_recverr = err; } void -nni_socket_senderr(nni_socket *sock, int err) +nni_sock_senderr(nni_sock *sock, int err) { sock->s_senderr = err; } int -nni_socket_setopt(nni_socket *sock, int opt, const void *val, size_t size) +nni_sock_setopt(nni_sock *sock, int opt, const void *val, size_t size) { size_t rsz; void *ptr; @@ -428,7 +428,7 @@ nni_socket_setopt(nni_socket *sock, int opt, const void *val, size_t size) int -nni_socket_getopt(nni_socket *sock, int opt, void *val, size_t *sizep) +nni_sock_getopt(nni_sock *sock, int opt, void *val, size_t *sizep) { size_t rsz; void *ptr; diff --git a/src/core/socket.h b/src/core/socket.h index bd0a5c8a..1808b09d 100644 --- a/src/core/socket.h +++ b/src/core/socket.h @@ -45,20 +45,32 @@ struct nng_socket { uint32_t s_nextid; // Next Pipe ID. }; -extern int nni_socket_create(nni_socket **, uint16_t); -extern int nni_socket_close(nni_socket *); -extern uint16_t nni_socket_proto(nni_socket *); -extern int nni_socket_setopt(nni_socket *, int, const void *, size_t); -extern int nni_socket_getopt(nni_socket *, int, void *, size_t *); -extern int nni_socket_recvmsg(nni_socket *, nni_msg **, nni_time); -extern int nni_socket_sendmsg(nni_socket *, nni_msg *, nni_time); -extern int nni_socket_dial(nni_socket *, const char *, nni_endpt **, int); -extern int nni_socket_listen(nni_socket *, const char *, nni_endpt **, int); +extern int nni_sock_open(nni_sock **, uint16_t); +extern int nni_sock_close(nni_sock *); +extern uint16_t nni_sock_proto(nni_sock *); +extern int nni_sock_setopt(nni_sock *, int, const void *, size_t); +extern int nni_sock_getopt(nni_sock *, int, void *, size_t *); +extern int nni_sock_recvmsg(nni_sock *, nni_msg **, nni_time); +extern int nni_sock_sendmsg(nni_sock *, nni_msg *, nni_time); +extern int nni_sock_dial(nni_sock *, const char *, nni_endpt **, int); +extern int nni_sock_listen(nni_sock *, const char *, nni_endpt **, int); // Set error codes for applications. These are only ever // called from the filter functions in protocols, and thus // already have the socket lock held. -extern void nni_socket_recverr(nni_socket *, int); -extern void nni_socket_senderr(nni_socket *, int); +extern void nni_sock_recverr(nni_sock *, int); +extern void nni_sock_senderr(nni_sock *, int); +// These are socket methods that protocol operations can expect to call. +// Note that each of these should be called without any locks held, since +// the socket can reenter the protocol. + +// nni_socket_sendq obtains the upper writeq. The protocol should +// recieve messages from this, and place them on the appropriate pipe. +extern nni_msgq *nni_sock_sendq(nni_sock *); + +// nni_socket_recvq obtains the upper readq. The protocol should +// inject incoming messages from pipes to it. +extern nni_msgq *nni_sock_recvq(nni_sock *); + #endif // CORE_SOCKET_H @@ -37,7 +37,7 @@ nng_open(nng_socket **s, uint16_t proto) if ((rv = nni_init()) != 0) { return (rv); } - return (nni_socket_create(s, proto)); + return (nni_sock_open(s, proto)); } @@ -45,7 +45,7 @@ int nng_close(nng_socket *s) { NNI_INIT_INT(); - return (nni_socket_close(s)); + return (nni_sock_close(s)); } @@ -53,7 +53,7 @@ uint16_t nng_protocol(nng_socket *s) { NNI_INIT_VOID(); - return (nni_socket_proto(s)); + return (nni_sock_proto(s)); } @@ -72,7 +72,7 @@ nng_recvmsg(nng_socket *s, nng_msg **msgp, int flags) expire += s->s_rcvtimeo; } - return (nni_socket_recvmsg(s, msgp, expire)); + return (nni_sock_recvmsg(s, msgp, expire)); } @@ -92,7 +92,7 @@ nng_sendmsg(nng_socket *s, nng_msg *msg, int flags) expire += s->s_sndtimeo; } - return (nni_socket_sendmsg(s, msg, expire)); + return (nni_sock_sendmsg(s, msg, expire)); } @@ -100,7 +100,7 @@ int nng_dial(nng_socket *s, const char *addr, nng_endpt **epp, int flags) { NNI_INIT_INT(); - return (nni_socket_dial(s, addr, epp, flags)); + return (nni_sock_dial(s, addr, epp, flags)); } @@ -108,7 +108,7 @@ int nng_listen(nng_socket *s, const char *addr, nng_endpt **epp, int flags) { NNI_INIT_INT(); - return (nni_socket_listen(s, addr, epp, flags)); + return (nni_sock_listen(s, addr, epp, flags)); } @@ -116,7 +116,7 @@ int nng_setopt(nng_socket *s, int opt, const void *val, size_t sz) { NNI_INIT_INT(); - return (nni_socket_setopt(s, opt, val, sz)); + return (nni_sock_setopt(s, opt, val, sz)); } @@ -124,7 +124,7 @@ int nng_getopt(nng_socket *s, int opt, void *val, size_t *szp) { NNI_INIT_INT(); - return (nni_socket_getopt(s, opt, val, szp)); + return (nni_sock_getopt(s, opt, val, szp)); } @@ -187,7 +187,7 @@ nng_pipe_getopt(nng_pipe *pipe, int opt, void *val, size_t *sizep) rv = nni_pipe_getopt(pipe, opt, val, sizep); if (rv == ENOTSUP) { // Maybe its a generic socket option. - rv = nni_socket_getopt(pipe->p_sock, opt, val, sizep); + rv = nni_sock_getopt(pipe->p_sock, opt, val, sizep); } return (rv); } diff --git a/src/protocol/pair/pair.c b/src/protocol/pair/pair.c index 642f2845..037d5f1e 100644 --- a/src/protocol/pair/pair.c +++ b/src/protocol/pair/pair.c @@ -21,7 +21,7 @@ typedef struct nni_pair_sock nni_pair_sock; // An nni_pair_sock is our per-socket protocol private structure. struct nni_pair_sock { - nni_socket * sock; + nni_sock * sock; nni_pair_pipe * pipe; nni_mtx mx; nni_msgq * uwq; @@ -42,7 +42,7 @@ static void nni_pair_receiver(void *); static void nni_pair_sender(void *); static int -nni_pair_create(void **pairp, nni_socket *sock) +nni_pair_create(void **pairp, nni_sock *sock) { nni_pair_sock *pair; int rv; @@ -56,8 +56,8 @@ nni_pair_create(void **pairp, nni_socket *sock) } pair->sock = sock; pair->pipe = NULL; - pair->uwq = nni_socket_sendq(sock); - pair->urq = nni_socket_recvq(sock); + pair->uwq = nni_sock_sendq(sock); + pair->urq = nni_sock_recvq(sock); *pairp = pair; return (0); } diff --git a/src/protocol/reqrep/rep.c b/src/protocol/reqrep/rep.c index 9323428c..75f2af71 100644 --- a/src/protocol/reqrep/rep.c +++ b/src/protocol/reqrep/rep.c @@ -21,7 +21,7 @@ typedef struct nni_rep_sock nni_rep_sock; // An nni_rep_sock is our per-socket protocol private structure. struct nni_rep_sock { - nni_socket * sock; + nni_sock * sock; nni_mtx mx; nni_msgq * uwq; nni_msgq * urq; @@ -46,7 +46,7 @@ static void nni_rep_sender(void *); static void nni_rep_topsender(void *); static int -nni_rep_create(void **repp, nni_socket *sock) +nni_rep_create(void **repp, nni_sock *sock) { nni_rep_sock *rep; int rv; @@ -69,8 +69,8 @@ nni_rep_create(void **repp, nni_socket *sock) return (rv); } - rep->uwq = nni_socket_sendq(sock); - rep->urq = nni_socket_recvq(sock); + rep->uwq = nni_sock_sendq(sock); + rep->urq = nni_sock_recvq(sock); rv = nni_thr_init(&rep->sender, nni_rep_topsender, rep); if (rv != 0) { @@ -80,7 +80,7 @@ nni_rep_create(void **repp, nni_socket *sock) return (rv); } *repp = rep; - nni_socket_senderr(sock, NNG_ESTATE); + nni_sock_senderr(sock, NNG_ESTATE); nni_thr_run(&rep->sender); return (0); } @@ -360,7 +360,7 @@ nni_rep_sendfilter(void *arg, nni_msg *msg) } // Cannot send again until a receive is done... - nni_socket_senderr(rep->sock, NNG_ESTATE); + nni_sock_senderr(rep->sock, NNG_ESTATE); // If we have a stored backtrace, append it to the header... // if we don't have a backtrace, discard the message. @@ -404,7 +404,7 @@ nni_rep_recvfilter(void *arg, nni_msg *msg) return (msg); } - nni_socket_senderr(rep->sock, 0); + nni_sock_senderr(rep->sock, 0); header = nni_msg_header(msg, &len); if (rep->btrace != NULL) { nni_free(rep->btrace, rep->btrace_len); diff --git a/src/protocol/reqrep/req.c b/src/protocol/reqrep/req.c index 35df0e56..ba7d4f6b 100644 --- a/src/protocol/reqrep/req.c +++ b/src/protocol/reqrep/req.c @@ -21,7 +21,7 @@ typedef struct nni_req_sock nni_req_sock; // An nni_req_sock is our per-socket protocol private structure. struct nni_req_sock { - nni_socket * sock; + nni_sock * sock; nni_mtx mx; nni_cv cv; nni_msgq * uwq; @@ -50,7 +50,7 @@ static void nni_req_sender(void *); static void nni_req_resender(void *); static int -nni_req_create(void **reqp, nni_socket *sock) +nni_req_create(void **reqp, nni_sock *sock) { nni_req_sock *req; int rv; @@ -76,10 +76,10 @@ nni_req_create(void **reqp, nni_socket *sock) req->resend = NNI_TIME_ZERO; NNI_LIST_INIT(&req->pipes, nni_req_pipe, node); - req->uwq = nni_socket_sendq(sock); - req->urq = nni_socket_recvq(sock); + req->uwq = nni_sock_sendq(sock); + req->urq = nni_sock_recvq(sock); *reqp = req; - nni_socket_recverr(sock, NNG_ESTATE); + nni_sock_recverr(sock, NNG_ESTATE); rv = nni_thr_init(&req->resender, nni_req_resender, req); if (rv != 0) { nni_cv_fini(&req->cv); @@ -345,7 +345,7 @@ nni_req_sendfilter(void *arg, nni_msg *msg) nni_cv_wake(&req->cv); // Clear the error condition. - nni_socket_recverr(req->sock, 0); + nni_sock_recverr(req->sock, 0); nni_mtx_unlock(&req->mx); return (msg); @@ -386,7 +386,7 @@ nni_req_recvfilter(void *arg, nni_msg *msg) return (NULL); } - nni_socket_recverr(req->sock, NNG_ESTATE); + nni_sock_recverr(req->sock, NNG_ESTATE); nni_msg_free(req->reqmsg); req->reqmsg = NULL; nni_cv_wake(&req->cv); |
