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/CMakeLists.txt | 4 ++ 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 +++++++++++++++++ src/nng.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++ src/nng.h | 2 +- src/protocol/pair/pair.c | 26 ++++++------ 15 files changed, 286 insertions(+), 89 deletions(-) create mode 100644 src/core/message.h create mode 100644 src/core/socket.h create mode 100644 src/nng.c (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 96e83e28..4d28cb34 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,11 +24,14 @@ # set (NNG_SOURCES + nng.c nng.h + core/defs.h core/list.c core/list.h core/message.c + core/message.h core/msgqueue.c core/msgqueue.h core/nng_impl.h @@ -43,6 +46,7 @@ set (NNG_SOURCES core/snprintf.c core/snprintf.h core/socket.c + core/socket.h core/transport.c core/transport.h 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 */ diff --git a/src/nng.c b/src/nng.c new file mode 100644 index 00000000..123c69bd --- /dev/null +++ b/src/nng.c @@ -0,0 +1,108 @@ +/* + * 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. + */ + +#include "core/nng_impl.h" + +/* + * This file provides the "public" API. This is a thin wrapper around + * internal API functions. We use the public prefix instead of internal, + * to indicate that these interfaces are intended for applications to use + * directly. + * + * Anything not defined in this file, applications have no business using. + * Pretty much every function calls the nni_platform_init to check against + * fork related activity. + */ + +int +nng_socket_create(nng_socket_t *s, uint16_t proto) +{ + nni_platform_init(); + return (nni_socket_create(s, proto)); +} + +int +nng_socket_close(nng_socket_t s) +{ + nni_platform_init(); + return (nni_socket_close(s)); +} + +uint16_t +nng_socket_protocol(nng_socket_t s) +{ + nni_platform_init(); + return (nni_socket_protocol(s)); +} + +/* + * Misc. + */ + +const char * +nng_strerror(int num) +{ + switch (num) { + case 0: + return ("Hunky dory"); /* what did you expect? */ + case NNG_EINTR: + return ("Interrupted"); + case NNG_ENOMEM: + return ("Out of memory"); + case NNG_EINVAL: + return ("Invalid argument"); + case NNG_EBUSY: + return ("Resource busy"); + case NNG_ETIMEDOUT: + return ("Timed out"); + case NNG_ECONNREFUSED: + return ("Connection refused"); + case NNG_ECLOSED: + return ("Object closed"); + case NNG_EAGAIN: + return ("Try again"); + case NNG_ENOTSUP: + return ("Not supported"); + case NNG_EADDRINUSE: + return ("Address in use"); + default: + return ("Unknown error"); + } +} + +/* + * Message handling. + */ + +int +nng_msg_alloc(nng_msg_t *msgp, size_t size) +{ + nni_platform_init(); + return (nni_msg_alloc(msgp, size)); +} + +void +nng_msg_free(nng_msg_t msg) +{ + nni_platform_init(); + return (nni_msg_free(msg)); +} \ No newline at end of file diff --git a/src/nng.h b/src/nng.h index 1267d0a3..a9357f4a 100644 --- a/src/nng.h +++ b/src/nng.h @@ -88,7 +88,7 @@ uint16_t nng_socket_protocol(nng_socket_t); /* * nng_socket_setopt sets an option for a specific socket. */ -NNG_DECL int nng_socket_setopt(nng_socket_t, int, void *, size_t); +NNG_DECL int nng_socket_setopt(nng_socket_t, int, const void *, size_t); /* * nng_socket_getopt obtains the option for a socket. diff --git a/src/protocol/pair/pair.c b/src/protocol/pair/pair.c index 7313560e..4b8a180b 100644 --- a/src/protocol/pair/pair.c +++ b/src/protocol/pair/pair.c @@ -37,15 +37,15 @@ typedef struct pairpipe *pairpipe_t; * to create separate data structures for diferent pipe instances. */ struct pair { - nng_socket_t sock; + nni_socket_t sock; nni_mutex_t mx; - nng_pipe_t pipe; + nni_pipe_t pipe; nni_msgqueue_t uwq; nni_msgqueue_t urq; }; struct pairpipe { - nng_pipe_t pipe; + nni_pipe_t pipe; pair_t pair; int good; nni_thread_t sthr; @@ -57,7 +57,7 @@ static void pair_receiver(void *); static void pair_sender(void *); static int -pair_create(void **pairp, nng_socket_t sock) +pair_create(void **pairp, nni_socket_t sock) { pair_t pair; int rv; @@ -88,7 +88,7 @@ static void pair_shutdown(void *arg, uint64_t usec) { pair_t pair = arg; - nng_pipe_t pipe; + nni_pipe_t pipe; NNI_ARG_UNUSED(usec); @@ -106,7 +106,7 @@ pair_shutdown(void *arg, uint64_t usec) } static int -pair_add_pipe(void *arg, nng_pipe_t pipe) +pair_add_pipe(void *arg, nni_pipe_t pipe) { pair_t pair = arg; pairpipe_t pp; @@ -141,7 +141,7 @@ pair_add_pipe(void *arg, nng_pipe_t pipe) } static int -pair_remove_pipe(void *arg, nng_pipe_t pipe) +pair_remove_pipe(void *arg, nni_pipe_t pipe) { pairpipe_t pp = arg; pair_t pair = pp->pair; @@ -168,8 +168,8 @@ pair_sender(void *arg) pair_t pair = pp->pair; nni_msgqueue_t uwq = pair->uwq; nni_msgqueue_t urq = pair->urq; - nng_pipe_t pipe = pp->pipe; - nng_msg_t msg; + nni_pipe_t pipe = pp->pipe; + nni_msg_t msg; int rv; nni_mutex_enter(pair->mx); @@ -188,7 +188,7 @@ pair_sender(void *arg) } rv = nni_pipe_send(pipe, msg); if (rv != 0) { - nng_msg_free(msg); + nni_msg_free(msg); (void) nni_pipe_close(pipe); /* signal the other side */ nni_msgqueue_signal(urq, &pp->sigclose); @@ -204,8 +204,8 @@ pair_receiver(void *arg) pair_t pair = pp->pair; nni_msgqueue_t urq = pair->urq; nni_msgqueue_t uwq = pair->uwq; - nng_pipe_t pipe = pp->pipe; - nng_msg_t msg; + nni_pipe_t pipe = pp->pipe; + nni_msg_t msg; int rv; nni_mutex_enter(pair->mx); @@ -218,7 +218,7 @@ pair_receiver(void *arg) for (;;) { rv = nni_pipe_recv(pipe, &msg); if (rv != 0) { - nng_msg_free(msg); + nni_msg_free(msg); (void) nni_pipe_close(pipe); /* signal the other side */ nni_msgqueue_signal(uwq, &pp->sigclose); -- cgit v1.2.3-70-g09d2