From 660decae9ba5e2756950267587724c2d25953d00 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 11 Dec 2016 19:31:43 -0800 Subject: Work in progress on sendmsg. --- src/core/socket.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'src/core') diff --git a/src/core/socket.c b/src/core/socket.c index 247c5640..e9963b74 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -32,9 +32,83 @@ struct nng_socket { int s_proto; nni_mutex_t s_mx; + nni_msgqueue_t s_uwq; /* Upper write queue. */ + nni_msgqueue_t s_urq; /* Upper read queue. */ + /* uwq */ /* urq */ /* options */ /* pipes */ /* endpoints */ + + int s_besteffort; /* Best effort mode delivery. */ + int s_senderr; /* Protocol state machine use. */ }; + +int +nng_socket_create(nng_socket_t *sockp, int proto) +{ + return (NNG_EAGAIN); /* XXX: IMPLEMENT ME */ +} + +int +nng_socket_close(nng_socket_t sock) +{ + nni_msgqueue_close(sock->s_urq); + /* XXX: drain this? */ + nni_msgqueue_close(sock->s_uwq); + + /* XXX: close endpoints - no new pipes made... */ + + /* XXX: protocol shutdown */ + + /* XXX: close remaining pipes */ + + /* XXX: wait for workers to cease activity */ + + return (0); +} + +int +nng_socket_sendmsg(nng_socket_t sock, nng_msg_t msg, int tmout) +{ + int rv; + int besteffort; + + /* + * Senderr is typically set by protocols when the state machine + * indicates that it is no longer valid to send a message. E.g. + * a REP socket with no REQ pending. + */ + nni_mutex_enter(sock->s_mx); + if ((rv = sock->s_senderr) != 0) { + nni_mutex_exit(sock->s_mx); + return (rv); + } + besteffort = sock->s_besteffort; + nni_mutex_exit(sock->s_mx); + +#if 0 + if (s.ops.p_sendhook != NULL) { + if ((rv = s.ops.p_sendhook(sock->s_proto, msg)) != 0) { + nng_msg_free(msg); + return (0); + } + } +#endif + + if (besteffort) { + /* + * BestEffort mode -- if we cannot handle the message due + * to backpressure, we just throw it away, and don't complain. + */ + tmout = 0; + } + rv = nni_msgqueue_put(sock->s_uwq, msg, tmout); + if (besteffort && (rv == NNG_EAGAIN)) { + /* Pretend this worked... it didn't, but pretend. */ + nng_msg_free(msg); + return (0); + } + return (rv); +} -- cgit v1.2.3-70-g09d2