aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/nng_impl.h1
-rw-r--r--src/core/protocol.h127
-rw-r--r--src/core/transport.c10
-rw-r--r--src/core/transport.h2
4 files changed, 134 insertions, 6 deletions
diff --git a/src/core/nng_impl.h b/src/core/nng_impl.h
index d728c652..beae4056 100644
--- a/src/core/nng_impl.h
+++ b/src/core/nng_impl.h
@@ -44,6 +44,7 @@
#include "core/panic.h"
#include "core/snprintf.h"
#include "core/platform.h"
+#include "core/protocol.h"
#include "core/transport.h"
#endif /* CORE_NNG_IMPL_H */
diff --git a/src/core/protocol.h b/src/core/protocol.h
new file mode 100644
index 00000000..b0e579a3
--- /dev/null
+++ b/src/core/protocol.h
@@ -0,0 +1,127 @@
+/*
+ * 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.
+ */
+
+#ifndef CORE_PROTOCOL_H
+#define CORE_PROTOCOL_H
+
+/*
+ * Protocol implementation details. Protocols must implement the
+ * interfaces in this file.
+ */
+
+struct nni_protocol {
+
+ /*
+ * Protocol information.
+ */
+ uint16_t proto_self; /* our 16-bit protocol ID */
+ uint16_t proto_peer; /* who we peer with (protocol ID) */
+
+ /*
+ * Create protocol instance data, which will be stored on the socket.
+ */
+ int (*proto_create)(void **, nng_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 *, nng_pipe_t);
+ int (*proto_remove_pipe)(void *, nng_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 *, nng_msg_t);
+
+ /*
+ * Send filter. This may be NULL, but if it isn't, then
+ * messages here are filtered just after they come from the
+ * application.
+ */
+ nng_msg_t (*proto_send_filter)(void *, nng_msg_t);
+};
+
+/*
+ * These are socket methods that protocol operations can
+ * reasonably expect to call.
+ */
+
+/*
+ * nni_socket_sendq obtains the upper writeq. The protocol should
+ * recieve messages from this, and place them on the appropriate
+ * pipe.
+ */
+extern nni_msgqueue_t nni_socket_sendq(nng_socket_t);
+
+/*
+ * nni_socket_recvq obtains the upper readq. The protocol should
+ * inject incoming messages from pipes to it.
+ */
+extern nni_msgqueue_t nni_socket_recvq(nng_socket_t);
+
+/*
+ * nni_socket_recv_err sets an error code to be returned to clients
+ * rather than waiting for a message. Set it to 0 to resume normal
+ * receive operation.
+ */
+extern void nni_socket_recv_err(nng_socket_t, int);
+
+/*
+ * nni_socket_send_err sets an error code to be returned to clients
+ * when they try to send, so that they don't have to timeout waiting
+ * for their message to be accepted for send. Set it to 0 to resume
+ * normal send operations.
+ */
+extern void nni_socket_send_err(nng_socket_t, int);
+
+/*
+ * Pipe operations that protocols use.
+ */
+extern int nni_pipe_recv(nng_pipe_t, nng_msg_t *);
+extern int nni_pipe_send(nng_pipe_t, nng_msg_t);
+extern uint32_t nni_pipe_id(nng_pipe_t);
+extern uint32_t nni_pipe_close(nng_pipe_t);
+
+#endif /* CORE_PROTOCOL_H */
diff --git a/src/core/transport.c b/src/core/transport.c
index 67f2ca2f..1053cf16 100644
--- a/src/core/transport.c
+++ b/src/core/transport.c
@@ -26,10 +26,10 @@
* 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_ops nni_inproc_tran_ops;
+extern struct nni_transport nni_inproc_transport;
-static struct nni_transport_ops *transports[] = {
- &nni_inproc_tran_ops,
+static struct nni_transport *transports[] = {
+ &nni_inproc_transport,
NULL
};
@@ -41,7 +41,7 @@ void
nni_transport_init(void)
{
int i;
- struct nni_transport_ops *ops;
+ struct nni_transport *ops;
for (i = 0; (ops = transports[i]) != NULL; i++) {
ops->tran_init();
@@ -52,7 +52,7 @@ void
nni_transport_fork(int prefork)
{
int i;
- struct nni_transport_ops *ops;
+ struct nni_transport *ops;
for (i = 0; (ops = transports[i]) != NULL; i++) {
if (ops->tran_fork != NULL) {
diff --git a/src/core/transport.h b/src/core/transport.h
index 65f1976e..93eeafc0 100644
--- a/src/core/transport.h
+++ b/src/core/transport.h
@@ -28,7 +28,7 @@
* interfaces in this file.
*/
-struct nni_transport_ops {
+struct nni_transport {
/*
* tran_scheme is the transport scheme, such as "tcp" or "inproc".
*/