int zmq::socket_base_t::getsockopt (int option_, void *optval_, size_t *optvallen_) { if (unlikely (ctx_terminated)) { errno = ETERM; return -1; } if (option_ == ZMQ_RCVLABEL) { if (*optvallen_ < sizeof (int)) { errno = EINVAL; return -1; } *((int*) optval_) = rcvlabel ? 1 : 0; *optvallen_ = sizeof (int); return 0; } if (option_ == ZMQ_RCVMORE) { if (*optvallen_ < sizeof (int)) { errno = EINVAL; return -1; } *((int*) optval_) = rcvmore ? 1 : 0; *optvallen_ = sizeof (int); return 0; } if (option_ == ZMQ_FD) { if (*optvallen_ < sizeof (fd_t)) { errno = EINVAL; return -1; } *((fd_t*) optval_) = mailbox.get_fd (); *optvallen_ = sizeof (fd_t); return 0; } if (option_ == ZMQ_EVENTS) { if (*optvallen_ < sizeof (int)) { errno = EINVAL; return -1; } int rc = process_commands (0, false); if (rc != 0 && (errno == EINTR || errno == ETERM)) return -1; errno_assert (rc == 0); *((int*) optval_) = 0; if (has_out ()) *((int*) optval_) |= ZMQ_POLLOUT; if (has_in ()) *((int*) optval_) |= ZMQ_POLLIN; *optvallen_ = sizeof (int); return 0; } return options.getsockopt (option_, optval_, optvallen_); }
int zmq::socket_base_t::getsockopt (int option_, void *optval_, size_t *optvallen_) { if (unlikely (ctx_terminated)) { errno = ETERM; return -1; } // First, check whether specific socket type overloads the option. int rc = xgetsockopt (option_, optval_, optvallen_); if (rc == 0 || errno != EINVAL) return rc; if (option_ == ZMQ_RCVMORE) { if (*optvallen_ < sizeof (int)) { errno = EINVAL; return -1; } *((int*) optval_) = rcvmore ? 1 : 0; *optvallen_ = sizeof (int); return 0; } if (option_ == ZMQ_FD) { if (*optvallen_ < sizeof (fd_t)) { errno = EINVAL; return -1; } *((fd_t*) optval_) = mailbox.get_fd (); *optvallen_ = sizeof (fd_t); return 0; } if (option_ == ZMQ_EVENTS) { if (*optvallen_ < sizeof (int)) { errno = EINVAL; return -1; } int rc = process_commands (0, false); if (rc != 0 && (errno == EINTR || errno == ETERM)) return -1; errno_assert (rc == 0); *((int*) optval_) = 0; if (has_out ()) *((int*) optval_) |= ZMQ_POLLOUT; if (has_in ()) *((int*) optval_) |= ZMQ_POLLIN; *optvallen_ = sizeof (int); return 0; } if (option_ == ZMQ_LAST_ENDPOINT) { if (*optvallen_ < last_endpoint.size () + 1) { errno = EINVAL; return -1; } strcpy (static_cast <char *> (optval_), last_endpoint.c_str ()); *optvallen_ = last_endpoint.size () + 1; return 0; } return options.getsockopt (option_, optval_, optvallen_); }
int zmq::socket_base_t::getsockopt (int option_, void *optval_, size_t *optvallen_) { ENTER_MUTEX(); if (unlikely (ctx_terminated)) { errno = ETERM; EXIT_MUTEX(); return -1; } if (option_ == ZMQ_RCVMORE) { if (*optvallen_ < sizeof (int)) { errno = EINVAL; EXIT_MUTEX(); return -1; } memset(optval_, 0, *optvallen_); *((int*) optval_) = rcvmore ? 1 : 0; *optvallen_ = sizeof (int); EXIT_MUTEX(); return 0; } if (option_ == ZMQ_FD) { if (*optvallen_ < sizeof (fd_t)) { errno = EINVAL; EXIT_MUTEX(); return -1; } if (thread_safe) { // thread safe socket doesn't provide file descriptor errno = EINVAL; EXIT_MUTEX(); return -1; } *((fd_t*)optval_) = ((mailbox_t*)mailbox)->get_fd(); *optvallen_ = sizeof(fd_t); EXIT_MUTEX(); return 0; } if (option_ == ZMQ_EVENTS) { if (*optvallen_ < sizeof (int)) { errno = EINVAL; EXIT_MUTEX(); return -1; } int rc = process_commands (0, false); if (rc != 0 && (errno == EINTR || errno == ETERM)) { EXIT_MUTEX(); return -1; } errno_assert (rc == 0); *((int*) optval_) = 0; if (has_out ()) *((int*) optval_) |= ZMQ_POLLOUT; if (has_in ()) *((int*) optval_) |= ZMQ_POLLIN; *optvallen_ = sizeof (int); EXIT_MUTEX(); return 0; } if (option_ == ZMQ_LAST_ENDPOINT) { if (*optvallen_ < last_endpoint.size () + 1) { errno = EINVAL; EXIT_MUTEX(); return -1; } strcpy (static_cast <char *> (optval_), last_endpoint.c_str ()); *optvallen_ = last_endpoint.size () + 1; EXIT_MUTEX(); return 0; } if (option_ == ZMQ_THREAD_SAFE) { if (*optvallen_ < sizeof (int)) { errno = EINVAL; EXIT_MUTEX(); return -1; } memset(optval_, 0, *optvallen_); *((int*) optval_) = thread_safe ? 1 : 0; *optvallen_ = sizeof (int); EXIT_MUTEX(); return 0; } int rc = options.getsockopt (option_, optval_, optvallen_); EXIT_MUTEX(); return rc; }