public MyTcpServer(IPEndPoint localEndPoint, Pipeline pipeline) : base(localEndPoint, pipeline) { _tcpListener = new TcpListener(LocalEndPoint); _tcpListener.Server.LingerState = new LingerOption(false, 0); _tcpListener.Server.NoDelay = true; }
public PipelineSession(IChannel channel, Pipeline pipeline, IEnumerable<IInboundHandler> inboundHandlers, IEnumerable<IOutboundHandler> outboundHandlers) { _channel = channel; _pipeline = pipeline; InboundHandlers = new LinkedList<IInboundHandler>(inboundHandlers); OutboundHandlers = new LinkedList<IOutboundHandler>(outboundHandlers); _ctx = new ChannelHandlerContext(channel, this); }
protected BaseClient(IPEndPoint localEndPoint, Pipeline pipeline) : base(localEndPoint, pipeline) { Session = Pipeline.CreateClientSession(this); Session.TriggerActive(); }
public MyUdpClient(IPEndPoint localEndPoint, Pipeline pipeline) : base(localEndPoint, pipeline) { // bind _udpClient = new UdpClient(localEndPoint); }
public MyTcpClient(IPEndPoint localEndPoint, Pipeline pipeline) : base(localEndPoint, pipeline) { // bind _tcpClient = new TcpClient(localEndPoint); }
public Pipeline Filter(Pipeline pipeline, bool isTcp, bool isClient) { var filteredPipeline = new Pipeline(); filteredPipeline.AddLast("counter", isTcp ? _ccohTcp : _ccohUdp); foreach (var hi in pipeline.HandlerItems) { filteredPipeline.AddLast(hi.Name, hi.Handler); } return filteredPipeline; }
/// <summary> /// Creates a "channel" to the given address. /// This won't send any message unlike TCP. /// </summary> /// <param name="broadcast">Sets this channel to be able to broadcast.</param> /// <param name="handlers">The handlers to be added to the channel's pipeline.</param> /// <returns>The created channel or null, if the channel could not be created.</returns> public MyUdpClient CreateUdp(bool broadcast, IDictionary<string, IChannelHandler> handlers) { _readWriteLockUdp.EnterReadLock(); try { if (_shutdownUdp) { return null; } // try to aquire resources for the channel if (_semaphoreUdp == null || !_semaphoreUdp.TryAcquire()) { const string errorMsg = "Tried to acquire more resources (UDP) than announced."; Logger.Error(errorMsg); throw new SystemException(errorMsg); } // create and bind var pipeline = new Pipeline(handlers); var filteredPipeline = _channelClientConfiguration.PipelineFilter.Filter(pipeline, false, true); var udpClient = new MyUdpClient(_externalBindings.WildcardSocket(), filteredPipeline); _recipients.Add(udpClient); SetupCloseListener(udpClient, _semaphoreUdp); if (broadcast) { udpClient.Socket.EnableBroadcast = true; } return udpClient; } finally { _readWriteLockUdp.ExitReadLock(); } }
/// <summary> /// Creates a channel to the given address. This will setup the TCP connection. /// </summary> /// <param name="remoteAddress">The remote address.</param> /// <param name="connectionTimeoutMillis">The timeout for establishing a TCP connection.</param> /// <param name="handlers">The handlers to be added to the channel's pipeline.</param> /// <returns></returns> public MyTcpClient CreateTcp(IPEndPoint remoteAddress, int connectionTimeoutMillis, IDictionary<string, IChannelHandler> handlers) { _readWriteLockTcp.EnterReadLock(); try { if (_shutdownTcp) { return null; } // try to acquire resources for the channel if (_semaphoreTcp == null || !_semaphoreTcp.TryAcquire()) { const string errorMsg = "Tried to acquire more resources (TCP) than announced."; Logger.Error(errorMsg); throw new SystemException(errorMsg); } // create and bind var pipeline = new Pipeline(handlers); var filteredPipeline = _channelClientConfiguration.PipelineFilter.Filter(pipeline, true, true); var tcpClient = new MyTcpClient(_externalBindings.WildcardSocket(), filteredPipeline); _recipients.Add(tcpClient); SetupCloseListener(tcpClient, _semaphoreTcp); // TODO how to set CONNECT_TIMEOUT_MILLIS option? tcpClient.Socket.NoDelay = true; tcpClient.Socket.LingerState = new LingerOption(false, 0); tcpClient.Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); // connect try { tcpClient.ConnectAsync(remoteAddress).Wait(); } catch (Exception ex) { Logger.Warn(ex); throw; } return tcpClient; } finally { _readWriteLockTcp.ExitReadLock(); } }
private void AddOrReplace(Pipeline pipeline, string before, string name, IChannelHandler handler) { if (pipeline.Names.Contains(name)) { pipeline.Replace(name, name, handler); } else { if (before == null) { pipeline.AddFirst(name, handler); } else { pipeline.AddBefore(before, name, handler); } } }
protected BaseChannel(IPEndPoint localEndPoint, Pipeline pipeline) { LocalEndPoint = localEndPoint; Pipeline = pipeline; }
public Pipeline Filter(Pipeline pipeline, bool isTcp, bool isClient) { return pipeline; }
protected BaseServer(IPEndPoint localEndPoint, Pipeline pipeline) : base (localEndPoint, pipeline) { }