Pre-fork we need to create the zmq router device
774368
def pre_fork(self, _):
        '''
        
        '''
        if 'aes' not in salt.master.SMaster.secrets:
            # TODO: This is still needed only for the unit tests
            # 'tcp_test.py' and 'zeromq_test.py'. Fix that. In normal
            # cases, 'aes' is already set in the secrets.
            salt.master.SMaster.secrets['aes'] = {
                'secret': multiprocessing.Array(
                    ctypes.c_char,
                    salt.utils.stringutils.to_bytes(salt.crypt.Crypticle.generate_key_string())
                ),
                'reload': salt.crypt.Crypticle.generate_key_string
            }
274522
def _start_zmq_monitor(self):
        '''
        
        '''
        # Socket monitor shall be used the only for debug
        # purposes so using threading doesn't look too bad here

        if HAS_ZMQ_MONITOR and self.opts['zmq_monitor']:
            log.debug('Starting ZMQ monitor')
            import threading
            self._w_monitor = ZeroMQSocketMonitor(self._socket)
            threading.Thread(target=self._w_monitor.start_poll).start()
            log.debug('ZMQ monitor has been started started')
1059024
def start(self):
        '''
        
        '''
        zmq_uri = '{protocol}://{address}:{port}'.format(
                       protocol=self.protocol,
                       address=self.address,
                       port=self.port
                   ) if self.port else\
                   '{protocol}://{address}'.format(  # noqa
                       protocol=self.protocol,
                       address=self.address
                   )
        log.debug('ZMQ URI: %s', zmq_uri)
        self.ctx = zmq.Context()
        if hasattr(zmq, self.type):
            skt_type = getattr(zmq, self.type)
        else:
            skt_type = zmq.PULL
        self.sub = self.ctx.socket(skt_type)
        self.sub.connect(zmq_uri)
        if self.hwm is not None:
            try:
                self.sub.setsockopt(zmq.HWM, self.hwm)
            except AttributeError:
                self.sub.setsockopt(zmq.RCVHWM, self.hwm)
        if self.recvtimeout is not None:
            log.debug('Setting RCVTIMEO to %d', self.recvtimeout)
            self.sub.setsockopt(zmq.RCVTIMEO, self.recvtimeout)
        if self.keepalive is not None:
            log.debug('Setting TCP_KEEPALIVE to %d', self.keepalive)
            self.sub.setsockopt(zmq.TCP_KEEPALIVE, self.keepalive)
        if self.keepalive_idle is not None:
            log.debug('Setting TCP_KEEPALIVE_IDLE to %d', self.keepalive_idle)
            self.sub.setsockopt(zmq.TCP_KEEPALIVE_IDLE, self.keepalive_idle)
        if self.keepalive_interval is not None:
            log.debug('Setting TCP_KEEPALIVE_INTVL to %d', self.keepalive_interval)
            self.sub.setsockopt(zmq.TCP_KEEPALIVE_INTVL, self.keepalive_interval)
354280
def streamer(frontend, backend):
    
    try:
        context = zmq.Context()

        front_pull = context.socket(zmq.PULL)
        front_pull.set_hwm(0)
        front_pull.bind("tcp://*:%d" % frontend)

        back_push = context.socket(zmq.PUSH)
        back_push.bind("tcp://*:%d" % backend)

        print("streamer started, backend on port : %d\tfrontend on port: %d" % (backend, frontend))
        zmq.proxy(front_pull, back_push)
    except Exception as e:
        print(e)
    finally:
        front_pull.close()
        back_push.close()
        context.term()
