aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/defs.h33
-rw-r--r--src/core/endpt.h45
-rw-r--r--src/core/init.c23
-rw-r--r--src/core/init.h23
-rw-r--r--src/core/list.c44
-rw-r--r--src/core/list.h33
-rw-r--r--src/core/message.c63
-rw-r--r--src/core/message.h23
-rw-r--r--src/core/msgqueue.c38
-rw-r--r--src/core/msgqueue.h25
-rw-r--r--src/core/nng_impl.h21
-rw-r--r--src/core/panic.c28
-rw-r--r--src/core/panic.h21
-rw-r--r--src/core/pipe.c36
-rw-r--r--src/core/pipe.h38
-rw-r--r--src/core/platform.c21
-rw-r--r--src/core/platform.h21
-rw-r--r--src/core/protocol.c28
-rw-r--r--src/core/protocol.h126
-rw-r--r--src/core/snprintf.c23
-rw-r--r--src/core/snprintf.h23
-rw-r--r--src/core/socket.c85
-rw-r--r--src/core/socket.h41
-rw-r--r--src/core/transport.c27
-rw-r--r--src/core/transport.h59
-rw-r--r--src/nng.c59
-rw-r--r--src/nng.h167
-rw-r--r--src/platform/posix/posix_alloc.c26
-rw-r--r--src/platform/posix/posix_clock.c44
-rw-r--r--src/platform/posix/posix_config.h35
-rw-r--r--src/platform/posix/posix_debug.c25
-rw-r--r--src/platform/posix/posix_impl.h23
-rw-r--r--src/platform/posix/posix_synch.c43
-rw-r--r--src/platform/posix/posix_thread.c39
-rw-r--r--src/platform/posix/posix_vsnprintf.c24
-rw-r--r--src/protocol/pair/pair.c182
-rw-r--r--src/transport/inproc/inproc.c86
37 files changed, 677 insertions, 1024 deletions
diff --git a/src/core/defs.h b/src/core/defs.h
index a1789a36..b862f3ab 100644
--- a/src/core/defs.h
+++ b/src/core/defs.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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
@@ -28,14 +15,14 @@
* there are things like __attribute__((unused)) which are arguably
* superior, support for such are not universal.
*/
-#define NNI_ARG_UNUSED(x) ((void)x);
+#define NNI_ARG_UNUSED(x) ((void) x);
/*
* 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;
+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 */
+#endif /* CORE_DEFS_H */
diff --git a/src/core/endpt.h b/src/core/endpt.h
index fff0f905..f96df047 100644
--- a/src/core/endpt.h
+++ b/src/core/endpt.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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
@@ -32,27 +19,27 @@
*/
struct nng_endpt {
- struct nni_endpt_ops ep_ops;
- void *ep_tran;
- nni_list_node_t ep_sock_node;
- nni_socket_t ep_sock;
- const char *ep_addr;
- nni_thread_t ep_dialer;
- nni_thread_t ep_listener;
- int ep_close;
- nni_mutex_t ep_mx;
- nni_cond_t ep_cv;
+ struct nni_endpt_ops ep_ops;
+ void *ep_tran;
+ nni_list_node_t ep_sock_node;
+ nni_socket_t ep_sock;
+ const char *ep_addr;
+ nni_thread_t ep_dialer;
+ nni_thread_t ep_listener;
+ int ep_close;
+ nni_mutex_t ep_mx;
+ nni_cond_t ep_cv;
};
/*
* This file contains definitions for endpoints.
*/
-int nni_endpt_create(nni_endpt_t *, nni_socket_t, const char *);
+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
+#endif /* CORE_ENDPT_H */
diff --git a/src/core/init.c b/src/core/init.c
index 4738a585..debfbbbe 100644
--- a/src/core/init.c
+++ b/src/core/init.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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"
@@ -31,12 +18,14 @@ init_helper(void)
return (0);
}
+
int
nni_init(void)
{
return (nni_plat_init(init_helper));
}
+
void
nni_fini(void)
{
diff --git a/src/core/init.h b/src/core/init.h
index 3a9221e4..3f36abe6 100644
--- a/src/core/init.h
+++ b/src/core/init.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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_INIT_H
@@ -38,4 +25,4 @@ extern int nni_init(void);
*/
extern void nni_fini(void);
-#endif /* CORE_INIT_H */ \ No newline at end of file
+#endif /* CORE_INIT_H */
diff --git a/src/core/list.c b/src/core/list.c
index d81c6379..eb3f73d2 100644
--- a/src/core/list.c
+++ b/src/core/list.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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 <stdlib.h>
@@ -30,10 +17,10 @@
* Using pointer arithmetic, we can operate as a list of "anything".
*/
-#define NODE(list, item) \
- (nni_list_node_t *)(void *)(((char *)item) + list->ll_offset)
-#define ITEM(list, node) \
- (void *)(((char *)node) - list->ll_offset)
+#define NODE(list, item) \
+ (nni_list_node_t *) (void *) (((char *) item) + list->ll_offset)
+#define ITEM(list, node) \
+ (void *) (((char *) node) - list->ll_offset)
void
nni_list_init_offset(nni_list_t *list, size_t offset)
@@ -43,26 +30,31 @@ nni_list_init_offset(nni_list_t *list, size_t offset)
list->ll_head.ln_prev = &list->ll_head;
}
+
void *
nni_list_first(nni_list_t *list)
{
nni_list_node_t *node = list->ll_head.ln_next;
+
if (node == &list->ll_head) {
return (NULL);
}
return (ITEM(list, node));
}
+
void *
nni_list_last(nni_list_t *list)
{
nni_list_node_t *node = list->ll_head.ln_prev;
+
if (node == &list->ll_head) {
return (NULL);
}
return (ITEM(list, node));
}
+
void
nni_list_append(nni_list_t *list, void *item)
{
@@ -73,6 +65,8 @@ nni_list_append(nni_list_t *list, void *item)
node->ln_next->ln_prev = node;
node->ln_prev->ln_next = node;
}
+
+
void
nni_list_prepend(nni_list_t *list, void *item)
{
@@ -84,6 +78,7 @@ nni_list_prepend(nni_list_t *list, void *item)
node->ln_prev->ln_next = node;
}
+
void *
nni_list_next(nni_list_t *list, void *item)
{
@@ -95,6 +90,7 @@ nni_list_next(nni_list_t *list, void *item)
return (ITEM(list, node));
}
+
void *
nni_list_prev(nni_list_t *list, void *item)
{
@@ -106,17 +102,21 @@ nni_list_prev(nni_list_t *list, void *item)
return (ITEM(list, node));
}
+
void
nni_list_remove(nni_list_t *list, void *item)
{
nni_list_node_t *node = NODE(list, item);
+
node->ln_prev->ln_next = node->ln_next;
node->ln_next->ln_prev = node->ln_prev;
}
+
void
nni_list_node_init(nni_list_t *list, void *item)
{
- nni_list_node_t *node = NODE(list, item);
+ nni_list_node_t *node = NODE(list, item);
+
node->ln_prev = node->ln_next = NULL;
}
diff --git a/src/core/list.h b/src/core/list.h
index f12087a2..65d6ae9e 100644
--- a/src/core/list.h
+++ b/src/core/list.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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_LIST_H
@@ -30,8 +17,8 @@
* directly, and let consumers directly inline structures.
*/
typedef struct nni_list_node {
- struct nni_list_node *ln_next;
- struct nni_list_node *ln_prev;
+ struct nni_list_node * ln_next;
+ struct nni_list_node * ln_prev;
} nni_list_node_t;
typedef struct nni_list {
@@ -40,8 +27,9 @@ typedef struct nni_list {
} nni_list_t;
extern void nni_list_init_offset(nni_list_t *list, size_t offset);
-#define NNI_LIST_INIT(list, type, field) \
- nni_list_init_offset(list, offsetof (type, field))
+
+#define NNI_LIST_INIT(list, type, field) \
+ nni_list_init_offset(list, offsetof(type, field))
extern void *nni_list_first(nni_list_t *);
extern void *nni_list_last(nni_list_t *);
extern void nni_list_append(nni_list_t *, void *);
@@ -50,7 +38,8 @@ extern void *nni_list_next(nni_list_t *, void *);
extern void *nni_list_prev(nni_list_t *, void *);
extern void nni_list_remove(nni_list_t *, void *);
extern void nni_list_node_init(nni_list_t *, void *);
+
#define NNI_LIST_FOREACH(l, it) \
for (it = nni_list_first(l); it != NULL; it = nni_list_next(l, it))
-#endif /* CORE_LIST_H */
+#endif /* CORE_LIST_H */
diff --git a/src/core/message.c b/src/core/message.c
index b0c83da9..4ba30ed6 100644
--- a/src/core/message.c
+++ b/src/core/message.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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 <stdlib.h>
@@ -31,18 +18,18 @@
/* Message chunk, internal to the message implementation. */
typedef struct {
- size_t ch_cap; /* allocated size */
- size_t ch_len; /* length in use */
- uint8_t *ch_buf; /* underlying buffer */
- uint8_t *ch_ptr; /* pointer to actual data */
+ size_t ch_cap; /* allocated size */
+ size_t ch_len; /* length in use */
+ uint8_t * ch_buf; /* underlying buffer */
+ uint8_t * ch_ptr; /* pointer to actual data */
} chunk_t;
/* Underlying message chunk. */
struct nng_msg {
chunk_t m_header;
chunk_t m_body;
- int64_t m_expire; /* Unix usec */
- nni_pipe_t m_pipe; /* Pipe message was received on */
+ int64_t m_expire; /* Unix usec */
+ nni_pipe_t m_pipe; /* Pipe message was received on */
};
/*
@@ -76,8 +63,7 @@ chunk_grow(chunk_t *ch, size_t newsz, size_t headwanted)
if ((ch->ch_ptr >= ch->ch_buf) &&
(ch->ch_ptr < (ch->ch_buf + ch->ch_cap))) {
-
- headroom = (size_t)(ch->ch_ptr - ch->ch_buf);
+ headroom = (size_t) (ch->ch_ptr - ch->ch_buf);
if (((newsz + headwanted) < ch->ch_cap) &&
(headwanted <= headroom)) {
/* We have enough space at the ends already. */
@@ -110,7 +96,6 @@ chunk_grow(chunk_t *ch, size_t newsz, size_t headwanted)
ch->ch_ptr = ch->ch_buf + headwanted;
}
return (0);
-
} else if ((newbuf = nni_alloc(newsz)) == NULL) {
return (NNG_ENOMEM);
}
@@ -124,6 +109,7 @@ chunk_grow(chunk_t *ch, size_t newsz, size_t headwanted)
return (0);
}
+
static void
chunk_free(chunk_t *ch)
{
@@ -136,6 +122,7 @@ chunk_free(chunk_t *ch)
ch->ch_cap = 0;
}
+
/* chunk_trunc truncates the number of bytes from the end of the chunk. */
static int
chunk_trunc(chunk_t *ch, size_t len)
@@ -147,6 +134,7 @@ chunk_trunc(chunk_t *ch, size_t len)
return (0);
}
+
/* chunk_trim removes the number of bytes from the beginning of the chunk. */
static int
chunk_trim(chunk_t *ch, size_t len)
@@ -159,6 +147,7 @@ chunk_trim(chunk_t *ch, size_t len)
return (0);
}
+
/*
* chunk_append appends the data to the chunk, growing the size as necessary.
* If the data pointer is NULL, then the chunk data region is allocated, but
@@ -168,6 +157,7 @@ static int
chunk_append(chunk_t *ch, const void *data, size_t len)
{
int rv;
+
if (len == 0) {
return (0);
}
@@ -184,6 +174,7 @@ chunk_append(chunk_t *ch, const void *data, size_t len)
return (0);
}
+
/*
* chunk_prepend prepends data to the chunk, as efficiently as possible.
* If the data pointer is NULL, then no data is actually copied, but the
@@ -200,18 +191,15 @@ chunk_prepend(chunk_t *ch, const void *data, size_t len)
if ((ch->ch_ptr >= ch->ch_buf) &&
(ch->ch_ptr < (ch->ch_buf + ch->ch_cap)) &&
- (len <= (size_t)(ch->ch_ptr - ch->ch_buf))) {
+ (len <= (size_t) (ch->ch_ptr - ch->ch_buf))) {
/* There is already enough room at the beginning. */
ch->ch_ptr -= len;
-
} else if ((ch->ch_len + len) <= ch->ch_cap) {
/* We had enough capacity, just shuffle data down. */
memmove(ch->ch_ptr + len, ch->ch_ptr, ch->ch_len);
-
} else if ((rv = chunk_grow(ch, 0, len)) == 0) {
/* We grew the chunk, so adjust. */
ch->ch_ptr -= len;
-
} else {
/* Couldn't grow the chunk either. Error. */
return (rv);
@@ -225,6 +213,7 @@ chunk_prepend(chunk_t *ch, const void *data, size_t len)
return (0);
}
+
int
nni_msg_alloc(nni_msg_t *mp, size_t sz)
{
@@ -269,6 +258,7 @@ nni_msg_alloc(nni_msg_t *mp, size_t sz)
return (0);
}
+
void
nni_msg_free(nni_msg_t m)
{
@@ -277,10 +267,12 @@ nni_msg_free(nni_msg_t m)
nni_free(m, sizeof (*m));
}
+
int
nni_msg_realloc(nni_msg_t m, size_t sz)
{
int rv = 0;
+
if (m->m_body.ch_len < sz) {
rv = chunk_append(&m->m_body, NULL, sz - m->m_body.ch_len);
if (rv != 0) {
@@ -293,6 +285,7 @@ nni_msg_realloc(nni_msg_t m, size_t sz)
return (0);
}
+
void *
nni_msg_header(nni_msg_t m, size_t *szp)
{
@@ -302,6 +295,7 @@ nni_msg_header(nni_msg_t m, size_t *szp)
return (m->m_header.ch_ptr);
}
+
void *
nni_msg_body(nni_msg_t m, size_t *szp)
{
@@ -311,54 +305,63 @@ nni_msg_body(nni_msg_t m, size_t *szp)
return (m->m_body.ch_ptr);
}
+
int
nni_msg_append(nni_msg_t m, const void *data, size_t len)
{
return (chunk_append(&m->m_body, data, len));
}
+
int
nni_msg_prepend(nni_msg_t m, const void *data, size_t len)
{
return (chunk_prepend(&m->m_body, data, len));
}
+
int
nni_msg_trim(nni_msg_t m, size_t len)
{
return (chunk_trim(&m->m_body, len));
}
+
int
nni_msg_trunc(nni_msg_t m, size_t len)
{
return (chunk_trunc(&m->m_body, len));
}
+
int
nni_msg_append_header(nni_msg_t m, const void *data, size_t len)
{
return (chunk_append(&m->m_header, data, len));
}
+
int
nni_msg_prepend_header(nni_msg_t m, const void *data, size_t len)
{
return (chunk_prepend(&m->m_header, data, len));
}
+
int
nni_msg_trim_header(nni_msg_t m, size_t len)
{
return (chunk_trim(&m->m_header, len));
}
+
int
nni_msg_trunc_header(nni_msg_t m, size_t len)
{
return (chunk_trunc(&m->m_header, len));
}
+
int
nni_msg_pipe(nni_msg_t m, nni_pipe_t *pp)
{
diff --git a/src/core/message.h b/src/core/message.h
index 57184e56..7b17a007 100644
--- a/src/core/message.h
+++ b/src/core/message.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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_MESSAGE_H
@@ -43,4 +30,4 @@ 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 */
+#endif /* CORE_SOCKET_H */
diff --git a/src/core/msgqueue.c b/src/core/msgqueue.c
index 372d2c08..6b208e70 100644
--- a/src/core/msgqueue.c
+++ b/src/core/msgqueue.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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 "nng_impl.h"
@@ -38,7 +25,7 @@ struct nni_msgqueue {
int mq_get;
int mq_put;
int mq_closed;
- nng_msg_t *mq_msgs;
+ nng_msg_t * mq_msgs;
};
int
@@ -84,6 +71,7 @@ nni_msgqueue_create(nni_msgqueue_t *mqp, int cap)
return (0);
}
+
void
nni_msgqueue_destroy(nni_msgqueue_t mq)
{
@@ -108,6 +96,7 @@ nni_msgqueue_destroy(nni_msgqueue_t mq)
nni_free(mq, sizeof (*mq));
}
+
/*
* nni_msgqueue_signal raises a signal on the signal object. This allows a
* waiter to be signaled, so that it can be woken e.g. due to a pipe closing.
@@ -118,6 +107,7 @@ nni_msgqueue_signal(nni_msgqueue_t mq, int *signal)
{
nni_mutex_enter(mq->mq_lock);
*signal = 1;
+
/*
* We have to wake everyone.
*/
@@ -126,6 +116,7 @@ nni_msgqueue_signal(nni_msgqueue_t mq, int *signal)
nni_mutex_exit(mq->mq_lock);
}
+
int
nni_msgqueue_put_sig(nni_msgqueue_t mq, nni_msg_t msg, int tmout, int *signal)
{
@@ -142,7 +133,7 @@ nni_msgqueue_put_sig(nni_msgqueue_t mq, nni_msg_t msg, int tmout, int *signal)
nni_mutex_exit(mq->mq_lock);
return (NNG_EAGAIN);
}
-
+
if (tmout < 0) {
(void) nni_cond_wait(mq->mq_writeable);
continue;
@@ -185,6 +176,7 @@ nni_msgqueue_put_sig(nni_msgqueue_t mq, nni_msg_t msg, int tmout, int *signal)
return (0);
}
+
int
nni_msgqueue_get_sig(nni_msgqueue_t mq, nni_msg_t *msgp, int tmout, int *signal)
{
@@ -201,7 +193,7 @@ nni_msgqueue_get_sig(nni_msgqueue_t mq, nni_msg_t *msgp, int tmout, int *signal)
nni_mutex_exit(mq->mq_lock);
return (NNG_EAGAIN);
}
-
+
if (tmout < 0) {
(void) nni_cond_wait(mq->mq_readable);
continue;
@@ -243,23 +235,27 @@ nni_msgqueue_get_sig(nni_msgqueue_t mq, nni_msg_t *msgp, int tmout, int *signal)
}
nni_mutex_exit(mq->mq_lock);
return (0);
-
}
+
int
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, nni_msg_t msg, int tmout)
{
int nosig = 0;
+
return (nni_msgqueue_put_sig(mq, msg, tmout, &nosig));
}
+
void
nni_msgqueue_close(nni_msgqueue_t mq)
{
diff --git a/src/core/msgqueue.h b/src/core/msgqueue.h
index 85b22ece..dbf21d11 100644
--- a/src/core/msgqueue.h
+++ b/src/core/msgqueue.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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_MSGQUEUE_H
@@ -29,7 +16,7 @@
* Message queues. Message queues work in some ways like Go channels;
* they are a thread-safe way to pass messages between subsystems.
*/
-typedef struct nni_msgqueue *nni_msgqueue_t;
+typedef struct nni_msgqueue * nni_msgqueue_t;
/*
* nni_msgqueue_create creates a message queue with the given capacity,
@@ -84,4 +71,4 @@ extern void nni_msgqueue_signal(nni_msgqueue_t, int *);
*/
extern void nni_msgqueue_close(nni_msgqueue_t);
-#endif /* CORE_MSQUEUE_H */
+#endif /* CORE_MSQUEUE_H */
diff --git a/src/core/nng_impl.h b/src/core/nng_impl.h
index 82d39419..57aa520f 100644
--- a/src/core/nng_impl.h
+++ b/src/core/nng_impl.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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_NNG_IMPL_H
diff --git a/src/core/panic.c b/src/core/panic.c
index 43c25beb..822c0904 100644
--- a/src/core/panic.c
+++ b/src/core/panic.c
@@ -1,30 +1,17 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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 <stdlib.h>
#include <string.h>
#include <stdarg.h>
-#ifdef NNG_HAVE_BACKTRACE
+#ifdef NNG_HAVE_BACKTRACE
#include <execinfo.h>
#endif
@@ -33,7 +20,6 @@
/*
* Panic handling.
*/
-
static void
show_backtrace(void)
{
@@ -56,6 +42,7 @@ show_backtrace(void)
#endif
}
+
/*
* nni_panic shows a panic message, a possible stack bracktrace, then aborts
* the process/program. This should only be called when a condition arises
@@ -68,7 +55,7 @@ nni_panic(const char *fmt, ...)
{
char buf[128];
char fbuf[128];
- va_list va;
+ va_list va;
va_start(va, fmt);
(void) nni_snprintf(fbuf, sizeof (buf), "panic: %s", fmt);
@@ -83,6 +70,7 @@ nni_panic(const char *fmt, ...)
nni_plat_abort();
}
+
void
nni_println(const char *msg)
{
diff --git a/src/core/panic.h b/src/core/panic.h
index 2dc65f8c..e77117ee 100644
--- a/src/core/panic.h
+++ b/src/core/panic.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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_PANIC_H
diff --git a/src/core/pipe.c b/src/core/pipe.c
index 1895b74b..a617cf85 100644
--- a/src/core/pipe.c
+++ b/src/core/pipe.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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"
@@ -33,21 +20,24 @@
uint32_t
nni_pipe_id(nni_pipe_t p)
{
- return (p->p_id);
+ return (p->p_id);
}
+
int
nni_pipe_send(nni_pipe_t p, nng_msg_t msg)
{
- return (p->p_ops.p_send(p->p_tran, msg));
+ return (p->p_ops.p_send(p->p_tran, msg));
}
+
int
nni_pipe_recv(nni_pipe_t p, nng_msg_t *msgp)
{
- return (p->p_ops.p_recv(p->p_tran, msgp));
+ return (p->p_ops.p_recv(p->p_tran, msgp));
}
+
/*
* nni_pipe_close closes the underlying connection. It is expected that
* subsequent attempts receive or send (including any waiting receive) will
@@ -56,15 +46,17 @@ nni_pipe_recv(nni_pipe_t p, nng_msg_t *msgp)
void
nni_pipe_close(nni_pipe_t p)
{
- p->p_ops.p_close(p->p_tran);
+ p->p_ops.p_close(p->p_tran);
}
+
uint16_t
nni_pipe_peer(nni_pipe_t p)
{
- return (p->p_ops.p_peer(p->p_tran));
+ return (p->p_ops.p_peer(p->p_tran));
}
+
void
nni_pipe_destroy(nni_pipe_t p)
{
diff --git a/src/core/pipe.h b/src/core/pipe.h
index 0cedf5e8..0708fdcc 100644
--- a/src/core/pipe.h
+++ b/src/core/pipe.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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_PIPE_H
@@ -32,13 +19,13 @@
#include "core/transport.h"
struct nng_pipe {
- uint32_t p_id;
- struct nni_pipe_ops p_ops;
- void *p_tran;
- nni_list_node_t p_sock_node;
- nni_socket_t p_sock;
- nni_list_node_t p_ep_node;
- nni_endpt_t p_ep;
+ uint32_t p_id;
+ struct nni_pipe_ops p_ops;
+ void * p_tran;
+ nni_list_node_t p_sock_node;
+ nni_socket_t p_sock;
+ nni_list_node_t p_ep_node;
+ nni_endpt_t p_ep;
};
@@ -55,6 +42,7 @@ extern void nni_pipe_close(nni_pipe_t);
* of the pipe structure outside of pipe.c.
*/
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
+#endif /* CORE_PIPE_H */
diff --git a/src/core/platform.c b/src/core/platform.c
index dbdf3a7c..755dfe5e 100644
--- a/src/core/platform.c
+++ b/src/core/platform.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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.
*/
/*
diff --git a/src/core/platform.h b/src/core/platform.h
index 230055c3..f87042da 100644
--- a/src/core/platform.h
+++ b/src/core/platform.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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_PLATFORM_H
diff --git a/src/core/protocol.c b/src/core/protocol.c
index 56c8ecb8..113746b1 100644
--- a/src/core/protocol.c
+++ b/src/core/protocol.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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 <string.h>
@@ -33,7 +20,7 @@
* change, as adding new protocols is not something intended to be done
* outside of the core.
*/
-extern struct nni_protocol nni_pair_protocol;
+extern struct nni_protocol nni_pair_protocol;
static struct nni_protocol *protocols[] = {
&nni_pair_protocol,
@@ -45,6 +32,7 @@ nni_protocol_find(uint16_t num)
{
int i;
struct nni_protocol *p;
+
for (i = 0; (p = protocols[i]) != NULL; i++) {
if (p->proto_self == num) {
break;
@@ -53,6 +41,7 @@ nni_protocol_find(uint16_t num)
return (p);
}
+
const char *
nni_protocol_name(uint16_t num)
{
@@ -64,6 +53,7 @@ nni_protocol_name(uint16_t num)
return (p->proto_name);
}
+
uint16_t
nni_protocol_number(const char *name)
{
@@ -76,4 +66,4 @@ nni_protocol_number(const char *name)
}
}
return (NNG_PROTO_NONE);
-} \ No newline at end of file
+}
diff --git a/src/core/protocol.h b/src/core/protocol.h
index 4005aa5b..f524eb46 100644
--- a/src/core/protocol.h
+++ b/src/core/protocol.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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_PROTOCOL_H
@@ -41,59 +28,58 @@
*/
struct nni_protocol {
-
- /*
- * Protocol information.
- */
- uint16_t proto_self; /* our 16-bit protocol ID */
- uint16_t proto_peer; /* who we peer with (protocol ID) */
- const char *proto_name; /* string version of our name */
-
- /*
- * Create protocol instance data, which will be stored on the socket.
- */
- int (*proto_create)(void **, nni_socket_t);
-
- /*
- * Destroy the protocol instance.
- */
- void (*proto_destroy)(void *);
-
- /*
- * Shutdown the protocol instance, including giving time to
- * drain any outbound frames (linger). The protocol is not
- * required to honor the linger.
- */
- void (*proto_shutdown)(void *, uint64_t);
-
- /*
- * Add and remove pipes. These are called as connections are
- * created or destroyed.
- */
- int (*proto_add_pipe)(void *, nni_pipe_t);
- int (*proto_remove_pipe)(void *, nni_pipe_t);
-
- /*
- * Option manipulation. These may be NULL.
- */
- int (*proto_setopt)(void *, int, const void *, size_t);
- int (*proto_getopt)(void *, int, void *, size_t *);
-
- /*
- * Receive filter. This may be NULL, but if it isn't, then
- * messages coming into the system are routed here just before
- * being delivered to the application. To drop the message,
- * the protocol should return NULL, otherwise the message
- * (possibly modified).
- */
- 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 *, nni_msg_t);
+ /*
+ * Protocol information.
+ */
+ uint16_t proto_self; /* our 16-bit protocol ID */
+ uint16_t proto_peer; /* who we peer with (protocol ID) */
+ const char * proto_name; /* string version of our name */
+
+ /*
+ * Create protocol instance data, which will be stored on the socket.
+ */
+ int (*proto_create)(void **, nni_socket_t);
+
+ /*
+ * Destroy the protocol instance.
+ */
+ void (*proto_destroy)(void *);
+
+ /*
+ * Shutdown the protocol instance, including giving time to
+ * drain any outbound frames (linger). The protocol is not
+ * required to honor the linger.
+ */
+ void (*proto_shutdown)(void *, uint64_t);
+
+ /*
+ * Add and remove pipes. These are called as connections are
+ * created or destroyed.
+ */
+ int (*proto_add_pipe)(void *, nni_pipe_t);
+ int (*proto_remove_pipe)(void *, nni_pipe_t);
+
+ /*
+ * Option manipulation. These may be NULL.
+ */
+ int (*proto_setopt)(void *, int, const void *, size_t);
+ int (*proto_getopt)(void *, int, void *, size_t *);
+
+ /*
+ * Receive filter. This may be NULL, but if it isn't, then
+ * messages coming into the system are routed here just before
+ * being delivered to the application. To drop the message,
+ * the protocol should return NULL, otherwise the message
+ * (possibly modified).
+ */
+ 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 *, nni_msg_t);
};
/*
diff --git a/src/core/snprintf.c b/src/core/snprintf.c
index 004916a2..be002e57 100644
--- a/src/core/snprintf.c
+++ b/src/core/snprintf.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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 <stdarg.h>
@@ -30,11 +17,13 @@ void
nni_snprintf(char *dst, size_t sz, const char *fmt, ...)
{
va_list va;
+
va_start(va, fmt);
nni_vsnprintf(dst, sz, fmt, va);
va_end(va);
}
+
void
nni_vsnprintf(char *dst, size_t sz, const char *fmt, va_list va)
{
diff --git a/src/core/snprintf.h b/src/core/snprintf.h
index 12d7f207..f25bc297 100644
--- a/src/core/snprintf.h
+++ b/src/core/snprintf.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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_SNPRINTF_H
@@ -33,4 +20,4 @@
extern void nni_snprintf(char *, size_t, const char *, ...);
extern void nni_vsnprintf(char *, size_t, const char *, va_list);
-#endif /* CORE_SNPRINTF_H */
+#endif /* CORE_SNPRINTF_H */
diff --git a/src/core/socket.c b/src/core/socket.c
index bc18b4a3..c7de05fa 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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"
@@ -36,39 +23,41 @@ nni_socket_sendq(nni_socket_t s)
return (s->s_uwq);
}
+
nni_msgqueue_t
nni_socket_recvq(nni_socket_t s)
{
return (s->s_urq);
}
+
int
nni_socket_create(nni_socket_t *sockp, uint16_t proto)
{
- nni_socket_t sock;
- struct nni_protocol *ops;
- int rv;
-
- if ((ops = nni_protocol_find(proto)) == NULL) {
- return (NNG_ENOTSUP);
- }
- if ((sock = nni_alloc(sizeof (*sock))) == NULL) {
- return (NNG_ENOMEM);
- }
- sock->s_ops = *ops;
-
- NNI_LIST_INIT(&sock->s_pipes, struct nng_pipe, p_sock_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));
- return (rv);
-
- }
- *sockp = sock;
+ nni_socket_t sock;
+ struct nni_protocol *ops;
+ int rv;
+
+ if ((ops = nni_protocol_find(proto)) == NULL) {
+ return (NNG_ENOTSUP);
+ }
+ if ((sock = nni_alloc(sizeof (*sock))) == NULL) {
+ return (NNG_ENOMEM);
+ }
+ sock->s_ops = *ops;
+
+ NNI_LIST_INIT(&sock->s_pipes, struct nng_pipe, p_sock_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));
+ return (rv);
+ }
+ *sockp = sock;
return (0);
}
+
int
nni_socket_close(nni_socket_t sock)
{
@@ -80,16 +69,16 @@ nni_socket_close(nni_socket_t sock)
nni_msgqueue_close(sock->s_uwq);
nni_mutex_enter(sock->s_mx);
- NNI_LIST_FOREACH(&sock->s_eps, ep) {
- #if 0
+ NNI_LIST_FOREACH (&sock->s_eps, ep) {
+#if 0
nni_ep_stop(ep);
// OR....
nni_mutex_enter(ep->ep_mx);
ep->ep_stop = 1;
nni_cond_broadcast(ep->ep_cond);
nni_mutex_exit(ep->ep_mx);
- #endif
- break; /* REMOVE ME */
+#endif
+ break; /* REMOVE ME */
}
nni_mutex_exit(sock->s_mx);
/* XXX: close endpoints - no new pipes made... */
@@ -119,6 +108,7 @@ nni_socket_close(nni_socket_t sock)
return (0);
}
+
int
nni_socket_sendmsg(nni_socket_t sock, nni_msg_t msg, int tmout)
{
@@ -147,8 +137,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;
}
@@ -161,12 +151,14 @@ nni_socket_sendmsg(nni_socket_t sock, nni_msg_t msg, int tmout)
return (rv);
}
+
uint16_t
nni_socket_protocol(nni_socket_t sock)
{
- return (sock->s_ops.proto_self);
+ return (sock->s_ops.proto_self);
}
+
void
nni_socket_remove_pipe(nni_socket_t sock, nni_pipe_t pipe)
{
@@ -174,6 +166,7 @@ nni_socket_remove_pipe(nni_socket_t sock, nni_pipe_t pipe)
if (pipe->p_sock != sock) {
nni_mutex_exit(sock->s_mx);
}
+
/*
* Remove the pipe from the protocol. Protocols may
* keep lists of pipes for managing their topologies.
@@ -191,10 +184,12 @@ nni_socket_remove_pipe(nni_socket_t sock, nni_pipe_t pipe)
nni_mutex_exit(sock->s_mx);
}
+
int
nni_socket_add_pipe(nni_socket_t sock, nni_pipe_t pipe)
{
int rv;
+
nni_mutex_enter(sock->s_mx);
if ((rv = sock->s_ops.proto_add_pipe(sock->s_data, pipe)) != 0) {
nni_mutex_exit(sock->s_mx);
diff --git a/src/core/socket.h b/src/core/socket.h
index cfc42806..da531836 100644
--- a/src/core/socket.h
+++ b/src/core/socket.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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
@@ -30,22 +17,22 @@
*/
struct nng_socket {
- nni_mutex_t s_mx;
+ nni_mutex_t s_mx;
- nni_msgqueue_t s_uwq; /* Upper write queue. */
- nni_msgqueue_t s_urq; /* Upper read queue. */
+ nni_msgqueue_t s_uwq; /* Upper write queue. */
+ nni_msgqueue_t s_urq; /* Upper read queue. */
- struct nni_protocol s_ops;
+ struct nni_protocol s_ops;
- void *s_data; /* Protocol private. */
+ void * s_data; /* Protocol private. */
/* options */
- nni_list_t s_eps;
- nni_list_t s_pipes;
+ nni_list_t s_eps;
+ nni_list_t s_pipes;
- int s_besteffort; /* Best effort mode delivery. */
- int s_senderr; /* Protocol state machine use. */
+ int s_besteffort; /* Best effort mode delivery. */
+ int s_senderr; /* Protocol state machine use. */
};
/*
@@ -61,4 +48,4 @@ 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 */
+#endif /* CORE_SOCKET_H */
diff --git a/src/core/transport.c b/src/core/transport.c
index 97d51e23..61ec5033 100644
--- a/src/core/transport.c
+++ b/src/core/transport.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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 <string.h>
@@ -28,7 +15,7 @@
* For now the list of transports is hard-wired. Adding new transports
* to the system dynamically is something that might be considered later.
*/
-extern struct nni_transport nni_inproc_transport;
+extern struct nni_transport nni_inproc_transport;
static struct nni_transport *transports[] = {
&nni_inproc_transport,
@@ -47,7 +34,7 @@ nni_transport_find(const char *addr)
if ((end = strstr(addr, "://")) == NULL) {
return (NULL);
}
- len = (int)(end - addr);
+ len = (int) (end - addr);
for (i = 0; (ops = transports[i]) != NULL; i++) {
if (strncmp(addr, ops->tran_scheme, len) == 0) {
return (ops);
@@ -56,6 +43,7 @@ nni_transport_find(const char *addr)
return (NULL);
}
+
/*
* nni_transport_init initializes the entire transport subsystem, including
* each individual transport.
@@ -71,6 +59,7 @@ nni_transport_init(void)
}
}
+
void
nni_transport_fini(void)
{
diff --git a/src/core/transport.h b/src/core/transport.h
index 4edfecf5..370e87f5 100644
--- a/src/core/transport.h
+++ b/src/core/transport.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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_TRANSPORT_H
@@ -32,23 +19,23 @@ struct nni_transport {
/*
* tran_scheme is the transport scheme, such as "tcp" or "inproc".
*/
- const char *tran_scheme;
+ const char * tran_scheme;
/*
* tran_ep_ops links our endpoint operations.
*/
- const struct nni_endpt_ops *tran_ep_ops;
+ const struct nni_endpt_ops * tran_ep_ops;
/*
* tran_pipe_ops links our pipe operations.
*/
- const struct nni_pipe_ops *tran_pipe_ops;
+ const struct nni_pipe_ops * tran_pipe_ops;
/*
* tran_init, if not NULL, is called once during library
* initialization.
*/
- int (*tran_init)(void);
+ int (*tran_init)(void);
/*
* tran_fini, if not NULL, is called during library deinitialization.
@@ -61,7 +48,7 @@ struct nni_transport {
* threading routines. Mutexes and condition variables may be
* safely destroyed.
*/
- void (*tran_fini)(void);
+ void (*tran_fini)(void);
};
/*
@@ -75,13 +62,13 @@ struct nni_endpt_ops {
* ep_create creates a vanilla endpoint. The value created is
* used for the first argument for all other endpoint functions.
*/
- int (*ep_create)(void **, const char *, uint16_t);
+ int (*ep_create)(void **, const char *, uint16_t);
/*
* ep_destroy frees the resources associated with the endpoint.
* The endpoint will already have been closed.
*/
- void (*ep_destroy)(void *);
+ void (*ep_destroy)(void *);
/*
* ep_dial starts dialing, and creates a new pipe,
@@ -89,7 +76,7 @@ struct nni_endpt_ops {
* NNG_EACCESS, NNG_ECONNREFUSED, NNG_EBADADDR, NNG_ECONNFAILED,
* NNG_ETIMEDOUT, and NNG_EPROTO.
*/
- int (*ep_dial)(void *, void **);
+ int (*ep_dial)(void *, void **);
/*
* ep_listen just does the bind() and listen() work,
@@ -98,25 +85,25 @@ struct nni_endpt_ops {
* taken. It can also return NNG_EBADADDR for an unsuitable
* address, or NNG_EACCESS for permission problems.
*/
- int (*ep_listen)(void *);
+ int (*ep_listen)(void *);
/*
* ep_accept accepts an inbound connection, and creates
* a transport pipe, which is returned in the final argument.
*/
- int (*ep_accept)(void *, void **);
+ int (*ep_accept)(void *, void **);
/*
* ep_close stops the endpoint from operating altogether. It does
* not affect pipes that have already been created.
*/
- void (*ep_close)(void *);
+ void (*ep_close)(void *);
/* ep_setopt sets an endpoint (transport-specific) option */
- int (*ep_setopt)(void *, int, const void *, size_t);
+ int (*ep_setopt)(void *, int, const void *, size_t);
/* ep_getopt gets an endpoint (transport-specific) option */
- int (*ep_getopt)(void *, int, void *, size_t *);
+ int (*ep_getopt)(void *, int, void *, size_t *);
};
/*
@@ -132,7 +119,7 @@ struct nni_pipe_ops {
* this call returns, the system will not make further calls on the same
* pipe.
*/
- void (*p_destroy)(void *);
+ void (*p_destroy)(void *);
/*
* p_send sends the message. If the message cannot be received, then
@@ -142,7 +129,7 @@ struct nni_pipe_ops {
* responsibility to free the message (nng_msg_free()) when it is
* finished with it.
*/
- int (*p_send)(void *, nng_msg_t);
+ int (*p_send)(void *, nng_msg_t);
/*
* p_recv recvs the message. This is a blocking operation, and a read
@@ -152,25 +139,25 @@ struct nni_pipe_ops {
* a result of a remote peer closing the connection, or a synchronous
* call to p_close.
*/
- int (*p_recv)(void *, nng_msg_t *);
+ int (*p_recv)(void *, nng_msg_t *);
/*
* p_close closes the pipe. Further recv or send operations should
* return back NNG_ECLOSED.
*/
- void (*p_close)(void *);
+ void (*p_close)(void *);
/*
* p_peer returns the peer protocol. This may arrive in whatever
* transport specific manner is appropriate.
*/
- uint16_t (*p_peer)(void *);
+ uint16_t (*p_peer)(void *);
/*
* p_getopt gets an pipe (transport-specific) property. These values
* may not be changed once the pipe is created.
*/
- int (*p_getopt)(void *, int, void *, size_t *);
+ int (*p_getopt)(void *, int, void *, size_t *);
};
/*
diff --git a/src/nng.c b/src/nng.c
index 9b10c3b1..a2398a9d 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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"
@@ -32,27 +19,30 @@
* 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)
{
int rv;
+
if ((rv = nni_init()) != 0) {
return (rv);
}
return (nni_socket_create(s, proto));
}
+
int
nng_socket_close(nng_socket_t s)
{
int rv;
+
if ((rv = nni_init()) != 0) {
return (rv);
}
return (nni_socket_close(s));
}
+
uint16_t
nng_socket_protocol(nng_socket_t s)
{
@@ -60,59 +50,72 @@ nng_socket_protocol(nng_socket_t s)
return (nni_socket_protocol(s));
}
+
/*
* Misc.
*/
-
const char *
nng_strerror(int num)
{
nni_init();
switch (num) {
case 0:
- return ("Hunky dory"); /* what did you expect? */
- case NNG_EINTR:
- return ("Interrupted");
+ 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)
{
int rv;
+
if ((rv = nni_init()) != 0) {
return (rv);
}
- return (nni_msg_alloc(msgp, size));
+ return (nni_msg_alloc(msgp, size));
}
+
void
nng_msg_free(nng_msg_t msg)
{
- nni_init();
- return (nni_msg_free(msg));
-} \ No newline at end of file
+ nni_init();
+ return (nni_msg_free(msg));
+}
diff --git a/src/nng.h b/src/nng.h
index a9357f4a..dcb3c21c 100644
--- a/src/nng.h
+++ b/src/nng.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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 NNG_H
@@ -46,21 +33,21 @@ extern "C" {
* as a DLL, but instead linking it statically for your projects
* to minimize questions about link dependencies later.)
*/
-#ifndef NNG_DECL
-#define NNG_DECL extern
+#ifndef NNG_DECL
+#define NNG_DECL extern
#endif
/*
* Types common to nng.
*/
-typedef struct nng_socket *nng_socket_t;
-typedef struct nng_endpt *nng_endpt_t;
-typedef struct nng_pipe *nng_pipe_t;
-typedef struct nng_msg *nng_msg_t;
-typedef struct nng_event *nng_event_t;
-typedef struct nng_notify *nng_notify_t;
-typedef struct nng_snapshot *nng_snapshot_t;
-typedef struct nng_stat *nng_stat_t;
+typedef struct nng_socket * nng_socket_t;
+typedef struct nng_endpt * nng_endpt_t;
+typedef struct nng_pipe * nng_pipe_t;
+typedef struct nng_msg * nng_msg_t;
+typedef struct nng_event * nng_event_t;
+typedef struct nng_notify * nng_notify_t;
+typedef struct nng_snapshot * nng_snapshot_t;
+typedef struct nng_stat * nng_stat_t;
/*
* nng_socket simply creates a socket of the given class. It returns an
@@ -103,7 +90,7 @@ NNG_DECL int nng_socket_getopt(nng_socket_t, int, void *, size_t *);
* recursion.
*/
NNG_DECL nng_notify_t nng_notify_register(nng_socket_t, int,
- void (*)(nng_socket_t, nng_event_t, void *), void *);
+void (*)(nng_socket_t, nng_event_t, void *), void *);
NNG_DECL int nng_notify_unregister(nng_socket_t, nng_notify_t);
/*
@@ -123,14 +110,14 @@ NNG_DECL int nng_notify_unregister(nng_socket_t, nng_notify_t);
* NNG_EVENT_ENDPT_RM - An endpoint is removed from the socket.
* The argument is an nn_endpt_t.
*/
-#define NNG_EVENT_BIT(x) (1U << (x))
-#define NNG_EVENT_RECV NNG_EVENT_BIT(0)
-#define NNG_EVENT_SEND NNG_EVENT_BIT(1)
-#define NNG_EVENT_ERROR NNG_EVENT_BIT(2)
-#define NNG_EVENT_PIPE_ADD NNG_EVENT_BIT(3)
-#define NNG_EVENT_PIPE_RM NNG_EVENT_BIT(4)
-#define NNG_EVENT_ENDPT_ADD NNG_EVENT_BIT(5)
-#define NNG_EVENT_ENDPT_RM NNG_EVENT_BIT(6)
+#define NNG_EVENT_BIT(x) (1U << (x))
+#define NNG_EVENT_RECV NNG_EVENT_BIT(0)
+#define NNG_EVENT_SEND NNG_EVENT_BIT(1)
+#define NNG_EVENT_ERROR NNG_EVENT_BIT(2)
+#define NNG_EVENT_PIPE_ADD NNG_EVENT_BIT(3)
+#define NNG_EVENT_PIPE_RM NNG_EVENT_BIT(4)
+#define NNG_EVENT_ENDPT_ADD NNG_EVENT_BIT(5)
+#define NNG_EVENT_ENDPT_RM NNG_EVENT_BIT(6)
/*
* The following functions return more detailed information about the event.
@@ -210,7 +197,7 @@ NNG_DECL const char *nng_strerror(int);
NNG_DECL int nng_send(nng_socket_t, const void *, size_t, int);
/*
- * nng_recv receives message data into the socket, up to the supplied size.
+ * nng_recv receives message data into the socket, up to the supplied size.
* The actual size of the message data will be written to the value pointed
* to by size. The flags may include NNG_FLAG_NONBLOCK and NNG_FLAG_ALLOC.
* If NNG_FLAG_ALLOC is supplied then the library will allocate memory for
@@ -273,19 +260,19 @@ NNG_DECL int nng_pipe_close(nng_pipe_t);
* Protocol numbers are never more than 16 bits. Also, there will never be
* a valid protocol numbered 0 (NNG_PROTO_NONE).
*/
-#define NNG_PROTO(major, minor) (((major) * 16) + (minor))
+#define NNG_PROTO(major, minor) (((major) * 16) + (minor))
#define NNG_PROTO_NONE NNG_PROTO(0, 0)
-#define NNG_PROTO_PAIR NNG_PROTO(1, 0)
-#define NNG_PROTO_PUB NNG_PROTO(2, 0)
-#define NNG_PROTO_SUB NNG_PROTO(2, 1)
-#define NNG_PROTO_REQ NNG_PROTO(3, 0)
-#define NNG_PROTO_REP NNG_PROTO(3, 1)
-#define NNG_PROTO_PUSH NNG_PROTO(5, 0)
-#define NNG_PROTO_PULL NNG_PROTO(5, 1)
-#define NNG_PROTO_SURVEYOR NNG_PROTO(6, 2)
-#define NNG_PROTO_RESPONDENT NNG_PROTO(6, 3)
-#define NNG_PROTO_BUS NNG_PROTO(7, 0)
-#define NNG_PROTO_STAR NNG_PROTO(100, 0)
+#define NNG_PROTO_PAIR NNG_PROTO(1, 0)
+#define NNG_PROTO_PUB NNG_PROTO(2, 0)
+#define NNG_PROTO_SUB NNG_PROTO(2, 1)
+#define NNG_PROTO_REQ NNG_PROTO(3, 0)
+#define NNG_PROTO_REP NNG_PROTO(3, 1)
+#define NNG_PROTO_PUSH NNG_PROTO(5, 0)
+#define NNG_PROTO_PULL NNG_PROTO(5, 1)
+#define NNG_PROTO_SURVEYOR NNG_PROTO(6, 2)
+#define NNG_PROTO_RESPONDENT NNG_PROTO(6, 3)
+#define NNG_PROTO_BUS NNG_PROTO(7, 0)
+#define NNG_PROTO_STAR NNG_PROTO(100, 0)
/*
* Options. We encode option numbers as follows:
@@ -295,29 +282,29 @@ NNG_DECL int nng_pipe_close(nng_pipe_t);
* <code> - specific value (16 bits)
*
*/
-#define NNG_OPT_SOCKET(c) (c)
-#define NNG_OPT_TRANSPORT_OPT(t, c) (0x10000 | ((p) << 16) | (c))
-
-#define NNG_OPT_RAW NNG_OPT_SOCKET(0)
-#define NNG_OPT_LINGER NNG_OPT_SOCKET(1)
-#define NNG_OPT_RCVBUF NNG_OPT_SOCKET(2)
-#define NNG_OPT_SNDBUF NNG_OPT_SOCKET(3)
-#define NNG_OPT_RCVTIMEO NNG_OPT_SOCKET(4)
-#define NNG_OPT_SNDTIMEO NNG_OPT_SOCKET(5)
-#define NNG_OPT_RECONN_TIME NNG_OPT_SOCKET(6)
-#define NNG_OPT_RECONN_MAXTIME NNG_OPT_SOCKET(7)
-#define NNG_OPT_RCVMAXSZ NNG_OPT_SOCKET(8)
-#define NNG_OPT_MAXTTL NNG_OPT_SOCKET(9)
-#define NNG_OPT_PROTOCOL NNG_OPT_SOCKET(10)
-#define NNG_OPT_SUBSCRIBE NNG_OPT_SOCKET(11)
-#define NNG_OPT_UNSUBSCRIBE NNG_OPT_SOCKET(12)
-#define NNG_OPT_SURVEYTIME NNG_OPT_SOCKET(13)
-#define NNG_OPT_RESENDTIME NNG_OPT_SOCKET(14)
-#define NNG_OPT_TRANSPORT NNG_OPT_SOCKET(15)
-#define NNG_OPT_LOCALADDR NNG_OPT_SOCKET(16)
-#define NNG_OPT_REMOTEADDR NNG_OPT_SOCKET(17)
-#define NNG_OPT_RECVFD NNG_OPT_SOCKET(18)
-#define NNG_OPT_SENDFD NNG_OPT_SOCKET(19)
+#define NNG_OPT_SOCKET(c) (c)
+#define NNG_OPT_TRANSPORT_OPT(t, c) (0x10000 | ((p) << 16) | (c))
+
+#define NNG_OPT_RAW NNG_OPT_SOCKET(0)
+#define NNG_OPT_LINGER NNG_OPT_SOCKET(1)
+#define NNG_OPT_RCVBUF NNG_OPT_SOCKET(2)
+#define NNG_OPT_SNDBUF NNG_OPT_SOCKET(3)
+#define NNG_OPT_RCVTIMEO NNG_OPT_SOCKET(4)
+#define NNG_OPT_SNDTIMEO NNG_OPT_SOCKET(5)
+#define NNG_OPT_RECONN_TIME NNG_OPT_SOCKET(6)
+#define NNG_OPT_RECONN_MAXTIME NNG_OPT_SOCKET(7)
+#define NNG_OPT_RCVMAXSZ NNG_OPT_SOCKET(8)
+#define NNG_OPT_MAXTTL NNG_OPT_SOCKET(9)
+#define NNG_OPT_PROTOCOL NNG_OPT_SOCKET(10)
+#define NNG_OPT_SUBSCRIBE NNG_OPT_SOCKET(11)
+#define NNG_OPT_UNSUBSCRIBE NNG_OPT_SOCKET(12)
+#define NNG_OPT_SURVEYTIME NNG_OPT_SOCKET(13)
+#define NNG_OPT_RESENDTIME NNG_OPT_SOCKET(14)
+#define NNG_OPT_TRANSPORT NNG_OPT_SOCKET(15)
+#define NNG_OPT_LOCALADDR NNG_OPT_SOCKET(16)
+#define NNG_OPT_REMOTEADDR NNG_OPT_SOCKET(17)
+#define NNG_OPT_RECVFD NNG_OPT_SOCKET(18)
+#define NNG_OPT_SENDFD NNG_OPT_SOCKET(19)
/* XXX: TBD: priorities, socket names, ipv4only */
@@ -380,8 +367,8 @@ NNG_DECL const char *nng_stat_name(nng_stat_t);
* user as is.
*/
NNG_DECL int nng_stat_type(nng_stat_t);
-#define NNG_STAT_LEVEL 0
-#define NNG_STAT_COUNTER 1
+#define NNG_STAT_LEVEL 0
+#define NNG_STAT_COUNTER 1
/*
* nng_stat_unit provides information about the unit for the statistic,
@@ -390,12 +377,12 @@ NNG_DECL int nng_stat_type(nng_stat_t);
* returned.
*/
NNG_DECL int nng_stat_unit(nng_stat_t);
-#define NNG_UNIT_NONE 0
-#define NNG_UNIT_BYTES 1
-#define NNG_UNIT_MESSAGES 2
-#define NNG_UNIT_BOOLEAN 3
-#define NNG_UNIT_MILLIS 4
-#define NNG_UNIT_EVENTS 5
+#define NNG_UNIT_NONE 0
+#define NNG_UNIT_BYTES 1
+#define NNG_UNIT_MESSAGES 2
+#define NNG_UNIT_BOOLEAN 3
+#define NNG_UNIT_MILLIS 4
+#define NNG_UNIT_EVENTS 5
/*
* nng_stat_value returns returns the actual value of the statistic.
@@ -431,21 +418,21 @@ NNG_DECL int nng_device(nng_socket_t, nng_socket_t);
* but do not count on this.
*/
#define NNG_EINTR (-1)
-#define NNG_ENOMEM (-2)
-#define NNG_EINVAL (-3)
-#define NNG_EBUSY (-4)
-#define NNG_ETIMEDOUT (-5)
-#define NNG_ECONNREFUSED (-6)
-#define NNG_ECLOSED (-7)
-#define NNG_EAGAIN (-8)
-#define NNG_ENOTSUP (-9)
-#define NNG_EADDRINUSE (-10)
+#define NNG_ENOMEM (-2)
+#define NNG_EINVAL (-3)
+#define NNG_EBUSY (-4)
+#define NNG_ETIMEDOUT (-5)
+#define NNG_ECONNREFUSED (-6)
+#define NNG_ECLOSED (-7)
+#define NNG_EAGAIN (-8)
+#define NNG_ENOTSUP (-9)
+#define NNG_EADDRINUSE (-10)
/*
* Maximum length of a socket address. This includes the terminating NUL.
* This limit is built into other implementations, so do not change it.
*/
-#define NNG_MAXADDRLEN (128)
+#define NNG_MAXADDRLEN (128)
#ifdef __cplusplus
}
diff --git a/src/platform/posix/posix_alloc.c b/src/platform/posix/posix_alloc.c
index b47a95b2..16b2dce3 100644
--- a/src/platform/posix/posix_alloc.c
+++ b/src/platform/posix/posix_alloc.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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.
*/
/*
@@ -36,13 +23,13 @@
/*
* POSIX memory allocation. This is pretty much standard C.
*/
-
void *
nni_alloc(size_t size)
{
return (malloc(size));
}
+
void
nni_free(void *ptr, size_t size)
{
@@ -50,4 +37,5 @@ nni_free(void *ptr, size_t size)
free(ptr);
}
-#endif \ No newline at end of file
+
+#endif
diff --git a/src/platform/posix/posix_clock.c b/src/platform/posix/posix_clock.c
index c772263c..4307fa89 100644
--- a/src/platform/posix/posix_clock.c
+++ b/src/platform/posix/posix_clock.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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.
*/
/*
@@ -38,17 +25,16 @@
#include <errno.h>
#include <string.h>
-#ifndef NNG_USE_GETTIMEOFDAY
+#ifndef NNG_USE_GETTIMEOFDAY
/*
* Use POSIX realtime stuff.
*/
-
uint64_t
nni_clock(void)
{
- struct timespec ts;
- uint64_t usec;
+ struct timespec ts;
+ uint64_t usec;
if (clock_gettime(NNG_USE_CLOCKID, &ts) != 0) {
/* This should never ever occur. */
@@ -76,7 +62,8 @@ nni_usleep(uint64_t usec)
}
}
-#else /* NNG_USE_GETTIMEOFDAY */
+
+#else /* NNG_USE_GETTIMEOFDAY */
/*
* If you're here, its because you don't have a modern clock_gettime with
@@ -98,6 +85,7 @@ nni_clock(void)
uint64_t usec;
struct timeval tv;
+
if (gettimeofday(&tv, NULL) != 0) {
nni_panic("gettimeofday failed: %s", strerror(errno));
}
@@ -108,6 +96,7 @@ nni_clock(void)
return (usec);
}
+
void
nni_usleep(uint64_t usec)
{
@@ -133,7 +122,7 @@ nni_usleep(uint64_t usec)
pfd.fd = -1;
pfd.events = 0;
- now = nni_clock();
+ now = nni_clock();
expire = now + usec;
while (now < expire) {
@@ -144,11 +133,12 @@ nni_usleep(uint64_t usec)
* early. So this gives us a better chance to avoid adding
* nearly an extra unneeded millisecond to the wait.
*/
- (void) poll(&pfd, 0, (int)((expire - now) / 1000));
- now = nni_clock();
+ (void) poll(&pfd, 0, (int) ((expire - now) / 1000));
+ now = nni_clock();
}
}
-#endif /* NNG_USE_GETTIMEOFDAY */
-#endif /* PLATFORM_POSIX_CLOCK */
+#endif /* NNG_USE_GETTIMEOFDAY */
+
+#endif /* PLATFORM_POSIX_CLOCK */
diff --git a/src/platform/posix/posix_config.h b/src/platform/posix/posix_config.h
index 1e83a948..a8da8ccd 100644
--- a/src/platform/posix/posix_config.h
+++ b/src/platform/posix/posix_config.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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.
*/
/*
@@ -35,7 +22,7 @@
* This value may be ignored on platforms that don't use POSIX clocks.
*
* #define NNG_USE_CLOCKID
- * This macro may be defined to a different clock id (see
+ * This macro may be defined to a different clock id (see
* clock_gettime()). By default we use CLOCK_MONOTONIC if it exists,
* or CLOCK_REALTIME otherwise. This is ignored if NNG_USE_GETTIMEOFDAY
* is defined. Platforms that don't use POSIX clocks will probably
@@ -49,12 +36,12 @@
#include <time.h>
-#ifndef CLOCK_REALTIME
-#define NNG_USE_GETTIMEOFDAY
+#ifndef CLOCK_REALTIME
+#define NNG_USE_GETTIMEOFDAY
#elif !defined(NNG_USE_CLOCKID)
-#ifdef CLOCK_MONOTONIC
-#define NNG_USE_CLOCKID CLOCK_MONOTONIC
+#ifdef CLOCK_MONOTONIC
+#define NNG_USE_CLOCKID CLOCK_MONOTONIC
#else
-#define NNG_USE_CLOCKID CLOCK_REALTIME
+#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 6b2d875a..37c0af66 100644
--- a/src/platform/posix/posix_debug.c
+++ b/src/platform/posix/posix_debug.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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"
@@ -33,10 +20,12 @@ nni_plat_abort(void)
abort();
}
+
void
nni_plat_println(const char *message)
{
(void) fprintf(stderr, "%s\n", message);
}
-#endif /* PLATFORM_POSIX_DEBUG */ \ No newline at end of file
+
+#endif /* PLATFORM_POSIX_DEBUG */
diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h
index 48b6e99b..c18af983 100644
--- a/src/platform/posix/posix_impl.h
+++ b/src/platform/posix/posix_impl.h
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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.
*/
/*
@@ -30,7 +17,7 @@
* functionality.
*/
-#ifdef PLATFORM_POSIX
+#ifdef PLATFORM_POSIX
#define PLATFORM_POSIX_ALLOC
#define PLATFORM_POSIX_DEBUG
#define PLATFORM_POSIX_CLOCK
diff --git a/src/platform/posix/posix_synch.c b/src/platform/posix/posix_synch.c
index cb8b30dd..555da36b 100644
--- a/src/platform/posix/posix_synch.c
+++ b/src/platform/posix/posix_synch.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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.
*/
/*
@@ -40,12 +27,12 @@
#include <time.h>
struct nni_mutex {
- pthread_mutex_t mx;
+ pthread_mutex_t mx;
};
struct nni_cond {
- pthread_cond_t cv;
- pthread_mutex_t *mx;
+ pthread_cond_t cv;
+ pthread_mutex_t * mx;
};
int
@@ -83,6 +70,7 @@ nni_mutex_create(nni_mutex_t *mp)
return (0);
}
+
void
nni_mutex_destroy(nni_mutex_t m)
{
@@ -92,6 +80,7 @@ nni_mutex_destroy(nni_mutex_t m)
nni_free(m, sizeof (*m));
}
+
void
nni_mutex_enter(nni_mutex_t m)
{
@@ -100,6 +89,7 @@ nni_mutex_enter(nni_mutex_t m)
}
}
+
void
nni_mutex_exit(nni_mutex_t m)
{
@@ -108,6 +98,7 @@ nni_mutex_exit(nni_mutex_t m)
}
}
+
int
nni_mutex_tryenter(nni_mutex_t m)
{
@@ -117,12 +108,14 @@ nni_mutex_tryenter(nni_mutex_t m)
return (0);
}
+
int
cond_attr(pthread_condattr_t **attrpp)
{
#if defined(NNG_USE_GETTIMEOFDAY) || NNG_USE_CLOCKID == CLOCK_REALTIME
*attrpp = NULL;
return (0);
+
#else
/* In order to make this fast, avoid reinitializing attrs. */
static pthread_condattr_t attr;
@@ -156,9 +149,11 @@ cond_attr(pthread_condattr_t **attrpp)
(void) pthread_mutex_unlock(&mx);
*attrpp = &attr;
return (0);
+
#endif
}
+
int
nni_cond_create(nni_cond_t *cvp, nni_mutex_t mx)
{
@@ -186,6 +181,7 @@ nni_cond_create(nni_cond_t *cvp, nni_mutex_t mx)
return (0);
}
+
void
nni_cond_destroy(nni_cond_t c)
{
@@ -195,6 +191,7 @@ nni_cond_destroy(nni_cond_t c)
nni_free(c, sizeof (*c));
}
+
void
nni_cond_signal(nni_cond_t c)
{
@@ -203,6 +200,7 @@ nni_cond_signal(nni_cond_t c)
}
}
+
void
nni_cond_broadcast(nni_cond_t c)
{
@@ -211,6 +209,7 @@ nni_cond_broadcast(nni_cond_t c)
}
}
+
void
nni_cond_wait(nni_cond_t c)
{
@@ -219,6 +218,7 @@ nni_cond_wait(nni_cond_t c)
}
}
+
int
nni_cond_timedwait(nni_cond_t c, uint64_t usec)
{
@@ -240,4 +240,5 @@ nni_cond_timedwait(nni_cond_t c, uint64_t usec)
return (0);
}
-#endif \ No newline at end of file
+
+#endif
diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c
index a41c7e7c..98b42d5c 100644
--- a/src/platform/posix/posix_thread.c
+++ b/src/platform/posix/posix_thread.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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.
*/
/*
@@ -41,8 +28,8 @@
struct nni_thread {
pthread_t tid;
- void *arg;
- void (*func)(void *);
+ void * arg;
+ void (*func)(void *);
};
static pthread_mutex_t plat_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -58,6 +45,7 @@ thrfunc(void *arg)
return (NULL);
}
+
int
nni_thread_create(nni_thread_t *tp, void (*fn)(void *), void *arg)
{
@@ -78,34 +66,39 @@ nni_thread_create(nni_thread_t *tp, void (*fn)(void *), void *arg)
return (0);
}
+
void
nni_thread_reap(nni_thread_t thr)
{
int rv;
+
if ((rv = pthread_join(thr->tid, NULL)) != 0) {
nni_panic("pthread_thread: %s", strerror(errno));
}
nni_free(thr, sizeof (*thr));
}
+
void
atfork_child(void)
{
plat_fork = 1;
}
+
int
nni_plat_init(int (*helper)(void))
{
int rv;
+
if (plat_fork) {
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);
}
@@ -121,10 +114,12 @@ nni_plat_init(int (*helper)(void))
return (rv);
}
+
void
nni_plat_fini(void)
{
/* XXX: NOTHING *YET* */
}
-#endif \ No newline at end of file
+
+#endif
diff --git a/src/platform/posix/posix_vsnprintf.c b/src/platform/posix/posix_vsnprintf.c
index 42367b4c..d8191a90 100644
--- a/src/platform/posix/posix_vsnprintf.c
+++ b/src/platform/posix/posix_vsnprintf.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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"
@@ -33,4 +20,5 @@ nni_plat_vsnprintf(char *dst, size_t sz, const char *fmt, va_list va)
(void) vsnprintf(dst, sz, fmt, va);
}
-#endif \ No newline at end of file
+
+#endif
diff --git a/src/protocol/pair/pair.c b/src/protocol/pair/pair.c
index 6bb55a5d..e24efd71 100644
--- a/src/protocol/pair/pair.c
+++ b/src/protocol/pair/pair.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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 <stdlib.h>
@@ -29,28 +16,28 @@
* Pair protocol. The PAIR protocol is a simple 1:1 messaging pattern.
*/
-typedef struct pair *pair_t;
-typedef struct pairpipe *pairpipe_t;
+typedef struct pair * pair_t;
+typedef struct pairpipe * pairpipe_t;
/*
* Note that pair can only have a single pipe, so we don't need
* to create separate data structures for diferent pipe instances.
*/
struct pair {
- nni_socket_t sock;
- nni_mutex_t mx;
- nni_pipe_t pipe;
- nni_msgqueue_t uwq;
- nni_msgqueue_t urq;
+ nni_socket_t sock;
+ nni_mutex_t mx;
+ nni_pipe_t pipe;
+ nni_msgqueue_t uwq;
+ nni_msgqueue_t urq;
};
struct pairpipe {
nni_pipe_t pipe;
pair_t pair;
int good;
- nni_thread_t sthr;
- nni_thread_t rthr;
- int sigclose;
+ nni_thread_t sthr;
+ nni_thread_t rthr;
+ int sigclose;
};
static void pair_receiver(void *);
@@ -62,55 +49,59 @@ pair_create(void **pairp, nni_socket_t sock)
pair_t pair;
int rv;
- if ((pair = nni_alloc(sizeof (*pair))) == NULL) {
- return (NNG_ENOMEM);
- }
- if ((rv = nni_mutex_create(&pair->mx)) != 0) {
- nni_free(pair, sizeof (*pair));
- return (rv);
- }
- pair->sock = sock;
- pair->uwq = nni_socket_sendq(sock);
- pair->urq = nni_socket_recvq(sock);
- *pairp = pair;
- return (0);
+ if ((pair = nni_alloc(sizeof (*pair))) == NULL) {
+ return (NNG_ENOMEM);
+ }
+ if ((rv = nni_mutex_create(&pair->mx)) != 0) {
+ nni_free(pair, sizeof (*pair));
+ return (rv);
+ }
+ pair->sock = sock;
+ pair->uwq = nni_socket_sendq(sock);
+ pair->urq = nni_socket_recvq(sock);
+ *pairp = pair;
+ return (0);
}
+
static void
pair_destroy(void *arg)
{
- pair_t pair = arg;
- nni_mutex_destroy(pair->mx);
- nni_free(pair, sizeof (*pair));
+ pair_t pair = arg;
+
+ nni_mutex_destroy(pair->mx);
+ nni_free(pair, sizeof (*pair));
}
+
static void
pair_shutdown(void *arg, uint64_t usec)
{
pair_t pair = arg;
nni_pipe_t pipe;
- NNI_ARG_UNUSED(usec);
+ NNI_ARG_UNUSED(usec);
- /*
- * XXX: correct implementation here is to set a draining flag,
- * and wait a bit for the sender to finish draining (linger),
- * then reap the pipe. For now we just act a little more harshly.
- */
- nni_mutex_enter(pair->mx);
- pipe = pair->pipe;
- pair->pipe = NULL;
- nni_mutex_exit(pair->mx);
+ /*
+ * XXX: correct implementation here is to set a draining flag,
+ * and wait a bit for the sender to finish draining (linger),
+ * then reap the pipe. For now we just act a little more harshly.
+ */
+ nni_mutex_enter(pair->mx);
+ pipe = pair->pipe;
+ pair->pipe = NULL;
+ nni_mutex_exit(pair->mx);
- nni_pipe_close(pipe);
+ nni_pipe_close(pipe);
}
+
static int
pair_add_pipe(void *arg, nni_pipe_t pipe)
{
- pair_t pair = arg;
- pairpipe_t pp;
- int rv;
+ pair_t pair = arg;
+ pairpipe_t pp;
+ int rv;
pp = nni_alloc(sizeof (*pp));
pp->pipe = pipe;
@@ -119,27 +110,28 @@ pair_add_pipe(void *arg, nni_pipe_t pipe)
pp->sthr = NULL;
pp->rthr = NULL;
- nni_mutex_enter(pair->mx);
- if (pair->pipe != NULL) {
- /* Already have a peer, denied. */
- nni_mutex_exit(pair->mx);
- nni_free(pp, sizeof (*pp));
- return (NNG_EBUSY);
- }
- if ((rv = nni_thread_create(&pp->rthr, pair_receiver, pp)) != 0) {
- nni_mutex_exit(pair->mx);
- return (rv);
- }
- if ((rv = nni_thread_create(&pp->sthr, pair_sender, pp)) != 0) {
- nni_mutex_exit(pair->mx);
- return (rv);
- }
- pp->good = 1;
- pair->pipe = pipe;
- nni_mutex_exit(pair->mx);
- return (NNG_EINVAL);
+ nni_mutex_enter(pair->mx);
+ if (pair->pipe != NULL) {
+ /* Already have a peer, denied. */
+ nni_mutex_exit(pair->mx);
+ nni_free(pp, sizeof (*pp));
+ return (NNG_EBUSY);
+ }
+ if ((rv = nni_thread_create(&pp->rthr, pair_receiver, pp)) != 0) {
+ nni_mutex_exit(pair->mx);
+ return (rv);
+ }
+ if ((rv = nni_thread_create(&pp->sthr, pair_sender, pp)) != 0) {
+ nni_mutex_exit(pair->mx);
+ return (rv);
+ }
+ pp->good = 1;
+ pair->pipe = pipe;
+ nni_mutex_exit(pair->mx);
+ return (NNG_EINVAL);
}
+
static int
pair_remove_pipe(void *arg, nni_pipe_t pipe)
{
@@ -152,15 +144,16 @@ pair_remove_pipe(void *arg, nni_pipe_t pipe)
if (pp->rthr) {
(void) nni_thread_reap(pp->rthr);
}
- nni_mutex_enter(pair->mx);
- if (pair->pipe != pipe) {
- nni_mutex_exit(pair->mx);
- return (NNG_EINVAL);
- }
- nni_mutex_exit(pair->mx);
- return (NNG_EINVAL);
+ nni_mutex_enter(pair->mx);
+ if (pair->pipe != pipe) {
+ nni_mutex_exit(pair->mx);
+ return (NNG_EINVAL);
+ }
+ nni_mutex_exit(pair->mx);
+ return (NNG_EINVAL);
}
+
static void
pair_sender(void *arg)
{
@@ -196,6 +189,7 @@ pair_sender(void *arg)
nni_socket_remove_pipe(pair->sock, pipe);
}
+
static void
pair_receiver(void *arg)
{
@@ -230,35 +224,37 @@ pair_receiver(void *arg)
nni_socket_remove_pipe(pair->sock, pipe);
}
+
static int
pair_setopt(void *arg, int opt, const void *buf, size_t sz)
{
return (NNG_ENOTSUP);
}
+
static int
pair_getopt(void *arg, int opt, void *buf, size_t *szp)
{
return (NNG_ENOTSUP);
}
+
/*
* Global inproc state - this contains the list of active endpoints
* which we use for coordinating rendezvous.
*/
struct nni_protocol nni_pair_protocol = {
- NNG_PROTO_PAIR, /* proto_self */
- NNG_PROTO_PAIR, /* proto_peer */
- "pair",
- pair_create,
- pair_destroy,
- pair_shutdown,
- pair_add_pipe,
- pair_remove_pipe,
+ NNG_PROTO_PAIR, /* proto_self */
+ NNG_PROTO_PAIR, /* proto_peer */
+ "pair",
+ pair_create,
+ pair_destroy,
+ pair_shutdown,
+ pair_add_pipe,
+ pair_remove_pipe,
pair_setopt,
pair_getopt,
- NULL, /* proto_recvfilter */
- NULL, /* proto_sendfilter */
+ NULL, /* proto_recvfilter */
+ NULL, /* proto_sendfilter */
};
-
diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c
index 154f4117..b031a5bc 100644
--- a/src/transport/inproc/inproc.c
+++ b/src/transport/inproc/inproc.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * 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.
+ * 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 <stdlib.h>
@@ -30,9 +17,9 @@
* peer to another.
*/
-typedef struct inproc_pair *inproc_pair_t;
-typedef struct inproc_pipe *inproc_pipe_t;
-typedef struct inproc_ep *inproc_ep_t;
+typedef struct inproc_pair * inproc_pair_t;
+typedef struct inproc_pipe * inproc_pipe_t;
+typedef struct inproc_ep * inproc_ep_t;
typedef struct {
nni_mutex_t mx;
@@ -41,7 +28,7 @@ typedef struct {
} inproc_global_t;
struct inproc_pipe {
- const char *addr;
+ const char * addr;
inproc_pair_t pair;
nni_msgqueue_t rq;
nni_msgqueue_t wq;
@@ -60,14 +47,14 @@ struct inproc_ep {
char addr[NNG_MAXADDRLEN];
int mode;
int closed;
- nni_list_node_t node;
+ nni_list_node_t node;
uint16_t proto;
- void *cpipe; /* connected pipe (DIAL only) */
+ void * cpipe; /* connected pipe (DIAL only) */
};
-#define INPROC_EP_IDLE 0
-#define INPROC_EP_DIAL 1
-#define INPROC_EP_LISTEN 2
+#define INPROC_EP_IDLE 0
+#define INPROC_EP_DIAL 1
+#define INPROC_EP_LISTEN 2
/*
* Global inproc state - this contains the list of active endpoints
@@ -79,6 +66,7 @@ static int
inproc_init(void)
{
int rv;
+
if ((rv = nni_mutex_create(&inproc.mx)) != 0) {
return (rv);
}
@@ -91,6 +79,7 @@ inproc_init(void)
return (0);
}
+
static void
inproc_fini(void)
{
@@ -98,15 +87,17 @@ inproc_fini(void)
nni_mutex_destroy(inproc.mx);
}
+
static void
inproc_pipe_close(void *arg)
{
- inproc_pipe_t pipe = arg;
+ inproc_pipe_t pipe = arg;
nni_msgqueue_close(pipe->rq);
nni_msgqueue_close(pipe->wq);
}
+
static void
inproc_pair_destroy(inproc_pair_t pair)
{
@@ -125,11 +116,12 @@ inproc_pair_destroy(inproc_pair_t pair)
nni_free(pair, sizeof (*pair));
}
+
static void
inproc_pipe_destroy(void *arg)
{
- inproc_pipe_t pipe = arg;
- inproc_pair_t pair = pipe->pair;
+ inproc_pipe_t pipe = arg;
+ inproc_pair_t pair = pipe->pair;
/* We could assert the pipe closed... */
@@ -144,6 +136,7 @@ inproc_pipe_destroy(void *arg)
}
}
+
static int
inproc_pipe_send(void *arg, nng_msg_t msg)
{
@@ -156,6 +149,7 @@ inproc_pipe_send(void *arg, nng_msg_t msg)
return (nni_msgqueue_put(pipe->wq, msg, -1));
}
+
static int
inproc_pipe_recv(void *arg, nng_msg_t *msgp)
{
@@ -164,6 +158,7 @@ inproc_pipe_recv(void *arg, nng_msg_t *msgp)
return (nni_msgqueue_get(pipe->rq, msgp, -1));
}
+
static uint16_t
inproc_pipe_peer(void *arg)
{
@@ -172,6 +167,7 @@ inproc_pipe_peer(void *arg)
return (pipe->peer);
}
+
static int
inproc_pipe_getopt(void *arg, int option, void *buf, size_t *szp)
{
@@ -193,10 +189,11 @@ inproc_pipe_getopt(void *arg, int option, void *buf, size_t *szp)
return (NNG_ENOTSUP);
}
+
static int
inproc_ep_create(void **epp, const char *url, uint16_t proto)
{
- inproc_ep_t ep;
+ inproc_ep_t ep;
if (strlen(url) > NNG_MAXADDRLEN-1) {
return (NNG_EINVAL);
@@ -214,20 +211,23 @@ inproc_ep_create(void **epp, const char *url, uint16_t proto)
return (0);
}
+
static void
inproc_ep_destroy(void *arg)
{
inproc_ep_t ep = arg;
+
if (!ep->closed) {
nni_panic("inproc_ep_destroy while not closed!");
}
nni_free(ep, sizeof (*free));
}
+
static void
inproc_ep_close(void *arg)
{
- inproc_ep_t ep = arg;
+ inproc_ep_t ep = arg;
nni_mutex_enter(inproc.mx);
if (!ep->closed) {
@@ -238,18 +238,19 @@ inproc_ep_close(void *arg)
nni_mutex_exit(inproc.mx);
}
+
static int
inproc_ep_dial(void *arg, void **pipep)
{
inproc_ep_t ep = arg;
inproc_ep_t srch;
nni_list_t *list = &inproc.eps;
-
+
if (ep->mode != INPROC_EP_IDLE) {
return (NNG_EINVAL);
}
nni_mutex_enter(inproc.mx);
- NNI_LIST_FOREACH(list, srch) {
+ NNI_LIST_FOREACH (list, srch) {
if (srch->mode != INPROC_EP_LISTEN) {
continue;
}
@@ -283,6 +284,7 @@ inproc_ep_dial(void *arg, void **pipep)
return (ep->closed ? NNG_ECLOSED : 0);
}
+
static int
inproc_ep_listen(void *arg)
{
@@ -298,7 +300,7 @@ inproc_ep_listen(void *arg)
nni_mutex_exit(inproc.mx);
return (NNG_ECLOSED);
}
- NNI_LIST_FOREACH(list, srch) {
+ NNI_LIST_FOREACH (list, srch) {
if (srch->mode != INPROC_EP_LISTEN) {
continue;
}
@@ -313,6 +315,7 @@ inproc_ep_listen(void *arg)
return (0);
}
+
static int
inproc_ep_accept(void *arg, void **pipep)
{
@@ -332,7 +335,7 @@ inproc_ep_accept(void *arg, void **pipep)
nni_mutex_exit(inproc.mx);
return (NNG_ECLOSED);
}
- NNI_LIST_FOREACH(list, srch) {
+ NNI_LIST_FOREACH (list, srch) {
if (srch->mode != INPROC_EP_DIAL) {
continue;
}
@@ -365,12 +368,13 @@ inproc_ep_accept(void *arg, void **pipep)
srch->cpipe = &pair->pipe[0];
*pipep = &pair->pipe[1];
nni_cond_broadcast(inproc.cv);
-
+
nni_mutex_exit(inproc.mx);
return (0);
}
+
static struct nni_pipe_ops inproc_pipe_ops = {
inproc_pipe_destroy,
inproc_pipe_send,
@@ -387,14 +391,14 @@ static struct nni_endpt_ops inproc_ep_ops = {
inproc_ep_listen,
inproc_ep_accept,
inproc_ep_close,
- NULL, /* inproc_ep_setopt */
- NULL, /* inproc_ep_getopt */
+ NULL, /* inproc_ep_setopt */
+ NULL, /* inproc_ep_getopt */
};
struct nni_transport nni_inproc_transport = {
- "inproc", /* tran_scheme */
+ "inproc", /* tran_scheme */
&inproc_ep_ops,
&inproc_pipe_ops,
- inproc_init, /* tran_init */
- inproc_fini, /* tran_fini */
+ inproc_init, /* tran_init */
+ inproc_fini, /* tran_fini */
};