Ejemplo n.º 1
0
        private void InboundProc(InboundProcStartSequenceState state)
        {
            Thread.CurrentThread.Name = "ZmqTransport.InboundProc";
            _logger.DebugFormat("Starting inbound proc...");

            var inboundSocket = CreateInboundSocket(state);

            if (inboundSocket == null)
            {
                return;
            }

            using (inboundSocket)
            {
                while (IsListening)
                {
                    var inputStream = inboundSocket.Receive();
                    if (inputStream == null)
                    {
                        continue;
                    }

                    DeserializeAndForwardTransportMessage(inputStream);
                }

                GracefullyDisconnectInboundSocket(inboundSocket);
            }

            _logger.InfoFormat("InboundProc terminated");
        }
Ejemplo n.º 2
0
        private ZmqInboundSocket CreateInboundSocket(InboundProcStartSequenceState state)
        {
            ZmqInboundSocket inboundSocket = null;

            try
            {
                inboundSocket        = new ZmqInboundSocket(_context, PeerId, _configuredInboundEndPoint, _socketOptions, _environment);
                _realInboundEndPoint = inboundSocket.Bind();
                return(inboundSocket);
            }
            catch (Exception ex)
            {
                state.SetFailed(ex);
                if (inboundSocket != null)
                {
                    inboundSocket.Dispose();
                }

                return(null);
            }
            finally
            {
                state.Release();
            }
        }
Ejemplo n.º 3
0
        public void Start()
        {
            var zmqVersion = ZmqUtil.GetVersion();

            _logger.InfoFormat("Loaded ZMQ v{0}", zmqVersion.ToString(3));

            if (zmqVersion.Major != 4)
            {
                throw new InvalidOperationException($"Expected ZMQ v4.*, loaded ZMQ v{zmqVersion.ToString(3)}");
            }

            _isListening = true;

            _outboundSockets       = new ConcurrentDictionary <PeerId, ZmqOutboundSocket>();
            _outboundSocketActions = new BlockingCollection <OutboundSocketAction>();
            _pendingDisconnects    = new BlockingCollection <PendingDisconnect>();
            _context = new ZmqContext();

            var startSequenceState = new InboundProcStartSequenceState();

            _inboundThread    = BackgroundThread.Start(InboundProc, startSequenceState);
            _outboundThread   = BackgroundThread.Start(OutboundProc);
            _disconnectThread = BackgroundThread.Start(DisconnectProc);

            startSequenceState.Wait();
            _isRunning = true;
        }
Ejemplo n.º 4
0
        public void Start()
        {
            IsListening = true;

            _outboundSockets       = new ConcurrentDictionary <PeerId, ZmqOutboundSocket>();
            _outboundSocketActions = new BlockingCollection <OutboundSocketAction>();
            _pendingDisconnects    = new BlockingCollection <PendingDisconnect>();
            _context = ZmqContext.Create();

            var startSequenceState = new InboundProcStartSequenceState();

            _inboundThread    = BackgroundThread.Start(InboundProc, startSequenceState, null);
            _outboundThread   = BackgroundThread.Start(OutboundProc);
            _disconnectThread = BackgroundThread.Start(DisconnectProc);

            startSequenceState.Wait();
        }