public TcpStreamLogic(FlowShape <ByteString, ByteString> shape, ITcpRole role, EndPoint remoteAddress) : base(shape) { _role = role; _remoteAddress = remoteAddress; _bytesIn = shape.Inlet; _bytesOut = shape.Outlet; _readHandler = new LambdaOutHandler( onPull: () => _connection.Tell(Tcp.ResumeReading.Instance, StageActorRef), onDownstreamFinish: () => { if (!IsClosed(_bytesIn)) { _connection.Tell(Tcp.ResumeReading.Instance, StageActorRef); } else { _connection.Tell(Tcp.Abort.Instance, StageActorRef); CompleteStage(); } }); // No reading until role have been decided SetHandler(_bytesOut, onPull: DoNothing); SetHandler(_bytesIn, onPush: () => { var elem = Grab(_bytesIn); ReactiveStreamsCompliance.RequireNonNullElement(elem); _connection.Tell(Tcp.Write.Create(elem, WriteAck.Instance), StageActorRef); }, onUpstreamFinish: () => { // Reading has stopped before, either because of cancel, or PeerClosed, so just Close now // (or half-close is turned off) if (IsClosed(_bytesOut) || !_role.HalfClose) { _connection.Tell(Tcp.Close.Instance, StageActorRef); } // We still read, so we only close the write side else if (_connection != null) { _connection.Tell(Tcp.ConfirmedClose.Instance, StageActorRef); } else { CompleteStage(); } }, onUpstreamFailure: ex => { if (_connection != null) { if (Interpreter.Log.IsDebugEnabled) { Interpreter.Log.Debug( $"Aborting tcp connection to {_remoteAddress} because of upstream failure: {ex.Message}\n{ex.StackTrace}"); } _connection.Tell(Tcp.Abort.Instance, StageActorRef); } else { FailStage(ex); } }); }
public void OnNext(T element) { ReactiveStreamsCompliance.RequireNonNullElement(element); _parent.Tell(new OnNext(_shell, _id, element)); }
/// <summary> /// TBD /// </summary> /// <param name="element">TBD</param> public SingleSource(T element) { ReactiveStreamsCompliance.RequireNonNullElement(element); _element = element; Shape = new SourceShape <T>(Outlet); }
/// <summary> /// TBD /// </summary> /// <param name="task">TBD</param> public TaskSource(Task <T> task) { ReactiveStreamsCompliance.RequireNonNullElement(task); _task = task; Shape = new SourceShape <T>(Outlet); }
public TaskFlattenSource(Task <Source <T, M> > taskSource) { ReactiveStreamsCompliance.RequireNonNullElement(taskSource); _taskSource = taskSource; Shape = new SourceShape <T>(Outlet); }