diff options
| author | Garrett D'Amore <garrett@damore.org> | 2016-12-28 21:03:06 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2016-12-28 21:03:06 -0800 |
| commit | bdd36ae2d624bebab7fb6f071738ca7a154fa916 (patch) | |
| tree | e765a3224eee6f19cc6b279729a4fdd8a425bffd /src/core | |
| parent | 123e1439a284716c651eca037b95ba997e6c30db (diff) | |
| download | nng-bdd36ae2d624bebab7fb6f071738ca7a154fa916.tar.gz nng-bdd36ae2d624bebab7fb6f071738ca7a154fa916.tar.bz2 nng-bdd36ae2d624bebab7fb6f071738ca7a154fa916.zip | |
Start of REQ protocol. Still need hook handling and resender.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/socket.c | 38 | ||||
| -rw-r--r-- | src/core/socket.h | 5 |
2 files changed, 36 insertions, 7 deletions
diff --git a/src/core/socket.c b/src/core/socket.c index aabcab7c..8c734591 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -197,8 +197,7 @@ nni_socket_close(nni_socket *sock) // Generally, unless the protocol is blocked trying to perform // writes (e.g. a slow reader on the other side), it should be - // trying to shut things down -- the normal flow is for it to - // close pipes and call nni_sock_rem_pipe(). We wait to give it + // trying to shut things down. We wait to give it // a chance to do so gracefully. nni_mutex_enter(&sock->s_mx); while (nni_list_first(&sock->s_pipes) != NULL) { @@ -419,7 +418,7 @@ nni_socket_listen(nni_socket *sock, const char *addr, nni_endpt **epp, } -static int +int nni_setopt_duration(nni_duration *ptr, const void *val, size_t size) { nni_duration dur; @@ -429,27 +428,52 @@ nni_setopt_duration(nni_duration *ptr, const void *val, size_t size) } memcpy(&dur, val, sizeof (dur)); if (dur < -1) { - return (-EINVAL); + return (NNG_EINVAL); } *ptr = dur; return (0); } -static int +int +nni_setopt_int(int *ptr, const void *val, size_t size) +{ + if (size != sizeof (*ptr)) { + return (NNG_EINVAL); + } + memcpy(ptr, val, sizeof (*ptr)); + return (0); +} + + +int nni_getopt_duration(nni_duration *ptr, void *val, size_t *sizep) { - size_t sz = sizeof (nni_duration); + size_t sz = sizeof (*ptr); + + if (sz > *sizep) { + sz = *sizep; + } + *sizep = sizeof (*ptr); + memcpy(val, ptr, sz); + return (0); +} + +int +nni_getopt_int(int *ptr, void *val, size_t *sizep) +{ + size_t sz = sizeof (*ptr); if (sz > *sizep) { sz = *sizep; } - *sizep = sizeof (nni_duration); + *sizep = sizeof (*ptr); memcpy(val, ptr, sz); return (0); } + static int nni_setopt_buf(nni_msgqueue *mq, const void *val, size_t sz) { diff --git a/src/core/socket.h b/src/core/socket.h index 37a0e5eb..35ddc36c 100644 --- a/src/core/socket.h +++ b/src/core/socket.h @@ -56,4 +56,9 @@ extern int nni_socket_sendmsg(nni_socket *, nni_msg *, nni_time); extern int nni_socket_dial(nni_socket *, const char *, nni_endpt **, int); extern int nni_socket_listen(nni_socket *, const char *, nni_endpt **, int); +extern int nni_setopt_duration(nni_duration *, const void *, size_t); +extern int nni_getopt_duration(nni_duration *, void *, size_t *); +extern int nni_setopt_int(int *, const void *, size_t); +extern int nni_getopt_int(int *, void *, size_t *); + #endif // CORE_SOCKET_H |
