diff options
| author | Garrett D'Amore <garrett@damore.org> | 2016-12-23 01:50:31 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2016-12-23 01:50:31 -0800 |
| commit | 72440b0d815b1b79941f3f58a47ec4df1ba1e0fc (patch) | |
| tree | 6494c69b89f36ab75976fc7acaec68a4d4f0d1bf | |
| parent | 07478f02caaebf74c11b366d048ba696a8678fec (diff) | |
| download | nng-72440b0d815b1b79941f3f58a47ec4df1ba1e0fc.tar.gz nng-72440b0d815b1b79941f3f58a47ec4df1ba1e0fc.tar.bz2 nng-72440b0d815b1b79941f3f58a47ec4df1ba1e0fc.zip | |
Some tests around recvmsg (no senders yet). Fixes for some edge cases.
| -rw-r--r-- | src/core/socket.c | 4 | ||||
| -rw-r--r-- | src/core/socket.h | 1 | ||||
| -rw-r--r-- | src/nng.c | 16 | ||||
| -rw-r--r-- | src/nng.h | 6 | ||||
| -rw-r--r-- | tests/sock.c | 14 |
5 files changed, 38 insertions, 3 deletions
diff --git a/src/core/socket.c b/src/core/socket.c index 99573a2f..e3298886 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -57,8 +57,8 @@ nni_socket_create(nni_socket **sockp, uint16_t proto) NNI_LIST_INIT(&sock->s_pipes, nni_pipe, p_sock_node); NNI_LIST_INIT(&sock->s_eps, nni_endpt, ep_sock_node); - if (((rv = nni_msgqueue_create(&sock->s_uwq, 1)) != 0) || - ((rv = nni_msgqueue_create(&sock->s_urq, 1)) != 0)) { + if (((rv = nni_msgqueue_create(&sock->s_uwq, 0)) != 0) || + ((rv = nni_msgqueue_create(&sock->s_urq, 0)) != 0)) { goto fail; } diff --git a/src/core/socket.h b/src/core/socket.h index 1376c454..4fa59355 100644 --- a/src/core/socket.h +++ b/src/core/socket.h @@ -45,5 +45,6 @@ extern void nni_socket_rem_pipe(nni_socket *, nni_pipe *); extern uint16_t nni_socket_proto(nni_socket *); extern int nni_socket_setopt(nni_socket *, int, const void *, size_t); extern int nni_socket_getopt(nni_socket *, int, void *, size_t *); +extern int nni_socket_recvmsg(nni_socket *, nni_msg **, int); #endif // CORE_SOCKET_H @@ -48,6 +48,22 @@ nng_socket_protocol(nng_socket *s) return (nni_socket_proto(s)); } +int +nng_recvmsg(nng_socket *s, nng_msg **msgp, int flags) +{ + int rv; + nni_duration expire; + if ((rv = nni_init()) != 0) { + return (rv); + } + if (flags == NNG_FLAG_NONBLOCK) { + expire = 0; + } else { + // XXX: revise this timeout from socket option!! + expire = 1000000; + } + return (nni_socket_recvmsg(s, msgp, expire)); +} // Misc. const char * @@ -193,6 +193,10 @@ NNG_DECL int nng_msg_trunc_header(nng_msg *, size_t); NNG_DECL int nng_pipe_getopt(nng_pipe *, int, void *, size_t *); NNG_DECL int nng_pipe_close(nng_pipe *); +// Flags. +#define NNG_FLAG_ALLOC 1 // Recv to allocate receive buffer. +#define NNG_FLAG_NONBLOCK 2 // Non-block send/recv. + // Protocol numbers. These are to be used with nng_socket_create(). // These values are used on the wire, so must not be changed. The major // number of the protocol is shifted left by 4 bits, and a subprotocol is @@ -349,7 +353,7 @@ NNG_DECL int nng_device(nng_socket *, nng_socket *); // Default linger time in microseconds. The framework will wait up until // this long for outgoing message queues to drain before closing underlying // connections, when closing the socket itself. -#define NNG_LINGER_DEFAULT (1000000) +#define NNG_LINGER_DEFAULT (1000000) #ifdef __cplusplus } diff --git a/tests/sock.c b/tests/sock.c index 40949bfe..76942d31 100644 --- a/tests/sock.c +++ b/tests/sock.c @@ -27,5 +27,19 @@ TestMain("Socket Operations", { Convey("It's type is still proto", { So(nng_socket_protocol(sock) == NNG_PROTO_PAIR); }) + + Convey("Recv on with no pipes times out", { + nng_msg *msg = NULL; + rv = nng_recvmsg(sock, &msg, 0); + So(rv == NNG_ETIMEDOUT); + So(msg == NULL); + }) + + Convey("Recv nonblock with no pipes gives EAGAIN", { + nng_msg *msg = NULL; + rv = nng_recvmsg(sock, &msg, NNG_FLAG_NONBLOCK); + So(rv == NNG_EAGAIN); + So(msg == NULL); + }) }) })
\ No newline at end of file |
