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"); }
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(); } }
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; }
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(); }