diff options
| author | Garrett D'Amore <garrett@damore.org> | 2016-12-21 00:38:26 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2016-12-21 00:38:26 -0800 |
| commit | 5db7f0f969fb05cb0783acd187857b7b06b09b8b (patch) | |
| tree | 421d2fdaf2830e961ab9cd50dc518e22803b62ec /src/core | |
| parent | 529c84d6a1bf2400170263c9e68d9433a70cc43d (diff) | |
| download | nng-5db7f0f969fb05cb0783acd187857b7b06b09b8b.tar.gz nng-5db7f0f969fb05cb0783acd187857b7b06b09b8b.tar.bz2 nng-5db7f0f969fb05cb0783acd187857b7b06b09b8b.zip | |
Uncrustify configuration, and shorter copyright banners, plus reformat
code with uncrustify. (Minor adjustments.) No more arguments!
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/defs.h | 33 | ||||
| -rw-r--r-- | src/core/endpt.h | 45 | ||||
| -rw-r--r-- | src/core/init.c | 23 | ||||
| -rw-r--r-- | src/core/init.h | 23 | ||||
| -rw-r--r-- | src/core/list.c | 44 | ||||
| -rw-r--r-- | src/core/list.h | 33 | ||||
| -rw-r--r-- | src/core/message.c | 63 | ||||
| -rw-r--r-- | src/core/message.h | 23 | ||||
| -rw-r--r-- | src/core/msgqueue.c | 38 | ||||
| -rw-r--r-- | src/core/msgqueue.h | 25 | ||||
| -rw-r--r-- | src/core/nng_impl.h | 21 | ||||
| -rw-r--r-- | src/core/panic.c | 28 | ||||
| -rw-r--r-- | src/core/panic.h | 21 | ||||
| -rw-r--r-- | src/core/pipe.c | 36 | ||||
| -rw-r--r-- | src/core/pipe.h | 38 | ||||
| -rw-r--r-- | src/core/platform.c | 21 | ||||
| -rw-r--r-- | src/core/platform.h | 21 | ||||
| -rw-r--r-- | src/core/protocol.c | 28 | ||||
| -rw-r--r-- | src/core/protocol.h | 126 | ||||
| -rw-r--r-- | src/core/snprintf.c | 23 | ||||
| -rw-r--r-- | src/core/snprintf.h | 23 | ||||
| -rw-r--r-- | src/core/socket.c | 85 | ||||
| -rw-r--r-- | src/core/socket.h | 41 | ||||
| -rw-r--r-- | src/core/transport.c | 27 | ||||
| -rw-r--r-- | src/core/transport.h | 59 |
25 files changed, 343 insertions, 605 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 *); }; /* |