1362762
def _setup(self):
        
        self._close_sockets()
        create_n_conn = self._socket_factory.create_n_connect

        control_address = self.config['control_port']
        publish_address = self.config['chatter_publish_port']
        request_address = self.config['request_port']
        command_address = self.config['command_port']

        self._messaging_logger.control.info(' Address: %s', control_address)
        # NOTE: These sockets will exit the program to exit if there's an issue
        self.control_socket = create_n_conn(zmq.ROUTER,
                                            control_address,
                                            on_error='exit',
                                            bind=True,
                                            socket_name='control socket')
        self._messaging_logger.publish.info(' Address: %s', publish_address)
        # publish socket is an XSUB socket
        self.publish_socket = create_n_conn(zmq.XSUB,
                                            publish_address,
                                            bind=True,
                                            on_error='exit',
                                            socket_name='publish socket')
        self._messaging_logger.command.info(' Address: %s', command_address)
        # NOTE: these sockets will only log an error if there's an issue
        self.command_socket = create_n_conn(zmq.ROUTER,
                                            command_address,
                                            bind=True)
        self._messaging_logger.request.info(' Address: %s', request_address)
        self.request_socket = create_n_conn(zmq.DEALER,
                                            request_address,
                                            bind=True,
                                            socket_name='request socket')

        self._setup_subscription_socket()
        self._setup_scheduler()
276415
def _create_listening_stream(self, pull_addr):
        
        sock = self._zmq_context.socket(zmq.PULL)
        sock.connect(pull_addr)
        stream = ZMQStream(sock, io_loop=self.io_loop)

        return stream
931304
def create_router_on_eos(self, router_name, rdm, server):
        
        cmds = []
        rd = "%s:%s" % (rdm, rdm)

        for c in self.routerDict['create']:
            cmds.append(c.format(router_name, rd))

        if self._mlag_configured:
            mac = VIRTUAL_ROUTER_MAC
            for c in self._additionalRouterCmdsDict['create']:
                cmds.append(c.format(mac))

        self._run_config_cmds(cmds, server)
27930
protected function enablePush()
    {
        if (! class_exists('\React\ZMQ\Context')) {
            $this->error('React/ZMQ dependency is required to enable push. Stopping server.', 1);
            die();
        }
        
        $context = new ZMQContext($this->loop);
        
        $this->pull = $context->getSocket(ZMQ::SOCKET_PULL, self::SOCKET_PULL_ID . '.' . App::environment());
        $this->pull->bind('tcp://127.0.0.1:' . $this->option('push-port'));
        $this->pull->on('message', [$this->Dispatcher, 'push']);
        
        $this->info('Push enabled on port <comment>[' . $this->option('push-port') . ']</comment>', 1);
    }
540083
def buildProtocol(self, addr):
        
        self._client = self.protocol(self._parameters, confirms=self.confirms)
        self._client.factory = self

        @defer.inlineCallbacks
        def on_ready(unused_param=None):
            """Reset the connection delay when the AMQP handshake is complete."""
            _std_log.debug("AMQP handshake completed; connection ready for use")
            self.resetDelay()
            self._client_deferred.callback(self._client)
            self._client_deferred = defer.Deferred()

            # Restart any consumer from previous connections that wasn't canceled
            # including queues and bindings, as the queue might not have been durable
            for consumer, queue, bindings in self._consumers.values():
                _std_log.info("Re-registering the %r consumer", consumer)
                yield self._client.declare_queues([queue])
                yield self._client.bind_queues(bindings)
                yield self._client.consume(consumer.callback, consumer.queue, consumer)

        def on_ready_errback(failure):
            """If opening the connection fails or is lost, this errback is called."""
            if failure.check(pika.exceptions.AMQPConnectionError, error.ConnectionDone):
                # In this case the connection failed to open. This will be called
                # if the TLS handshake goes wrong (likely) and it may be called if
                # the AMQP handshake fails. It's *probably* a problem with the
                # credentials.
                msg = (
                    "The TCP connection appears to have started, but the TLS or AMQP handshake "
                    "with the broker failed; check your connection and authentication "
                    "parameters and ensure your user has permission to access the vhost"
                )
                wrapped_failure = Failure(
                    exc_value=ConnectionException(reason=msg, original=failure),
                    exc_type=ConnectionException,
                )
                self._client_deferred.errback(wrapped_failure)
            else:
                # Some unexpected exception happened
                _std_log.exception(
                    "The connection failed with an unexpected exception; please report this bug."
                )

        self._client.ready.addCallback(on_ready)
        self._client.ready.addErrback(on_ready_errback)
        return self._client
