void zmq::tune_ofi_keepalives (fd_t s_, int keepalive_, int keepalive_cnt_, int keepalive_idle_, int keepalive_intvl_) { // These options are used only under certain #ifdefs below. LIBZMQ_UNUSED (keepalive_); LIBZMQ_UNUSED (keepalive_cnt_); LIBZMQ_UNUSED (keepalive_idle_); LIBZMQ_UNUSED (keepalive_intvl_); // If none of the #ifdefs apply, then s_ is unused. LIBZMQ_UNUSED (s_); // Tuning OFI keep-alives if platform allows it // All values = -1 means skip and leave it for OS #ifdef ZMQ_HAVE_WINDOWS if (keepalive_ != -1) { ofi_keepalive keepalive_opts; keepalive_opts.onoff = keepalive_; keepalive_opts.keepalivetime = keepalive_idle_ != -1 ? keepalive_idle_ * 1000 : 7200000; keepalive_opts.keepaliveinterval = keepalive_intvl_ != -1 ? keepalive_intvl_ * 1000 : 1000; DWORD num_bytes_returned; int rc = WSAIoctl(s_, SIO_KEEPALIVE_VALS, &keepalive_opts, sizeof(keepalive_opts), NULL, 0, &num_bytes_returned, NULL, NULL); wsa_assert (rc != SOCKET_ERROR); } #else #ifdef ZMQ_HAVE_SO_KEEPALIVE if (keepalive_ != -1) { int rc = setsockopt (s_, SOL_SOCKET, SO_KEEPALIVE, (char*) &keepalive_, sizeof (int)); errno_assert (rc == 0); #ifdef ZMQ_HAVE_OFI_KEEPCNT if (keepalive_cnt_ != -1) { int rc = setsockopt (s_, IPPROTO_TCP, OFI_KEEPCNT, &keepalive_cnt_, sizeof (int)); errno_assert (rc == 0); } #endif // ZMQ_HAVE_OFI_KEEPCNT #ifdef ZMQ_HAVE_OFI_KEEPIDLE if (keepalive_idle_ != -1) { int rc = setsockopt (s_, IPPROTO_TCP, OFI_KEEPIDLE, &keepalive_idle_, sizeof (int)); errno_assert (rc == 0); } #else // ZMQ_HAVE_OFI_KEEPIDLE #ifdef ZMQ_HAVE_OFI_KEEPALIVE if (keepalive_idle_ != -1) { int rc = setsockopt (s_, IPPROTO_TCP, OFI_KEEPALIVE, &keepalive_idle_, sizeof (int)); errno_assert (rc == 0); } #endif // ZMQ_HAVE_OFI_KEEPALIVE #endif // ZMQ_HAVE_OFI_KEEPIDLE #ifdef ZMQ_HAVE_OFI_KEEPINTVL if (keepalive_intvl_ != -1) { int rc = setsockopt (s_, IPPROTO_TCP, OFI_KEEPINTVL, &keepalive_intvl_, sizeof (int)); errno_assert (rc == 0); } #endif // ZMQ_HAVE_OFI_KEEPINTVL } #endif // ZMQ_HAVE_SO_KEEPALIVE #endif // ZMQ_HAVE_WINDOWS }
void zmq::thread_t::setSchedulingParameters ( int priority_, int schedulingPolicy_, const std::set<int> &affinity_cpus_) { // not implemented LIBZMQ_UNUSED (priority_); LIBZMQ_UNUSED (schedulingPolicy_); LIBZMQ_UNUSED (affinity_cpus_); }
// On other platforms we assume there are no sane interface names. // This is true especially of Windows. int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_src_) { LIBZMQ_UNUSED (nic_); LIBZMQ_UNUSED (ipv6_); errno = ENODEV; return -1; }
// On other platforms we assume there are no sane interface names. int zmq::ip_resolver_t::resolve_nic_name (ip_addr_t *ip_addr_, const char *nic_) { LIBZMQ_UNUSED (ip_addr_); LIBZMQ_UNUSED (nic_); errno = ENODEV; return -1; }
void zmq::pull_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_, bool locally_initiated_) { LIBZMQ_UNUSED (subscribe_to_all_); LIBZMQ_UNUSED (locally_initiated_); zmq_assert (pipe_); _fq.attach (pipe_); }
void zmq::xsub_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_, bool locally_initiated_) { LIBZMQ_UNUSED (subscribe_to_all_); LIBZMQ_UNUSED (locally_initiated_); zmq_assert (pipe_); _fq.attach (pipe_); _dist.attach (pipe_); // Send all the cached subscriptions to the new upstream peer. _subscriptions.apply (send_subscription, pipe_); pipe_->flush (); }
void zmq::gather_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) { LIBZMQ_UNUSED (subscribe_to_all_); zmq_assert (pipe_); _fq.attach (pipe_); }
void zmq::dgram_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_, bool locally_initiated_) { LIBZMQ_UNUSED (subscribe_to_all_); LIBZMQ_UNUSED (locally_initiated_); zmq_assert (pipe_); // ZMQ_DGRAM socket can only be connected to a single peer. // The socket rejects any further connection requests. if (_pipe == NULL) _pipe = pipe_; else pipe_->terminate (false); }
void zmq::router_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) { LIBZMQ_UNUSED (subscribe_to_all_); zmq_assert (pipe_); if (probe_router) { msg_t probe_msg_; int rc = probe_msg_.init (); errno_assert (rc == 0); rc = pipe_->write (&probe_msg_); // zmq_assert (rc) is not applicable here, since it is not a bug. pipe_->flush (); rc = probe_msg_.close (); errno_assert (rc == 0); } bool identity_ok = identify_peer (pipe_); if (identity_ok) fq.attach (pipe_); else anonymous_pipes.insert (pipe_); }
void zmq::bind_to_device (fd_t s_, std::string &bound_device_) { #ifdef ZMQ_HAVE_SO_BINDTODEVICE int rc = setsockopt (s_, SOL_SOCKET, SO_BINDTODEVICE, bound_device_.c_str (), bound_device_.length ()); #ifdef ZMQ_HAVE_WINDOWS wsa_assert (rc != SOCKET_ERROR); #else errno_assert (rc == 0); #endif #else LIBZMQ_UNUSED (s_); LIBZMQ_UNUSED (bound_device_); #endif }
int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_src_) { // TODO: Unused parameter, IPv6 support not implemented for AIX or HP/UX. LIBZMQ_UNUSED (ipv6_); // Create a socket. const int sd = open_socket (AF_INET, SOCK_DGRAM, 0); errno_assert (sd != -1); struct ifreq ifr; // Copy interface name for ioctl get. strncpy (ifr.ifr_name, nic_, sizeof ifr.ifr_name); // Fetch interface address. const int rc = ioctl (sd, SIOCGIFADDR, (caddr_t) &ifr, sizeof ifr); // Clean up. close (sd); if (rc == -1) { errno = ENODEV; return -1; } if (is_src_) memcpy (&source_address.ipv4.sin_addr, &((sockaddr_in*) &ifr.ifr_addr)->sin_addr, sizeof (struct in_addr)); else memcpy (&address.ipv4.sin_addr, &((sockaddr_in*) &ifr.ifr_addr)->sin_addr, sizeof (struct in_addr)); return 0; }
int zmq::radio_t::xrecv (msg_t *msg_) { // Messages cannot be received from PUB socket. LIBZMQ_UNUSED (msg_); errno = ENOTSUP; return -1; }
// On Solaris platform, network interface name can be queried by ioctl. int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_src_) { // TODO: Unused parameter, IPv6 support not implemented for Solaris. LIBZMQ_UNUSED (ipv6_); // Create a socket. const int fd = open_socket (AF_INET, SOCK_DGRAM, 0); errno_assert (fd != -1); // Retrieve number of interfaces. lifnum ifn; ifn.lifn_family = AF_INET; ifn.lifn_flags = 0; int rc = ioctl (fd, SIOCGLIFNUM, (char*) &ifn); errno_assert (rc != -1); // Allocate memory to get interface names. const size_t ifr_size = sizeof (struct lifreq) * ifn.lifn_count; char *ifr = (char*) malloc (ifr_size); alloc_assert (ifr); // Retrieve interface names. lifconf ifc; ifc.lifc_family = AF_INET; ifc.lifc_flags = 0; ifc.lifc_len = ifr_size; ifc.lifc_buf = ifr; rc = ioctl (fd, SIOCGLIFCONF, (char*) &ifc); errno_assert (rc != -1); // Find the interface with the specified name and AF_INET family. bool found = false; lifreq *ifrp = ifc.lifc_req; for (int n = 0; n < (int) (ifc.lifc_len / sizeof (lifreq)); n ++, ifrp ++) { if (!strcmp (nic_, ifrp->lifr_name)) { rc = ioctl (fd, SIOCGLIFADDR, (char*) ifrp); errno_assert (rc != -1); if (ifrp->lifr_addr.ss_family == AF_INET) { if (is_src_) source_address.ipv4 = *(sockaddr_in*) &ifrp->lifr_addr; else address.ipv4 = *(sockaddr_in*) &ifrp->lifr_addr; found = true; break; } } } // Clean-up. free (ifr); close (fd); if (!found) { errno = ENODEV; return -1; } return 0; }
virtual void timer_event (int id_) { LIBZMQ_UNUSED (id_); poller.rm_fd (handle); handle = (zmq::poller_t::handle_t) NULL; // this must only be incremented after rm_fd timer_events.add (1); }
void zmq::client_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) { LIBZMQ_UNUSED (subscribe_to_all_); zmq_assert (pipe_); fq.attach (pipe_); lb.attach (pipe_); }
void zmq::stream_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) { LIBZMQ_UNUSED (subscribe_to_all_); zmq_assert (pipe_); identify_peer (pipe_); fq.attach (pipe_); }
void zmq::thread_t::setSchedulingParameters(int priority_, int schedulingPolicy_) { #if defined _POSIX_THREAD_PRIORITY_SCHEDULING && _POSIX_THREAD_PRIORITY_SCHEDULING >= 0 int policy = 0; struct sched_param param; #if _POSIX_THREAD_PRIORITY_SCHEDULING == 0 && defined _SC_THREAD_PRIORITY_SCHEDULING if (sysconf(_SC_THREAD_PRIORITY_SCHEDULING) < 0) { return; } #endif int rc = pthread_getschedparam(descriptor, &policy, ¶m); posix_assert (rc); if(priority_ != -1) { param.sched_priority = priority_; } if(schedulingPolicy_ != -1) { policy = schedulingPolicy_; } #ifdef __NetBSD__ if(policy == SCHED_OTHER) param.sched_priority = -1; #endif rc = pthread_setschedparam(descriptor, policy, ¶m); #if defined(__FreeBSD_kernel__) || defined (__FreeBSD__) // If this feature is unavailable at run-time, don't abort. if(rc == ENOSYS) return; #endif posix_assert (rc); #else LIBZMQ_UNUSED (priority_); LIBZMQ_UNUSED (schedulingPolicy_); #endif }
void zmq::scatter_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) { LIBZMQ_UNUSED (subscribe_to_all_); // Don't delay pipe termination as there is no one // to receive the delimiter. pipe_->set_nodelay (); zmq_assert (pipe_); lb.attach (pipe_); }
void close_fdpair (zmq::fd_t w, zmq::fd_t r) { int rc = closesocket (w); TEST_ASSERT_EQUAL_INT (0, rc); #if !defined ZMQ_HAVE_EVENTFD rc = closesocket (r); TEST_ASSERT_EQUAL_INT (0, rc); #else LIBZMQ_UNUSED (r); #endif }
void zmq::dish_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) { LIBZMQ_UNUSED (subscribe_to_all_); zmq_assert (pipe_); fq.attach (pipe_); dist.attach (pipe_); // Send all the cached subscriptions to the new upstream peer. send_subscriptions (pipe_); }
void zmq::server_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) { LIBZMQ_UNUSED(subscribe_to_all_); zmq_assert (pipe_); uint32_t routing_id = next_rid++; pipe_->set_routing_id (routing_id); // Add the record into output pipes lookup table outpipe_t outpipe = {pipe_, true}; bool ok = outpipes.insert (outpipes_t::value_type (routing_id, outpipe)).second; zmq_assert (ok); fq.attach (pipe_); }
int zmq::plain_client_t::process_welcome ( const unsigned char *cmd_data, size_t data_size) { LIBZMQ_UNUSED (cmd_data); if (state != waiting_for_welcome) { errno = EPROTO; return -1; } if (data_size != 8) { errno = EPROTO; return -1; } state = sending_initiate; return 0; }
void zmq::server_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) { LIBZMQ_UNUSED (subscribe_to_all_); zmq_assert (pipe_); uint32_t routing_id = next_routing_id++; if (!routing_id) routing_id = next_routing_id++; // Never use Routing ID zero pipe_->set_server_socket_routing_id (routing_id); // Add the record into output pipes lookup table outpipe_t outpipe = {pipe_, true}; bool ok = outpipes.ZMQ_MAP_INSERT_OR_EMPLACE (routing_id, outpipe).second; zmq_assert (ok); fq.attach (pipe_); }
void zmq::enable_ipv4_mapping (fd_t s_) { LIBZMQ_UNUSED (s_); #if defined IPV6_V6ONLY && !defined ZMQ_HAVE_OPENBSD #ifdef ZMQ_HAVE_WINDOWS DWORD flag = 0; #else int flag = 0; #endif int rc = setsockopt (s_, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast<char *> (&flag), sizeof (flag)); #ifdef ZMQ_HAVE_WINDOWS wsa_assert (rc != SOCKET_ERROR); #else errno_assert (rc == 0); #endif #endif }
void zmq::make_socket_noninheritable (fd_t sock_) { #if defined ZMQ_HAVE_WINDOWS && !defined _WIN32_WCE \ && !defined ZMQ_HAVE_WINDOWS_UWP // On Windows, preventing sockets to be inherited by child processes. const BOOL brc = SetHandleInformation (reinterpret_cast<HANDLE> (sock_), HANDLE_FLAG_INHERIT, 0); win_assert (brc); #elif (!defined ZMQ_HAVE_SOCK_CLOEXEC || !defined HAVE_ACCEPT4) \ && defined FD_CLOEXEC // If there 's no SOCK_CLOEXEC, let's try the second best option. // Race condition can cause socket not to be closed (if fork happens // between accept and this point). const int rc = fcntl (sock_, F_SETFD, FD_CLOEXEC); errno_assert (rc != -1); #else LIBZMQ_UNUSED (sock_); #endif }
int zmq::set_nosigpipe (fd_t s_) { #ifdef SO_NOSIGPIPE // Make sure that SIGPIPE signal is not generated when writing to a // connection that was already closed by the peer. // As per POSIX spec, EINVAL will be returned if the socket was valid but // the connection has been reset by the peer. Return an error so that the // socket can be closed and the connection retried if necessary. int set = 1; int rc = setsockopt (s_, SOL_SOCKET, SO_NOSIGPIPE, &set, sizeof (int)); if (rc != 0 && errno == EINVAL) return -1; errno_assert (rc == 0); #else LIBZMQ_UNUSED (s_); #endif return 0; }
void zmq::radio_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) { LIBZMQ_UNUSED (subscribe_to_all_); zmq_assert (pipe_); // Don't delay pipe termination as there is no one // to receive the delimiter. pipe_->set_nodelay (); dist.attach (pipe_); if (subscribe_to_all_) udp_pipes.push_back (pipe_); // The pipe is active when attached. Let's read the subscriptions from // it, if any. else xread_activated (pipe_); }
int zmq::tune_tcp_maxrt (fd_t sockfd_, int timeout_) { if (timeout_ <= 0) return 0; LIBZMQ_UNUSED (sockfd_); #if defined (ZMQ_HAVE_WINDOWS) && defined (TCP_MAXRT) // msdn says it's supported in >= Vista, >= Windows Server 2003 timeout_ /= 1000; // in seconds int rc = setsockopt (sockfd_, IPPROTO_TCP, TCP_MAXRT, (char*) &timeout_, sizeof (timeout_)); tcp_assert_tuning_error (sockfd_, rc); return rc; // FIXME: should be ZMQ_HAVE_TCP_USER_TIMEOUT #elif defined (TCP_USER_TIMEOUT) int rc = setsockopt (sockfd_, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout_, sizeof (timeout_)); tcp_assert_tuning_error (sockfd_, rc); return rc; #endif return 0; }
void zmq::tcp_tune_loopback_fast_path (const fd_t socket_) { #if defined ZMQ_HAVE_WINDOWS && defined SIO_LOOPBACK_FAST_PATH int sio_loopback_fastpath = 1; DWORD numberOfBytesReturned = 0; int rc = WSAIoctl (socket_, SIO_LOOPBACK_FAST_PATH, &sio_loopback_fastpath, sizeof sio_loopback_fastpath, NULL, 0, &numberOfBytesReturned, 0, 0); if (SOCKET_ERROR == rc) { DWORD lastError = ::WSAGetLastError (); if (WSAEOPNOTSUPP == lastError) { // This system is not Windows 8 or Server 2012, and the call is not supported. } else { wsa_assert (false); } } #else LIBZMQ_UNUSED (socket_); #endif }
void zmq::thread_t::setThreadName(const char *name_) { // not implemented LIBZMQ_UNUSED (name_); }