aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2016-12-24 15:08:24 -0800
committerGarrett D'Amore <garrett@damore.org>2016-12-24 15:08:24 -0800
commitcb4fe7294f7da2ad1a2fdf896748b42e1a8115ab (patch)
tree1718afad8387d2dbcebb771d804fb7b5cf4d700b /src
parent9ff00f18a38559f668cb5c27e6d814dddffa801d (diff)
downloadnng-cb4fe7294f7da2ad1a2fdf896748b42e1a8115ab.tar.gz
nng-cb4fe7294f7da2ad1a2fdf896748b42e1a8115ab.tar.bz2
nng-cb4fe7294f7da2ad1a2fdf896748b42e1a8115ab.zip
Getopt implemented (and minimal test).
Diffstat (limited to 'src')
-rw-r--r--src/core/socket.c60
-rw-r--r--src/nng.c12
2 files changed, 62 insertions, 10 deletions
diff --git a/src/core/socket.c b/src/core/socket.c
index f3afb7bb..adf2e082 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -228,16 +228,6 @@ nni_socket_recvmsg(nni_socket *sock, nni_msg **msgp, nni_time expire)
int rv;
nni_msg *msg;
-#if 0
- if (tmout > 0) {
- expire = nni_clock() + tmout;
- } else if (tmout < 0) {
- expire = NNI_TIME_NEVER;
- } else {
- expire = NNI_TIME_ZERO;
- }
-#endif
-
nni_mutex_enter(&sock->s_mx);
if (sock->s_closing) {
nni_mutex_exit(&sock->s_mx);
@@ -567,6 +557,18 @@ nni_setopt_duration(nni_duration *ptr, const void *val, size_t size)
return (0);
}
+static int
+nni_getopt_duration(nni_duration *ptr, void *val, size_t *sizep)
+{
+ size_t sz = sizeof (nni_duration);
+
+ if (sz > *sizep) {
+ sz = *sizep;
+ }
+ *sizep = sizeof (nni_duration);
+ memcpy(val, ptr, sz);
+ return (0);
+}
int
nni_socket_setopt(nni_socket *sock, int opt, const void *val, size_t size)
@@ -603,3 +605,41 @@ nni_socket_setopt(nni_socket *sock, int opt, const void *val, size_t size)
nni_mutex_exit(&sock->s_mx);
return (rv);
}
+
+int
+nni_socket_getopt(nni_socket *sock, int opt, void *val, size_t *sizep)
+{
+ size_t rsz;
+ void *ptr;
+ int rv = ENOTSUP;
+
+ nni_mutex_enter(&sock->s_mx);
+ if (sock->s_ops.proto_getopt != NULL) {
+ rv = sock->s_ops.proto_getopt(sock->s_data, opt, val, sizep);
+ if (rv != NNG_ENOTSUP) {
+ nni_mutex_exit(&sock->s_mx);
+ return (rv);
+ }
+ }
+ switch (opt) {
+ case NNG_OPT_LINGER:
+ rv = nni_getopt_duration(&sock->s_linger, val, sizep);
+ break;
+ case NNG_OPT_SNDTIMEO:
+ rv = nni_getopt_duration(&sock->s_sndtimeo, val, sizep);
+ break;
+ case NNG_OPT_RCVTIMEO:
+ rv = nni_getopt_duration(&sock->s_rcvtimeo, val, sizep);
+ break;
+ case NNG_OPT_RECONN_TIME:
+ rv = nni_getopt_duration(&sock->s_reconn, val, sizep);
+ break;
+ case NNG_OPT_RECONN_MAXTIME:
+ rv = nni_getopt_duration(&sock->s_reconnmax, val, sizep);
+ break;
+ }
+ nni_mutex_exit(&sock->s_mx);
+ return (rv);
+}
+
+
diff --git a/src/nng.c b/src/nng.c
index fc57c037..225bf074 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -83,6 +83,18 @@ nng_setopt(nng_socket *s, int opt, const void *val, size_t sz)
}
+int
+nng_getopt(nng_socket *s, int opt, void *val, size_t *szp)
+{
+ int rv;
+
+ if ((rv == nni_init()) != 0) {
+ return (rv);
+ }
+ return (nni_socket_getopt(s, opt, val, szp));
+}
+
+
// Misc.
const char *
nng_strerror(int num)