public void Stop() { lock (protocolOperationsLock) { if (this.exceptionsStream == null) { return; } this.protocol?.Dispose(); this.protocol = null; this.exceptionsStream.Close(); this.exceptionsStream = null; } ProcessClosingMessage(); this.OnDisposed?.Invoke(this); this.OnDisposed = null; }
public TestClient( string host, int port, bool ssl, Type[] eventTypes, Action <object> onMessageRecived, Func <object, object> onMessageRequestRecived, IPXProtocol protocol = null ) { this.eventTypes = eventTypes; this.host = host != "0.0.0.0" ? host : "127.0.0.1"; this.port = port; this.ssl = ssl; this.onMessageRecived = onMessageRecived; this.onMessageRequestReceived = onMessageRequestRecived; this.protocol = protocol ?? new PXReliableDeliveryProtocol(); this.protocol.Initialize(this); this.protocol.StartReading(); }
public void SetupStream(Stream stream) { lock (protocolOperationsLock) { if (this.protocol == null) { this.protocol = protocolFactory(); this.protocol.Initialize(this); async void StartProtocolReading() { await HandleProtocolExceptionsAction(async delegate { await protocol.StartReading(); }); } StartProtocolReading(); } var state = this.protocol.GetState(); if (state == PXProtocolState.Working) { this.exceptionsStream?.SwitchToErrorState(); this.exceptionsStream?.Close(); } switch (state) { case PXProtocolState.None: case PXProtocolState.WaitingForConnection: case PXProtocolState.Working: this.protocol.SetupStream(exceptionsStream = new PXExceptionsFilterStream(stream)); break; default: throw new StreamSetupInWrongProtocolStateException(state); } } }