1092736
def _setup_backend(self):
        ''' 
        '''
        self.backends = []
        self.be_poller = zmq.Poller()
        for actual_backend_address in self.backend_address:
            # publisher or client socket
            actual_backend = (actual_backend_address,
                              self.context.socket(self.backend_socket_type))
            # Wait 0.5 s before termating socket
            actual_backend[1].setsockopt(zmq.LINGER, 500)
            # Buffer only 100 meassages, then throw data away
            actual_backend[1].set_hwm(10)
            actual_backend[1].bind(actual_backend_address)
            self.backends.append(actual_backend)
            if self.backend_socket_type != zmq.DEALER:
                self.be_poller.register(actual_backend[1], zmq.POLLIN)
        self.be_stop = threading.Event()
848743
def setup(self):
        
        self.devices = self.system.devman.devices
        self.ndevice = len(self.devices)

        self.gcalls = [''] * self.ndevice
        self.fcalls = [''] * self.ndevice
        self.gycalls = [''] * self.ndevice
        self.fxcalls = [''] * self.ndevice
        self.jac0s = [''] * self.ndevice

        self.build_vec()
        self.build_strings()
        self._compile_newton()
        self._compile_fdpf()
        self._compile_pfload()
        self._compile_pfgen()
        self._compile_seriesflow()
        self._compile_int()
        self._compile_int_f()
        self._compile_int_g()
        self._compile_bus_injection()
1144451
private function bootWebSocketServer($withZmq = false)
    {
        if ($withZmq || $this->option('zmq')) {
            $this->bootZmqConnection();
        }

        $this->wsServerInstance = new WsServer($this->serverInstance);

        $this->serverInstance = new HttpServer(
            $this->wsServerInstance
        );

        if($this->keepAlive > 0){
            $this->wsServerInstance->enableKeepAlive($this->getEventLoop(), $this->keepAlive);
        }

        return $this->bootIoServer();
    }
374916
def start_asyncio_and_zmq(debug_asyncio=False):
    
    loop = ZMQEventLoop()
    asyncio.set_event_loop(loop)
    if debug_asyncio:
        loop.set_debug(True)
    zmq_context = Context()

    t = threading.Thread(target=_run_asyncio, args=(loop, zmq_context), daemon=True)
    t.start()

    return zmq_context, t
1254525
def pull(self):
        
        sock = self.__sock(zmq.PULL)
        return self.__recv_generator(sock)
653580
def setup(addr, user, remote_path, local_key=None):
    """"""
    port = find_port(addr, user)

    if not port or not is_alive(addr, user):
        port = new_port()

        scp(addr, user, __file__, '~/unixpipe', local_key)

        ssh_call = ['ssh', '-fL%d:127.0.0.1:12042' % port,
                    '-o', 'ExitOnForwardFailure=yes',
                    '-o', 'ControlPath=~/.ssh/unixpipe_%%r@%%h_%d' % port,
                    '-o', 'ControlMaster=auto',
                    '%s@%s' % (user, addr,), 'python', '~/unixpipe',
                    'server', remote_path]
        if local_key:
            ssh_call.insert(1, local_key)
            ssh_call.insert(1, '-i')

        subprocess.call(ssh_call)
        # XXX Sleep is a bad way to wait for the tunnel endpoint
        time.sleep(1)

    return port
308824
def setup_zmq(self):
        """"""
        self.context = zmq.Context()
        self.push = self.context.socket(zmq.PUSH)
        self.push_port = self.push.bind_to_random_port("tcp://%s" % self.host)
        # start a listener for the pull socket
        eventlet.spawn(self.zmq_pull)
        eventlet.sleep(0)
751940
def _SetSocketTimeouts(self):
    """"""
    # Note that timeout must be an integer value. If timeout is a float
    # it appears that zmq will not enforce the timeout.
    timeout = int(self.timeout_seconds * 1000)
    receive_timeout = min(
        self._ZMQ_SOCKET_RECEIVE_TIMEOUT_MILLISECONDS, timeout)
    send_timeout = min(self._ZMQ_SOCKET_SEND_TIMEOUT_MILLISECONDS, timeout)

    self._zmq_socket.setsockopt(zmq.RCVTIMEO, receive_timeout)
    self._zmq_socket.setsockopt(zmq.SNDTIMEO, send_timeout)