From 6a5d5efd3ba1d74ad5f4f200418da0ba83ca9efa Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 14 Dec 2016 16:36:50 -0800 Subject: Better separate public vs. private names. --- src/core/defs.h | 10 +++++++++- src/core/endpt.h | 12 ++++++------ src/core/message.c | 32 ++++++++++++++++---------------- src/core/message.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/core/msgqueue.c | 16 ++++++++-------- src/core/nng_impl.h | 2 ++ src/core/pipe.c | 16 +++++++++------- src/core/pipe.h | 16 ++++++---------- src/core/protocol.h | 26 +++++++++----------------- src/core/socket.c | 20 ++++++++++---------- src/core/socket.h | 39 +++++++++++++++++++++++++++++++++++++++ 11 files changed, 160 insertions(+), 75 deletions(-) create mode 100644 src/core/message.h create mode 100644 src/core/socket.h (limited to 'src/core') diff --git a/src/core/defs.h b/src/core/defs.h index f747f901..a1789a36 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -30,4 +30,12 @@ */ #define NNI_ARG_UNUSED(x) ((void)x); -#endif /* NNG_IMPL_H */ +/* + * 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 */ diff --git a/src/core/endpt.h b/src/core/endpt.h index 4a0921dc..4c8336d6 100644 --- a/src/core/endpt.h +++ b/src/core/endpt.h @@ -27,11 +27,11 @@ * This file contains definitions for endpoints. */ -int nni_endpt_create(nng_endpt_t *, nng_socket_t, const char *); -void nni_endpt_destroy(nng_endpt_t); -int nni_endpt_dial(nng_endpt_t, nng_pipe_t *); -int nni_endpt_listen(nng_endpt_t); -int nni_endpt_accept(nng_endpt_t, nng_pipe_t *); -int nni_endpt_close(nng_endpt_t); +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); #endif /* CORE_ENDPT_H */ \ No newline at end of file diff --git a/src/core/message.c b/src/core/message.c index 581f7683..b0c83da9 100644 --- a/src/core/message.c +++ b/src/core/message.c @@ -42,7 +42,7 @@ struct nng_msg { chunk_t m_header; chunk_t m_body; int64_t m_expire; /* Unix usec */ - nng_pipe_t m_pipe; /* Pipe message was received on */ + nni_pipe_t m_pipe; /* Pipe message was received on */ }; /* @@ -226,9 +226,9 @@ chunk_prepend(chunk_t *ch, const void *data, size_t len) } int -nng_msg_alloc(nng_msg_t *mp, size_t sz) +nni_msg_alloc(nni_msg_t *mp, size_t sz) { - nng_msg_t m; + nni_msg_t m; int rv; if ((m = nni_alloc(sizeof (*m))) == NULL) { @@ -270,7 +270,7 @@ nng_msg_alloc(nng_msg_t *mp, size_t sz) } void -nng_msg_free(nng_msg_t m) +nni_msg_free(nni_msg_t m) { chunk_free(&m->m_header); chunk_free(&m->m_body); @@ -278,7 +278,7 @@ nng_msg_free(nng_msg_t m) } int -nng_msg_realloc(nng_msg_t m, size_t sz) +nni_msg_realloc(nni_msg_t m, size_t sz) { int rv = 0; if (m->m_body.ch_len < sz) { @@ -294,7 +294,7 @@ nng_msg_realloc(nng_msg_t m, size_t sz) } void * -nng_msg_header(nng_msg_t m, size_t *szp) +nni_msg_header(nni_msg_t m, size_t *szp) { if (szp != NULL) { *szp = m->m_header.ch_len; @@ -303,7 +303,7 @@ nng_msg_header(nng_msg_t m, size_t *szp) } void * -nng_msg_body(nng_msg_t m, size_t *szp) +nni_msg_body(nni_msg_t m, size_t *szp) { if (szp != NULL) { *szp = m->m_body.ch_len; @@ -312,55 +312,55 @@ nng_msg_body(nng_msg_t m, size_t *szp) } int -nng_msg_append(nng_msg_t m, const void *data, size_t len) +nni_msg_append(nni_msg_t m, const void *data, size_t len) { return (chunk_append(&m->m_body, data, len)); } int -nng_msg_prepend(nng_msg_t m, const void *data, size_t len) +nni_msg_prepend(nni_msg_t m, const void *data, size_t len) { return (chunk_prepend(&m->m_body, data, len)); } int -nng_msg_trim(nng_msg_t m, size_t len) +nni_msg_trim(nni_msg_t m, size_t len) { return (chunk_trim(&m->m_body, len)); } int -nng_msg_trunc(nng_msg_t m, size_t len) +nni_msg_trunc(nni_msg_t m, size_t len) { return (chunk_trunc(&m->m_body, len)); } int -nng_msg_append_header(nng_msg_t m, const void *data, size_t len) +nni_msg_append_header(nni_msg_t m, const void *data, size_t len) { return (chunk_append(&m->m_header, data, len)); } int -nng_msg_prepend_header(nng_msg_t m, const void *data, size_t len) +nni_msg_prepend_header(nni_msg_t m, const void *data, size_t len) { return (chunk_prepend(&m->m_header, data, len)); } int -nng_msg_trim_header(nng_msg_t m, size_t len) +nni_msg_trim_header(nni_msg_t m, size_t len) { return (chunk_trim(&m->m_header, len)); } int -nng_msg_trunc_header(nng_msg_t m, size_t len) +nni_msg_trunc_header(nni_msg_t m, size_t len) { return (chunk_trunc(&m->m_header, len)); } int -nng_msg_pipe(nng_msg_t m, nng_pipe_t *pp) +nni_msg_pipe(nni_msg_t m, nni_pipe_t *pp) { *pp = m->m_pipe; return (0); diff --git a/src/core/message.h b/src/core/message.h new file mode 100644 index 00000000..57184e56 --- /dev/null +++ b/src/core/message.h @@ -0,0 +1,46 @@ +/* + * Copyright 2016 Garrett D'Amore + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef CORE_MESSAGE_H +#define CORE_MESSAGE_H + +/* + * Internally used message API. Again, this stuff is not part of our public + * API. + */ + +extern int nni_msg_alloc(nni_msg_t *, size_t); +extern void nni_msg_free(nni_msg_t); +extern int nni_msg_realloc(nni_msg_t, size_t); +extern void *nni_msg_header(nni_msg_t, size_t *); +extern void *nni_msg_body(nni_msg_t, size_t *); +extern int nni_msg_append(nni_msg_t, const void *, size_t); +extern int nni_msg_prepend(nni_msg_t, const void *, size_t); +extern int nni_msg_append_header(nni_msg_t, const void *, size_t); +extern int nni_msg_prepend_header(nni_msg_t, const void *, size_t); +extern int nni_msg_trim(nni_msg_t, size_t); +extern int nni_msg_trunc(nni_msg_t, size_t); +extern int nni_msg_trim_header(nni_msg_t, size_t); +extern int nni_msg_trunc_header(nni_msg_t, size_t); +extern int nni_msg_pipe(nni_msg_t, nni_pipe_t *); + +#endif /* CORE_SOCKET_H */ diff --git a/src/core/msgqueue.c b/src/core/msgqueue.c index 7a4eaf52..372d2c08 100644 --- a/src/core/msgqueue.c +++ b/src/core/msgqueue.c @@ -87,7 +87,7 @@ nni_msgqueue_create(nni_msgqueue_t *mqp, int cap) void nni_msgqueue_destroy(nni_msgqueue_t mq) { - nng_msg_t msg; + nni_msg_t msg; nni_cond_destroy(mq->mq_writeable); nni_cond_destroy(mq->mq_readable); @@ -101,7 +101,7 @@ nni_msgqueue_destroy(nni_msgqueue_t mq) mq->mq_get = 0; } mq->mq_len--; - nng_msg_free(msg); + nni_msg_free(msg); } nni_free(mq->mq_msgs, mq->mq_cap * sizeof (nng_msg_t)); @@ -127,7 +127,7 @@ nni_msgqueue_signal(nni_msgqueue_t mq, int *signal) } int -nni_msgqueue_put_sig(nni_msgqueue_t mq, nng_msg_t msg, int tmout, int *signal) +nni_msgqueue_put_sig(nni_msgqueue_t mq, nni_msg_t msg, int tmout, int *signal) { uint64_t expire, now; @@ -186,7 +186,7 @@ nni_msgqueue_put_sig(nni_msgqueue_t mq, nng_msg_t msg, int tmout, int *signal) } int -nni_msgqueue_get_sig(nni_msgqueue_t mq, nng_msg_t *msgp, int tmout, int *signal) +nni_msgqueue_get_sig(nni_msgqueue_t mq, nni_msg_t *msgp, int tmout, int *signal) { uint64_t expire, now; @@ -247,14 +247,14 @@ nni_msgqueue_get_sig(nni_msgqueue_t mq, nng_msg_t *msgp, int tmout, int *signal) } int -nni_msgqueue_get(nni_msgqueue_t mq, nng_msg_t *msgp, int tmout) +nni_msgqueue_get(nni_msgqueue_t mq, nni_msg_t *msgp, int tmout) { int nosig = 0; return (nni_msgqueue_get_sig(mq, msgp, tmout, &nosig)); } int -nni_msgqueue_put(nni_msgqueue_t mq, nng_msg_t msg, int tmout) +nni_msgqueue_put(nni_msgqueue_t mq, nni_msg_t msg, int tmout) { int nosig = 0; return (nni_msgqueue_put_sig(mq, msg, tmout, &nosig)); @@ -263,7 +263,7 @@ nni_msgqueue_put(nni_msgqueue_t mq, nng_msg_t msg, int tmout) void nni_msgqueue_close(nni_msgqueue_t mq) { - nng_msg_t msg; + nni_msg_t msg; nni_mutex_enter(mq->mq_lock); mq->mq_closed = 1; @@ -278,7 +278,7 @@ nni_msgqueue_close(nni_msgqueue_t mq) mq->mq_get = 0; } mq->mq_len--; - nng_msg_free(msg); + nni_msg_free(msg); } nni_mutex_exit(mq->mq_lock); } diff --git a/src/core/nng_impl.h b/src/core/nng_impl.h index 6890c7c8..4b62cfee 100644 --- a/src/core/nng_impl.h +++ b/src/core/nng_impl.h @@ -40,12 +40,14 @@ #include "core/defs.h" #include "core/list.h" +#include "core/message.h" #include "core/msgqueue.h" #include "core/panic.h" #include "core/pipe.h" #include "core/snprintf.h" #include "core/platform.h" #include "core/protocol.h" +#include "core/socket.h" #include "core/transport.h" #endif /* CORE_NNG_IMPL_H */ diff --git a/src/core/pipe.c b/src/core/pipe.c index 5e867406..a08aab8a 100644 --- a/src/core/pipe.c +++ b/src/core/pipe.c @@ -34,23 +34,24 @@ struct nng_pipe { struct nni_pipe_ops p_ops; void *p_tran; nni_list_node_t p_node; + nni_socket_t p_sock; }; /* nni_pipe_id returns the 32-bit pipe id, which can be used in backtraces. */ uint32_t -nni_pipe_id(nng_pipe_t p) +nni_pipe_id(nni_pipe_t p) { return (p->p_id); } int -nni_pipe_send(nng_pipe_t p, nng_msg_t msg) +nni_pipe_send(nni_pipe_t p, nng_msg_t msg) { return (p->p_ops.p_send(p->p_tran, msg)); } int -nni_pipe_recv(nng_pipe_t p, nng_msg_t *msgp) +nni_pipe_recv(nni_pipe_t p, nng_msg_t *msgp) { return (p->p_ops.p_recv(p->p_tran, msgp)); } @@ -61,21 +62,22 @@ nni_pipe_recv(nng_pipe_t p, nng_msg_t *msgp) * simply return NNG_ECLOSED. */ void -nni_pipe_close(nng_pipe_t p) +nni_pipe_close(nni_pipe_t p) { /* XXX: we need to unregister from the parent socket. */ /* XXX: also unregister from the protocol. */ - return (p->p_ops.p_close(p->p_tran)); + p->p_ops.p_close(p->p_tran); + // XXX: nni_sock_remove_pipe(sock, p); } uint16_t -nni_pipe_peer(nng_pipe_t p) +nni_pipe_peer(nni_pipe_t p) { return (p->p_ops.p_peer(p->p_tran)); } void -nni_pipe_destroy(nng_pipe_t p) +nni_pipe_destroy(nni_pipe_t p) { p->p_ops.p_destroy(p->p_tran); nni_free(p, sizeof (*p)); diff --git a/src/core/pipe.h b/src/core/pipe.h index 4dcfb223..fa3f2bfe 100644 --- a/src/core/pipe.h +++ b/src/core/pipe.h @@ -23,24 +23,20 @@ #ifndef CORE_PIPE_H #define CORE_PIPE_H -/* - * This file contains definitions for pipes. - */ - /* * Pipe operations that protocols use. */ -extern int nni_pipe_recv(nng_pipe_t, nng_msg_t *); -extern int nni_pipe_send(nng_pipe_t, nng_msg_t); -extern uint32_t nni_pipe_id(nng_pipe_t); -extern void nni_pipe_close(nng_pipe_t); +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); /* * Used only by the socket core - as we don't wish to expose the details * of the pipe structure outside of pipe.c. */ extern void nni_pipe_list_init(nni_list_t *); -extern int nni_pipe_create(nng_pipe_t *, struct nni_transport *); -extern void nni_pipe_destroy(nng_pipe_t); +extern int nni_pipe_create(nni_pipe_t *, struct nni_transport *); +extern void nni_pipe_destroy(nni_pipe_t); #endif /* CORE_PIPE_H */ \ No newline at end of file diff --git a/src/core/protocol.h b/src/core/protocol.h index d7396456..4005aa5b 100644 --- a/src/core/protocol.h +++ b/src/core/protocol.h @@ -52,7 +52,7 @@ struct nni_protocol { /* * Create protocol instance data, which will be stored on the socket. */ - int (*proto_create)(void **, nng_socket_t); + int (*proto_create)(void **, nni_socket_t); /* * Destroy the protocol instance. @@ -70,8 +70,8 @@ struct nni_protocol { * Add and remove pipes. These are called as connections are * created or destroyed. */ - int (*proto_add_pipe)(void *, nng_pipe_t); - int (*proto_remove_pipe)(void *, nng_pipe_t); + int (*proto_add_pipe)(void *, nni_pipe_t); + int (*proto_remove_pipe)(void *, nni_pipe_t); /* * Option manipulation. These may be NULL. @@ -86,14 +86,14 @@ struct nni_protocol { * the protocol should return NULL, otherwise the message * (possibly modified). */ - nng_msg_t (*proto_recv_filter)(void *, nng_msg_t); + nng_msg_t (*proto_recv_filter)(void *, nni_msg_t); /* * Send filter. This may be NULL, but if it isn't, then * messages here are filtered just after they come from the * application. */ - nng_msg_t (*proto_send_filter)(void *, nng_msg_t); + nng_msg_t (*proto_send_filter)(void *, nni_msg_t); }; /* @@ -106,20 +106,20 @@ struct nni_protocol { * recieve messages from this, and place them on the appropriate * pipe. */ -extern nni_msgqueue_t nni_socket_sendq(nng_socket_t); +extern nni_msgqueue_t nni_socket_sendq(nni_socket_t); /* * nni_socket_recvq obtains the upper readq. The protocol should * inject incoming messages from pipes to it. */ -extern nni_msgqueue_t nni_socket_recvq(nng_socket_t); +extern nni_msgqueue_t nni_socket_recvq(nni_socket_t); /* * 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(nng_socket_t, int); +extern void nni_socket_recv_err(nni_socket_t, int); /* * nni_socket_send_err sets an error code to be returned to clients @@ -127,15 +127,7 @@ extern void nni_socket_recv_err(nng_socket_t, int); * for their message to be accepted for send. Set it to 0 to resume * normal send operations. */ -extern void nni_socket_send_err(nng_socket_t, int); - -/* - * Pipe operations that protocols use. - */ -extern int nni_pipe_recv(nng_pipe_t, nng_msg_t *); -extern int nni_pipe_send(nng_pipe_t, nng_msg_t); -extern uint32_t nni_pipe_id(nng_pipe_t); -extern void nni_pipe_close(nng_pipe_t); +extern void nni_socket_send_err(nni_socket_t, int); /* * These functions are not used by protocols, but rather by the socket diff --git a/src/core/socket.c b/src/core/socket.c index d48f2b86..9f6943af 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -50,21 +50,21 @@ struct nng_socket { * the upper read and write queues. */ nni_msgqueue_t -nni_socket_sendq(nng_socket_t s) +nni_socket_sendq(nni_socket_t s) { return (s->s_uwq); } nni_msgqueue_t -nni_socket_recvq(nng_socket_t s) +nni_socket_recvq(nni_socket_t s) { return (s->s_urq); } int -nng_socket_create(nng_socket_t *sockp, uint16_t proto) +nni_socket_create(nni_socket_t *sockp, uint16_t proto) { - nng_socket_t sock; + nni_socket_t sock; struct nni_protocol *ops; int rv; @@ -77,7 +77,7 @@ nng_socket_create(nng_socket_t *sockp, uint16_t proto) sock->s_ops = *ops; nni_pipe_list_init(&sock->s_pipes); - //NNI_LIST_INIT(&sock->s_eps, nng_endpt_t, ep_node); + //NNI_LIST_INIT(&sock->s_eps, nni_endpt_t, ep_node); if ((rv = sock->s_ops.proto_create(&sock->s_data, sock)) != 0) { nni_free(sock, sizeof (*sock)); @@ -89,7 +89,7 @@ nng_socket_create(nng_socket_t *sockp, uint16_t proto) } int -nng_socket_close(nng_socket_t sock) +nni_socket_close(nni_socket_t sock) { nni_msgqueue_close(sock->s_urq); /* XXX: drain this? */ @@ -107,7 +107,7 @@ nng_socket_close(nng_socket_t sock) } int -nng_socket_sendmsg(nng_socket_t sock, nng_msg_t msg, int tmout) +nni_socket_sendmsg(nni_socket_t sock, nni_msg_t msg, int tmout) { int rv; int besteffort; @@ -128,7 +128,7 @@ nng_socket_sendmsg(nng_socket_t sock, nng_msg_t msg, int tmout) #if 0 if (s.ops.p_sendhook != NULL) { if ((rv = s.ops.p_sendhook(sock->s_proto, msg)) != 0) { - nng_msg_free(msg); + nni_msg_free(msg); return (0); } } @@ -144,14 +144,14 @@ nng_socket_sendmsg(nng_socket_t sock, nng_msg_t msg, int tmout) rv = nni_msgqueue_put(sock->s_uwq, msg, tmout); if (besteffort && (rv == NNG_EAGAIN)) { /* Pretend this worked... it didn't, but pretend. */ - nng_msg_free(msg); + nni_msg_free(msg); return (0); } return (rv); } uint16_t -nng_socket_protocol(nng_socket_t sock) +nni_socket_protocol(nni_socket_t sock) { return (sock->s_ops.proto_self); } diff --git a/src/core/socket.h b/src/core/socket.h new file mode 100644 index 00000000..30d863e2 --- /dev/null +++ b/src/core/socket.h @@ -0,0 +1,39 @@ +/* + * Copyright 2016 Garrett D'Amore + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef CORE_SOCKET_H +#define CORE_SOCKET_H + +/* + * Internally used socket API. Again, this stuff is not part of our public + * API. + */ + +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 int nni_socket_remove_pipe(nni_socket_t, nni_pipe_t); +extern uint16_t nni_socket_protocol(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 *); + +#endif /* CORE_SOCKET_H */ -- cgit v1.2.3-70-g09d2