public RpcTcpSimplexConnection(RpcTcpClientChannel channel, TcpUri serverUri, int concurrentConnection) : base(RpcConnectionMode.Simplex, RpcConnectionDirection.Client) { _channel = channel; _serverUri = serverUri; _connections = new RpcTcpSimplexConnectionWrapper[concurrentConnection]; _lc = new LoopCounter(concurrentConnection); _connectionCount = new ComboClass <int>(0); for (int i = 0; i < concurrentConnection; i++) { var wrapper = new RpcTcpSimplexConnectionWrapper(this); RpcTcpSimplexConnectionManager.AddConnection(wrapper); _connections[i] = wrapper; } }
public void TryRecycle() { if (_sock == null || !_sock.Connected) { return; } var span = DateTime.Now - _sock.ConnectedTime; if (span.TotalSeconds > RpcTcpBufferManager.Configuration.ChannelItem.SimplexConnectionLife) { _tracing.InfoFmt("Try to recycle connection: {0} connected={1} span={2}", _sock.RemoteUri, _sock.ConnectedTime, span); RpcTcpSimplexConnectionManager.DelayClose(_sock); lock (_syncRoot) { CreateConnection(); } } }
/// <summary> /// 构造函数, 不需要参数 /// </summary> public RpcTcpClientChannel() : base("tcp") { RpcTcpBufferManager.Initialize(); RpcTcpSimplexConnectionManager.Initialize(); _simplexConnections = new Dictionary <ServerUri, RpcTcpSimplexConnection>(); _duplexConnections = new Dictionary <ServerUri, RpcTcpDuplexConnection>(); p_channelSettings = new RpcChannelSettings() { MaxBodySize = 512 * 1024 * 1024, SupportModes = RpcChannelSupportModes.Connection | RpcChannelSupportModes.DuplexConnection, Version = "4.3", Timeout = RpcTcpBufferManager.Configuration.ChannelItem.Timeout, ConcurrentConnection = RpcTcpBufferManager.Configuration.ChannelItem.SimplexConnections, }; RpcTcpTransactionManager.Initialize(); }