diff options
| author | Garrett D'Amore <garrett@damore.org> | 2016-12-24 15:22:36 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2016-12-24 15:22:36 -0800 |
| commit | 3bed9dca3a3ae5b226e3bf6aee3352d7665dbcc2 (patch) | |
| tree | df080f601ec6e050c2a7a4df7a7b728aa7d0d2fb | |
| parent | cb4fe7294f7da2ad1a2fdf896748b42e1a8115ab (diff) | |
| download | nng-3bed9dca3a3ae5b226e3bf6aee3352d7665dbcc2.tar.gz nng-3bed9dca3a3ae5b226e3bf6aee3352d7665dbcc2.tar.bz2 nng-3bed9dca3a3ae5b226e3bf6aee3352d7665dbcc2.zip | |
Expose nng_sendmsg.
| -rw-r--r-- | src/nng.c | 21 | ||||
| -rw-r--r-- | tests/sock.c | 21 |
2 files changed, 42 insertions, 0 deletions
@@ -70,6 +70,27 @@ nng_recvmsg(nng_socket *s, nng_msg **msgp, int flags) return (nni_socket_recvmsg(s, msgp, expire)); } +int +nng_sendmsg(nng_socket *s, nng_msg *msg, int flags) +{ + int rv; + nni_time expire; + + if ((rv = nni_init()) != 0) { + return (rv); + } + + if ((flags == NNG_FLAG_NONBLOCK) || (s->s_sndtimeo == 0)) { + expire = NNI_TIME_ZERO; + } else if (s->s_sndtimeo < 0) { + expire = NNI_TIME_NEVER; + } else { + expire = nni_clock() + s->s_sndtimeo; + } + + return (nni_socket_sendmsg(s, msg, expire)); +} + int nng_setopt(nng_socket *s, int opt, const void *val, size_t sz) diff --git a/tests/sock.c b/tests/sock.c index 931e114a..65ed5565 100644 --- a/tests/sock.c +++ b/tests/sock.c @@ -54,6 +54,27 @@ TestMain("Socket Operations", { So(msg == NULL); }) + Convey("Send with no pipes times out correctly", { + nng_msg *msg = NULL; + int64_t when = 500000; + uint64_t now; + + // We cheat to get access to the core's clock. + So(nng_msg_alloc(&msg, 0) == 0); + So(msg != NULL); + extern uint64_t nni_clock(void); + now = nni_clock(); + + rv = nng_setopt(sock, NNG_OPT_SNDTIMEO, &when, + sizeof (when)); + So(rv == 0); + rv = nng_sendmsg(sock, msg, 0); + So(rv == NNG_ETIMEDOUT); + So(nni_clock() > (now + 500000)); + So(nni_clock() < (now + 1000000)); + nng_msg_free(msg); + }) + Convey("We can set and get options", { int64_t when = 1234; int64_t check = 0; |
