public NRStream(AppConnection connection) { CanRead = true; CanWrite = true; CanSeek = false; Length = -1; Connection = connection; IsOpen = true; Pipeline = new Pipe(); }
public static async Task StandardSocketControlHandler(Packet packet) { var pa = new TcpCSSocketControl(packet); var ep = ((EntryPoint)packet.Connection.Ref); Log.Debug("Socket Control Detail for socket {Socket}: [{Flags}] {Extra}", pa.SocketId, pa.ReadableFlags, pa.InstanceId); AppConnection x = null; ep.Connections.TryGetValue(AppConnection.IdToString(pa.SocketId), out x); StoredApp app = null; if (pa.CheckFlag(TcpCSSocketControl.OpenRequest)) { if (x == null) { x = new AppConnection(pa.InstanceId, ep); x.SocketId = pa.SocketId; } else { x.Loopback = true; Log.Debug("Connection {Sid} switched to loopback mode", pa.SocketId); } app = ep._registeredApps.FirstOrDefault(e => e.InstanceId.SequenceEqual(x.InstanceId)); ep.Connections.Add(AppConnection.IdToString(pa.SocketId), x); await app.Callback(x); } if (x == null) { return; } if (pa.CheckFlag(TcpCSSocketControl.Ready)) { x.Open = true; x.ConnectCompletionSource.SetResult(true); } if (pa.CheckFlag(TcpCSSocketControl.Close)) { if (!x.Open) { x.ConnectCompletionSource.SetResult(false); } _ = Task.Run(async() => { await Task.Delay(500); await x.Close(); }); } }
public static async Task StandardDataHandler(Packet packet) { TcpCSSocketData data = new TcpCSSocketData(packet); var ep = ((EntryPoint)packet.Connection.Ref); AppConnection x = null; ep.Connections.TryGetValue(AppConnection.IdToString(data.SocketId), out x); if (x == null) { return; } Log.Debug("Signatures for {Pid}: {StartSig} {EndSig}", packet.PacketId, data.SocketData.Take(10).ToArray(), data.SocketData.TakeLast(10).ToArray()); await x.Stream.Pipeline.Writer.WriteAsync(data.SocketData); }