public SourceConnectionClient(TcpClient client) { this.Client = client; var stream = client.GetStream(); this.Stream = new ConnectionStream(stream, stream); this.Stream.ReadTimeout = 10000; this.Stream.WriteTimeout = 10000; }
public SourceConnectionClient(TcpClient client) { this.Client = client; this.Client.NoDelay = true; this.Client.ReceiveBufferSize = 256 * 1024; this.Client.SendBufferSize = 256 * 1024; var stream = client.GetStream(); this.Stream = new ConnectionStream(client.Client, stream); this.Stream.ReadTimeout = 10000; this.Stream.WriteTimeout = 10000; }
private async Task <(TcpClient, IOutputStream)> CreateMatchedHandler( TcpClient client, NetworkStream stream, AccessControlInfo acinfo, CancellationToken cancellationToken) { var output_factories = PeerCast.OutputStreamFactories.OrderBy(factory => factory.Priority); var header = new byte[4096]; int offset = 0; using (var cancel_source = new CancellationTokenSource(TimeSpan.FromMilliseconds(3000))) using (cancellationToken.Register(() => stream.Close(), false)) using (cancel_source.Token.Register(() => stream.Close(), false)) { try { while (offset < header.Length) { var len = await stream.ReadAsync(header, offset, header.Length - offset, cancellationToken).ConfigureAwait(false); if (len == 0) { break; } offset += len; var header_ary = header.Take(offset).ToArray(); foreach (var factory in output_factories) { var channel_id = factory.ParseChannelID(header_ary, acinfo); if (channel_id.HasValue) { if (factory.Name == "PCPGiv") { PeerCast.AddGivSocket(channel_id.Value, client.Client.AddressFamily, client.Client); return(null, factory.Create(null, acinfo, channel_id.Value)); } else { var connection = new ConnectionStream(client.Client, stream, header_ary); return(client, factory.Create(connection, acinfo, channel_id.Value)); } } } } } catch (ObjectDisposedException) { } catch (IOException) { } } logger.Debug("CreateMatchedHandle returning null"); return(client, null); }
/// <summary> /// 元になるストリーム、チャンネル、リクエストからHTTPOutputStreamを初期化します /// </summary> /// <param name="peercast">所属するPeerCast</param> /// <param name="connection">元になるストリーム</param> /// <param name="access_control">接続可否および認証の情報</param> /// <param name="channel">所属するチャンネル。無い場合はnull</param> public OutputStreamBase( PeerCast peercast, ConnectionStream connection, AccessControlInfo access_control, Channel channel) { this.Logger = new Logger(this.GetType(), connection.RemoteEndPoint?.ToString() ?? ""); this.Connection = connection; this.Connection.ReadTimeout = 10000; this.Connection.WriteTimeout = 10000; this.PeerCast = peercast; this.AccessControlInfo = access_control; this.Channel = channel; this.IsLocal = (RemoteEndPoint as IPEndPoint)?.Address?.IsSiteLocal() ?? true; }
/// <summary> /// 元になるストリーム、チャンネル、リクエストからHTTPOutputStreamを初期化します /// </summary> /// <param name="peercast">所属するPeerCast</param> /// <param name="input_stream">元になる受信ストリーム</param> /// <param name="output_stream">元になる送信ストリーム</param> /// <param name="remote_endpoint">接続先のアドレス</param> /// <param name="access_control">接続可否および認証の情報</param> /// <param name="channel">所属するチャンネル。無い場合はnull</param> /// <param name="request">クライアントからのリクエスト</param> public OutputStreamBase( PeerCast peercast, Stream input_stream, Stream output_stream, EndPoint remote_endpoint, AccessControlInfo access_control, Channel channel, byte[] header) { this.Logger = new Logger(this.GetType()); this.connection = new ConnectionStream( header!=null && header.Length>0 ? new PrependedStream(header, input_stream) : input_stream, output_stream); this.connection.ReadTimeout = 10000; this.connection.WriteTimeout = 10000; this.PeerCast = peercast; this.RemoteEndPoint = remote_endpoint; this.AccessControlInfo = access_control; this.Channel = channel; var ip = remote_endpoint as IPEndPoint; this.IsLocal = ip!=null ? ip.Address.IsSiteLocal() : true; }
/// <summary> /// 元になるストリーム、チャンネル、リクエストからHTTPOutputStreamを初期化します /// </summary> /// <param name="peercast">所属するPeerCast</param> /// <param name="input_stream">元になる受信ストリーム</param> /// <param name="output_stream">元になる送信ストリーム</param> /// <param name="remote_endpoint">接続先のアドレス</param> /// <param name="access_control">接続可否および認証の情報</param> /// <param name="channel">所属するチャンネル。無い場合はnull</param> /// <param name="request">クライアントからのリクエスト</param> public OutputStreamBase( PeerCast peercast, Stream input_stream, Stream output_stream, EndPoint remote_endpoint, AccessControlInfo access_control, Channel channel, byte[] header) { this.Logger = new Logger(this.GetType(), remote_endpoint != null ? remote_endpoint.ToString() : ""); this.connection = new ConnectionStream( header != null && header.Length > 0 ? new PrependedStream(header, input_stream) : input_stream, output_stream); this.connection.ReadTimeout = 10000; this.connection.WriteTimeout = 10000; this.PeerCast = peercast; this.RemoteEndPoint = remote_endpoint; this.AccessControlInfo = access_control; this.Channel = channel; var ip = remote_endpoint as IPEndPoint; this.IsLocal = ip != null?ip.Address.IsSiteLocal() : true; }
public RTMPOutputStream( PeerCast peercast, System.IO.Stream input_stream, System.IO.Stream output_stream, System.Net.EndPoint remote_endpoint, AccessControlInfo access_control, Guid channel_id, byte[] header) { input_stream.ReadTimeout = System.Threading.Timeout.Infinite; this.peerCast = peercast; var stream = new ConnectionStream(new BufferedReadStream(input_stream, 8192, header), output_stream); this.inputStream = stream; this.outputStream = stream; stream.WriteTimeout = 10000; this.remoteEndPoint = remote_endpoint; this.accessControl = access_control; this.connection = new RTMPPlayConnection(this, this.inputStream, this.outputStream); }
public abstract IOutputStream Create( ConnectionStream connection, AccessControlInfo access_control, Guid channel_id);