diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/defs.h | 43 | ||||
| -rw-r--r-- | src/core/endpt.h | 45 | ||||
| -rw-r--r-- | src/core/pipe.h | 26 | ||||
| -rw-r--r-- | src/core/platform.h | 8 | ||||
| -rw-r--r-- | src/core/protocol.h | 2 | ||||
| -rw-r--r-- | src/core/socket.c | 41 | ||||
| -rw-r--r-- | src/core/socket.h | 33 |
7 files changed, 100 insertions, 98 deletions
diff --git a/src/core/defs.h b/src/core/defs.h index b862f3ab..b294e0f3 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -1,28 +1,35 @@ -/* - * Copyright 2016 Garrett D'Amore <garrett@damore.org> - * - * This software is supplied under the terms of the MIT License, a - * copy of which should be located in the distribution where this - * file was obtained (LICENSE.txt). A copy of the license may also be - * found online at https://opensource.org/licenses/MIT. - */ +// +// Copyright 2016 Garrett D'Amore <garrett@damore.org> +// +// This software is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// #ifndef CORE_DEFS_H #define CORE_DEFS_H -/* - * C compilers may get unhappy when named arguments are not used. While - * there are things like __attribute__((unused)) which are arguably - * superior, support for such are not universal. - */ +// C compilers may get unhappy when named arguments are not used. While +// there are things like __attribute__((unused)) which are arguably +// superior, support for such are not universal. #define NNI_ARG_UNUSED(x) ((void) x); -/* - * These types are common but have names shared with user space. - */ +// These types are common but have names shared with user space. typedef struct nng_socket * nni_socket_t; typedef struct nng_pipe * nni_pipe_t; typedef struct nng_msg * nni_msg_t; -typedef struct nng_endpt * nni_endpt_t; -#endif /* CORE_DEFS_H */ +typedef struct nng_socket nni_socket; +typedef struct nng_endpt nni_endpt; +typedef struct nng_pipe nni_pipe; +typedef struct nng_msg nni_msg; + +// These are our own names. +typedef struct nni_transport nni_transport; +typedef struct nni_endpt_ops nni_endpt_ops; +typedef struct nni_pipe_ops nni_pipe_ops; + +typedef struct nni_protocol nni_protocol; + +#endif // CORE_DEFS_H diff --git a/src/core/endpt.h b/src/core/endpt.h index cd46bb61..063dcb7b 100644 --- a/src/core/endpt.h +++ b/src/core/endpt.h @@ -1,28 +1,25 @@ -/* - * Copyright 2016 Garrett D'Amore <garrett@damore.org> - * - * This software is supplied under the terms of the MIT License, a - * copy of which should be located in the distribution where this - * file was obtained (LICENSE.txt). A copy of the license may also be - * found online at https://opensource.org/licenses/MIT. - */ +// +// Copyright 2016 Garrett D'Amore <garrett@damore.org> +// +// This software is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// #ifndef CORE_ENDPT_H #define CORE_ENDPT_H #include "core/transport.h" -/* - * NB: This structure is supplied here for use by the CORE. Use of this library - * OUSIDE of the core is STRICTLY VERBOTEN. NO DIRECT ACCESS BY PROTOCOLS OR - * TRANSPORTS. - */ - +// NB: This structure is supplied here for use by the CORE. Use of this library +// OUSIDE of the core is STRICTLY VERBOTEN. NO DIRECT ACCESS BY PROTOCOLS OR +// TRANSPORTS. struct nng_endpt { struct nni_endpt_ops ep_ops; void * ep_tran; nni_list_node_t ep_sock_node; - nni_socket_t ep_sock; + nni_socket * ep_sock; const char * ep_addr; nni_thread_t ep_dialer; nni_thread_t ep_listener; @@ -31,15 +28,11 @@ struct nng_endpt { nni_cond_t ep_cv; }; -/* - * This file contains definitions for endpoints. - */ - -int nni_endpt_create(nni_endpt_t *, nni_socket_t, const char *); -void nni_endpt_destroy(nni_endpt_t); -int nni_endpt_dial(nni_endpt_t, nni_pipe_t *); -int nni_endpt_listen(nni_endpt_t); -int nni_endpt_accept(nni_endpt_t, nni_pipe_t *); -int nni_endpt_close(nni_endpt_t); +int nni_endpt_create(nni_endpt **, nni_socket *, const char *); +void nni_endpt_destroy(nni_endpt *); +int nni_endpt_dial(nni_endpt *, nni_pipe **); +int nni_endpt_listen(nni_endpt *); +int nni_endpt_accept(nni_endpt *, nni_pipe **); +int nni_endpt_close(nni_endpt *); -#endif /* CORE_ENDPT_H */ +#endif // CORE_ENDPT_H diff --git a/src/core/pipe.h b/src/core/pipe.h index 0708fdcc..a4a03a93 100644 --- a/src/core/pipe.h +++ b/src/core/pipe.h @@ -23,26 +23,22 @@ struct nng_pipe { struct nni_pipe_ops p_ops; void * p_tran; nni_list_node_t p_sock_node; - nni_socket_t p_sock; + nni_socket * p_sock; nni_list_node_t p_ep_node; - nni_endpt_t p_ep; + nni_endpt * p_ep; }; -/* - * Pipe operations that protocols use. - */ -extern int nni_pipe_recv(nni_pipe_t, nng_msg_t *); -extern int nni_pipe_send(nni_pipe_t, nng_msg_t); -extern uint32_t nni_pipe_id(nni_pipe_t); -extern void nni_pipe_close(nni_pipe_t); + // Pipe operations that protocols use. +extern int nni_pipe_recv(nni_pipe *, nng_msg_t *); +extern int nni_pipe_send(nni_pipe *, nng_msg_t); +extern uint32_t nni_pipe_id(nni_pipe *); +extern void nni_pipe_close(nni_pipe *); -/* - * Used only by the socket core - as we don't wish to expose the details - * of the pipe structure outside of pipe.c. - */ -extern int nni_pipe_create(nni_pipe_t *, struct nni_transport *); +// Used only by the socket core - as we don't wish to expose the details +// of the pipe structure outside of pipe.c. +extern int nni_pipe_create(nni_pipe **, struct nni_transport *); -extern void nni_pipe_destroy(nni_pipe_t); +extern void nni_pipe_destroy(nni_pipe *); #endif /* CORE_PIPE_H */ diff --git a/src/core/platform.h b/src/core/platform.h index 00401493..104a94a0 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -64,6 +64,9 @@ typedef struct nni_mutex * nni_mutex_t; typedef struct nni_cond * nni_cond_t; // Mutex handling. +extern int nni_mutex_init(nni_mutex *); +extern void nni_mutex_fini(nni_mutex *); + extern int nni_mutex_create(nni_mutex_t *); extern void nni_mutex_destroy(nni_mutex_t); @@ -96,15 +99,16 @@ extern void nni_cond_wait(nni_cond_t); extern int nni_cond_timedwait(nni_cond_t, uint64_t); typedef struct nni_thread * nni_thread_t; +typedef struct nni_thread nni_thread; // nni_thread_creates a thread that runs the given function. The thread // receives a single argument. -extern int nni_thread_create(nni_thread_t *, void (*fn)(void *), void *); +extern int nni_thread_create(nni_thread **, void (*fn)(void *), void *); // nni_thread_reap waits for the thread to exit, and then releases any // resources associated with the thread. After this returns, it // is an error to reference the thread in any further way. -extern void nni_thread_reap(nni_thread_t); +extern void nni_thread_reap(nni_thread *); // nn_clock returns a number of microseconds since some arbitrary time // in the past. The values returned by nni_clock may be used with diff --git a/src/core/protocol.h b/src/core/protocol.h index b9760725..21d3b6b9 100644 --- a/src/core/protocol.h +++ b/src/core/protocol.h @@ -59,7 +59,7 @@ struct nni_protocol { * created or destroyed. */ int (*proto_add_pipe)(void *, nni_pipe_t); - int (*proto_remove_pipe)(void *, nni_pipe_t); + int (*proto_rem_pipe)(void *, nni_pipe_t); /* * Option manipulation. These may be NULL. diff --git a/src/core/socket.c b/src/core/socket.c index 21b1b300..0272f454 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -14,14 +14,14 @@ // nni_socket_sendq and nni_socket_recvq are called by the protocol to obtain // the upper read and write queues. nni_msgqueue_t -nni_socket_sendq(nni_socket_t s) +nni_socket_sendq(nni_socket *s) { return (s->s_uwq); } nni_msgqueue_t -nni_socket_recvq(nni_socket_t s) +nni_socket_recvq(nni_socket *s) { return (s->s_urq); } @@ -29,9 +29,9 @@ nni_socket_recvq(nni_socket_t s) // nn_socket_create creates the underlying socket. int -nni_socket_create(nni_socket_t *sockp, uint16_t proto) +nni_socket_create(nni_socket **sockp, uint16_t proto) { - nni_socket_t sock; + nni_socket *sock; struct nni_protocol *ops; int rv; @@ -69,10 +69,10 @@ nni_socket_create(nni_socket_t *sockp, uint16_t proto) // nni_socket_close closes the underlying socket. int -nni_socket_close(nni_socket_t sock) +nni_socket_close(nni_socket *sock) { - nni_pipe_t pipe; - nni_endpt_t ep; + nni_pipe *pipe; + nni_endpt *ep; nni_mutex_enter(sock->s_mx); @@ -86,7 +86,9 @@ nni_socket_close(nni_socket_t sock) // XXX: Question: block for them now, or wait further down? // Probably we can simply just watch for the first list... // stopping EPs should be *dead* easy, and never block. - nni_ep_stop(ep); or nni_ep_shutdown(ep); + nni_ep_stop(ep); + or nni_ep_shutdown(ep); + #endif break; /* REMOVE ME */ } @@ -142,14 +144,14 @@ nni_socket_close(nni_socket_t sock) int -nni_socket_sendmsg(nni_socket_t sock, nni_msg_t msg, int tmout) +nni_socket_sendmsg(nni_socket *sock, nni_msg *msg, int tmout) { int rv; int besteffort; - // Senderr is typically set by protocols when the state machine - // indicates that it is no longer valid to send a message. E.g. - // a REP socket with no REQ pending. + // Senderr is typically set by protocols when the state machine + // indicates that it is no longer valid to send a message. E.g. + // a REP socket with no REQ pending. nni_mutex_enter(sock->s_mx); if ((rv = sock->s_senderr) != 0) { nni_mutex_exit(sock->s_mx); @@ -166,8 +168,8 @@ nni_socket_sendmsg(nni_socket_t sock, nni_msg_t msg, int tmout) } if (besteffort) { - // BestEffort mode -- if we cannot handle the message due to - // backpressure, we just throw it away, and don't complain. + // BestEffort mode -- if we cannot handle the message due to + // backpressure, we just throw it away, and don't complain. tmout = 0; } rv = nni_msgqueue_put(sock->s_uwq, msg, tmout); @@ -182,15 +184,16 @@ nni_socket_sendmsg(nni_socket_t sock, nni_msg_t msg, int tmout) // nni_socket_protocol returns the socket's 16-bit protocol number. uint16_t -nni_socket_proto(nni_socket_t sock) +nni_socket_proto(nni_socket *sock) { return (sock->s_ops.proto_self); } -// nni_socket_remove_pipe removes the pipe from the socket. This is often + +// nni_socket_rem_pipe removes the pipe from the socket. This is often // called by the protocol when a pipe is removed due to close. void -nni_socket_rem_pipe(nni_socket_t sock, nni_pipe_t pipe) +nni_socket_rem_pipe(nni_socket *sock, nni_pipe *pipe) { nni_mutex_enter(sock->s_mx); if (pipe->p_sock != sock) { @@ -199,7 +202,7 @@ nni_socket_rem_pipe(nni_socket_t sock, nni_pipe_t pipe) // Remove the pipe from the protocol. Protocols may // keep lists of pipes for managing their topologies. - sock->s_ops.proto_remove_pipe(sock->s_data, pipe); + sock->s_ops.proto_rem_pipe(sock->s_data, pipe); // Now remove it from our own list. nni_list_remove(&sock->s_pipes, pipe); @@ -219,7 +222,7 @@ nni_socket_rem_pipe(nni_socket_t sock, nni_pipe_t pipe) int -nni_socket_add_pipe(nni_socket_t sock, nni_pipe_t pipe) +nni_socket_add_pipe(nni_socket *sock, nni_pipe *pipe) { int rv; diff --git a/src/core/socket.h b/src/core/socket.h index 366e9958..55944c92 100644 --- a/src/core/socket.h +++ b/src/core/socket.h @@ -1,11 +1,11 @@ -/* - * Copyright 2016 Garrett D'Amore <garrett@damore.org> - * - * This software is supplied under the terms of the MIT License, a - * copy of which should be located in the distribution where this - * file was obtained (LICENSE.txt). A copy of the license may also be - * found online at https://opensource.org/licenses/MIT. - */ +// +// Copyright 2016 Garrett D'Amore <garrett@damore.org> +// +// This software is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// #ifndef CORE_SOCKET_H #define CORE_SOCKET_H @@ -13,7 +13,6 @@ // NB: This structure is supplied here for use by the CORE. Use of this library // OUSIDE of the core is STRICTLY VERBOTEN. NO DIRECT ACCESS BY PROTOCOLS OR // TRANSPORTS. - struct nng_socket { nni_mutex_t s_mx; nni_cond_t s_cv; @@ -25,7 +24,7 @@ struct nng_socket { void * s_data; // Protocol private - /* XXX: options */ + // XXX: options nni_list_t s_eps; nni_list_t s_pipes; @@ -35,12 +34,12 @@ struct nng_socket { int s_senderr; // Protocol state machine use }; -extern int nni_socket_create(nni_socket_t *, uint16_t); -extern int nni_socket_close(nni_socket_t); -extern int nni_socket_add_pipe(nni_socket_t, nni_pipe_t); -extern void nni_socket_rem_pipe(nni_socket_t, nni_pipe_t); -extern uint16_t nni_socket_proto(nni_socket_t); -extern int nni_socket_setopt(nni_socket_t, int, const void *, size_t); -extern int nni_socket_getopt(nni_socket_t, int, void *, size_t *); +extern int nni_socket_create(nni_socket **, uint16_t); +extern int nni_socket_close(nni_socket *); +extern int nni_socket_add_pipe(nni_socket *, nni_pipe *); +extern void nni_socket_rem_pipe(nni_socket *, nni_pipe *); +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 *); #endif // CORE_SOCKET_H |
