diff options
Diffstat (limited to 'src')
| -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 | ||||
| -rw-r--r-- | src/platform/posix/posix_alloc.c | 7 | ||||
| -rw-r--r-- | src/platform/posix/posix_clock.c | 7 | ||||
| -rw-r--r-- | src/platform/posix/posix_config.h | 2 | ||||
| -rw-r--r-- | src/platform/posix/posix_debug.c | 18 | ||||
| -rw-r--r-- | src/platform/posix/posix_impl.h | 42 | ||||
| -rw-r--r-- | src/platform/posix/posix_synch.c | 31 | ||||
| -rw-r--r-- | src/platform/posix/posix_thread.c | 35 | ||||
| -rw-r--r-- | src/protocol/pair/pair.c | 47 | ||||
| -rw-r--r-- | src/transport/inproc/inproc.c | 38 |
16 files changed, 212 insertions, 213 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 diff --git a/src/platform/posix/posix_alloc.c b/src/platform/posix/posix_alloc.c index 16b2dce3..eb5c889e 100644 --- a/src/platform/posix/posix_alloc.c +++ b/src/platform/posix/posix_alloc.c @@ -7,13 +7,6 @@ * found online at https://opensource.org/licenses/MIT. */ -/* - * This is more of a direct #include of a .c rather than .h file. - * But having it be a .h makes compiler rules work out properly. Do - * not include this more than once into your program, or you will - * get multiple symbols defined. - */ - #include "core/nng_impl.h" #ifdef PLATFORM_POSIX_ALLOC diff --git a/src/platform/posix/posix_clock.c b/src/platform/posix/posix_clock.c index 5c29d5ff..83f0b151 100644 --- a/src/platform/posix/posix_clock.c +++ b/src/platform/posix/posix_clock.c @@ -8,13 +8,6 @@ */ /* - * This is more of a direct #include of a .c rather than .h file. - * But having it be a .h makes compiler rules work out properly. Do - * not include this more than once into your program, or you will - * get multiple symbols defined. - */ - -/* * POSIX clock stuff. */ #include "core/nng_impl.h" diff --git a/src/platform/posix/posix_config.h b/src/platform/posix/posix_config.h index a8da8ccd..dd2167ab 100644 --- a/src/platform/posix/posix_config.h +++ b/src/platform/posix/posix_config.h @@ -44,4 +44,4 @@ #else #define NNG_USE_CLOCKID CLOCK_REALTIME #endif -#endif /* CLOCK_REALTIME */ +#endif // CLOCK_REALTIME diff --git a/src/platform/posix/posix_debug.c b/src/platform/posix/posix_debug.c index 37c0af66..56b443e9 100644 --- a/src/platform/posix/posix_debug.c +++ b/src/platform/posix/posix_debug.c @@ -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. +// #include "core/nng_impl.h" @@ -28,4 +28,4 @@ nni_plat_println(const char *message) } -#endif /* PLATFORM_POSIX_DEBUG */ +#endif // PLATFORM_POSIX_DEBUG diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h index c18af983..0a3151f3 100644 --- a/src/platform/posix/posix_impl.h +++ b/src/platform/posix/posix_impl.h @@ -1,21 +1,14 @@ -/* - * 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. +// -/* - * This is more of a direct #include of a .c rather than .h file. - * But having it be a .h makes compiler rules work out properly. Do - * not include this more than once into your program, or you will - * get multiple symbols defined. - * - * The file itself pulls in POSIX implementations for platform specific - * functionality. - */ +#ifndef PLATFORM_POSIX_IMPL_H +#define PLATFORM_POSIX_IMPL_H #ifdef PLATFORM_POSIX #define PLATFORM_POSIX_ALLOC @@ -23,7 +16,20 @@ #define PLATFORM_POSIX_CLOCK #define PLATFORM_POSIX_SYNCH #define PLATFORM_POSIX_THREAD -#define PLATFORM_POSIX_VSNPRINTF #include "platform/posix/posix_config.h" #endif + +// Define types that this platform uses. +#ifdef PLATFORM_POSIX_SYNCH +struct nni_mutex { + pthread_mutex_t mx; +} + +struct nni_condvar { + pthread_cond_t cv; + pthread_mutex_t * mx; +} +#endif + +#endif // PLATFORM_POSIX_IMPL_H
\ No newline at end of file diff --git a/src/platform/posix/posix_synch.c b/src/platform/posix/posix_synch.c index 555da36b..13147573 100644 --- a/src/platform/posix/posix_synch.c +++ b/src/platform/posix/posix_synch.c @@ -26,14 +26,27 @@ #include <pthread.h> #include <time.h> -struct nni_mutex { - pthread_mutex_t mx; -}; +int +nni_mutex_init(nni_mutex *mp) +{ + // pthrad_mutex_attr_t attr; + if (pthread_mutex_init(&mp->mx, NULL) != NULL) { + return (NNG_ENOMEM); + } + return (0); +} + + +void +nni_mutex_fini(nni_mutex *mp) +{ + int rv; + + if ((rv = pthread_mutex_destroy(&mp-- > mx)) != 0) { + nni_panic("pthread_mutex_destroy failed: %s", strerror(rv)); + } +} -struct nni_cond { - pthread_cond_t cv; - pthread_mutex_t * mx; -}; int nni_mutex_create(nni_mutex_t *mp) @@ -109,8 +122,8 @@ nni_mutex_tryenter(nni_mutex_t m) } -int -cond_attr(pthread_condattr_t **attrpp) +static int +nni_cond_attr(pthread_condattr_t **attrpp) { #if defined(NNG_USE_GETTIMEOFDAY) || NNG_USE_CLOCKID == CLOCK_REALTIME *attrpp = NULL; diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c index 98b42d5c..8928974c 100644 --- a/src/platform/posix/posix_thread.c +++ b/src/platform/posix/posix_thread.c @@ -1,22 +1,13 @@ -/* - * 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. - */ - -/* - * This is more of a direct #include of a .c rather than .h file. - * But having it be a .h makes compiler rules work out properly. Do - * not include this more than once into your program, or you will - * get multiple symbols defined. - */ - -/* - * POSIX threads. - */ +// +// 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. +// + +// POSIX threads. #include "core/nng_impl.h" @@ -95,10 +86,10 @@ nni_plat_init(int (*helper)(void)) nni_panic("nng is fork-reentrant safe"); } if (plat_init) { - return (0); /* fast path */ + return (0); // fast path } pthread_mutex_lock(&plat_lock); - if (plat_init) { /* check again under the lock to be sure */ + if (plat_init) { // check again under the lock to be sure pthread_mutex_unlock(&plat_lock); return (0); } @@ -118,7 +109,7 @@ nni_plat_init(int (*helper)(void)) void nni_plat_fini(void) { - /* XXX: NOTHING *YET* */ + // XXX: NOTHING *YET* } diff --git a/src/protocol/pair/pair.c b/src/protocol/pair/pair.c index 5c1862a1..4c2d36d1 100644 --- a/src/protocol/pair/pair.c +++ b/src/protocol/pair/pair.c @@ -18,9 +18,9 @@ // An nni_pair_sock is our per-socket protocol private structure. typedef struct nni_pair_sock { - nni_socket_t sock; + nni_socket * sock; + nni_pipe * pipe; nni_mutex_t mx; - nni_pipe_t pipe; nni_msgqueue_t uwq; nni_msgqueue_t urq; } nni_pair_sock; @@ -30,7 +30,7 @@ typedef struct nni_pair_sock { // pipe. The separate data structure is more like other protocols that do // manage multiple pipes. typedef struct nni_pair_pipe { - nni_pipe_t pipe; + nni_pipe * pipe; nni_pair_sock * pair; int good; nni_thread_t sthr; @@ -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_t sock) +nni_pair_create(void **pairp, nni_socket *sock) { nni_pair_sock *pair; int rv; @@ -100,7 +100,7 @@ nni_pair_shutdown(void *arg) static int -nni_pair_add_pipe(void *arg, nni_pipe_t pipe) +nni_pair_add_pipe(void *arg, nni_pipe *pipe) { nni_pair_sock *pair = arg; nni_pair_pipe *pp; @@ -136,7 +136,7 @@ nni_pair_add_pipe(void *arg, nni_pipe_t pipe) static int -nni_pair_rem_pipe(void *arg, nni_pipe_t pipe) +nni_pair_rem_pipe(void *arg, nni_pipe *pipe) { nni_pair_pipe *pp = arg; nni_pair_sock *pair = pp->pair; @@ -164,8 +164,8 @@ nni_pair_sender(void *arg) nni_pair_sock *pair = pp->pair; nni_msgqueue_t uwq = pair->uwq; nni_msgqueue_t urq = pair->urq; - nni_pipe_t pipe = pp->pipe; - nni_msg_t msg; + nni_pipe *pipe = pp->pipe; + nni_msg *msg; int rv; nni_mutex_enter(pair->mx); @@ -200,8 +200,8 @@ nni_pair_receiver(void *arg) nni_pair_sock *pair = pp->pair; nni_msgqueue_t urq = pair->urq; nni_msgqueue_t uwq = pair->uwq; - nni_pipe_t pipe = pp->pipe; - nni_msg_t msg; + nni_pipe *pipe = pp->pipe; + nni_msg *msg; int rv; nni_mutex_enter(pair->mx); @@ -227,7 +227,8 @@ nni_pair_receiver(void *arg) nni_socket_rem_pipe(pair->sock, pipe); } - +// TODO: probably we could replace these with NULL, since we have no +// protocol specific options? static int nni_pair_setopt(void *arg, int opt, const void *buf, size_t sz) { @@ -245,16 +246,16 @@ nni_pair_getopt(void *arg, int opt, void *buf, size_t *szp) // This is the global protocol structure -- our linkage to the core. // This should be the only global non-static symbol in this file. struct nni_protocol nni_pair_protocol = { - NNG_PROTO_PAIR, // proto_self - NNG_PROTO_PAIR, // proto_peer - "pair", - nni_pair_create, - nni_pair_destroy, - nni_pair_shutdown, - nni_pair_add_pipe, - nni_pair_rem_pipe, - nni_pair_setopt, - nni_pair_getopt, - NULL, // proto_recvfilter - NULL, // proto_sendfilter + .proto_self = NNG_PROTO_PAIR, + .proto_peer = NNG_PROTO_PAIR, + .proto_name = "pair", + .proto_create = nni_pair_create, + .proto_destroy = nni_pair_destroy, + .proto_shutdown = nni_pair_shutdown, + .proto_add_pipe = nni_pair_add_pipe, + .proto_rem_pipe = nni_pair_rem_pipe, + .proto_setopt = nni_pair_setopt, + .proto_getopt = nni_pair_getopt, + .proto_recv_filter = NULL, + .proto_send_filter = NULL, }; diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c index 49b9de26..029825b1 100644 --- a/src/transport/inproc/inproc.c +++ b/src/transport/inproc/inproc.c @@ -377,31 +377,31 @@ nni_inproc_ep_accept(void *arg, void **pipep) static struct nni_pipe_ops nni_inproc_pipe_ops = { - nni_inproc_pipe_destroy, - nni_inproc_pipe_send, - nni_inproc_pipe_recv, - nni_inproc_pipe_close, - nni_inproc_pipe_peer, - nni_inproc_pipe_getopt, + .p_destroy = nni_inproc_pipe_destroy, + .p_send = nni_inproc_pipe_send, + .p_recv = nni_inproc_pipe_recv, + .p_close = nni_inproc_pipe_close, + .p_peer = nni_inproc_pipe_peer, + .p_getopt = nni_inproc_pipe_getopt, }; static struct nni_endpt_ops nni_inproc_ep_ops = { - nni_inproc_ep_create, - nni_inproc_ep_destroy, - nni_inproc_ep_dial, - nni_inproc_ep_listen, - nni_inproc_ep_accept, - nni_inproc_ep_close, - NULL, // inproc_ep_setopt - NULL, // inproc_ep_getopt + .ep_create = nni_inproc_ep_create, + .ep_destroy = nni_inproc_ep_destroy, + .ep_dial = nni_inproc_ep_dial, + .ep_listen = nni_inproc_ep_listen, + .ep_accept = nni_inproc_ep_accept, + .ep_close = nni_inproc_ep_close, + .ep_setopt = NULL, + .ep_getopt = NULL, }; // This is the inproc transport linkage, and should be the only global // symbol in this entire file. struct nni_transport nni_inproc_transport = { - "inproc", // tran_scheme - &nni_inproc_ep_ops, // tran_ep_ops - &nni_inproc_pipe_ops, // tran_pipe_ops - nni_inproc_init, // tran_init - nni_inproc_fini, // tran_fini + .tran_scheme = "inproc", + .tran_ep_ops = &nni_inproc_ep_ops, + .tran_pipe_ops = &nni_inproc_pipe_ops, + .tran_init = nni_inproc_init, + .tran_fini = nni_inproc_fini, }; |
