private TcpConnection GetConnection(TcpServiceAddress address) { TcpConnection c; lock (connections) { // If there isn't, establish a connection, if (!connections.TryGetValue(address, out c)) { IPEndPoint endPoint = address.ToEndPoint(); Socket socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); #if DEBUG socket.ReceiveTimeout = Int32.MaxValue; #else socket.ReceiveTimeout = 8 * 1000; // 8 second timeout, #endif socket.NoDelay = true; int curSendBufSize = socket.SendBufferSize; if (curSendBufSize < 256 * 1024) socket.SendBufferSize = 256 * 1024; int curReceiveBufSize = socket.ReceiveBufferSize; if (curReceiveBufSize < 256 * 1024) socket.ReceiveBufferSize = 256 * 1024; socket.Connect(endPoint); c = new TcpConnection(socket); c.Connect(password); connections.Add(address, c); } else { c.AddLock(); } } return c; }
public void Test2() { ResponseMessage response = new ResponseMessage("response"); IServiceAddress[] addresses = new IServiceAddress[1]; int[] status = new int[1]; response.Arguments.Add(1); addresses[0] = new TcpServiceAddress("127.0.0.1", 3500); status[0] = (int) ServiceStatus.Up; response.Arguments.Add(addresses); response.Arguments.Add(status); Stream stream = Serialize(response); Message message = Deserialize(stream, MessageType.Response); Assert.IsNotNull(message); Assert.AreEqual(MessageType.Response, message.MessageType); Assert.AreEqual(3, message.Arguments.Count); Assert.AreEqual(1, message.Arguments[0].Value); Assert.IsInstanceOf(typeof(IServiceAddress[]), message.Arguments[1].Value); }
public void Test2() { ResponseMessage response = new ResponseMessage("response"); IServiceAddress[] addresses = new IServiceAddress[1]; int[] status = new int[1]; response.Arguments.Add(1); addresses[0] = new TcpServiceAddress("127.0.0.1", 3500); status[0] = (int)ServiceStatus.Up; response.Arguments.Add(addresses); response.Arguments.Add(status); Stream stream = Serialize(response); Message message = Deserialize(stream, MessageType.Response); Assert.IsNotNull(message); Assert.AreEqual(MessageType.Response, message.MessageType); Assert.AreEqual(3, message.Arguments.Count); Assert.AreEqual(1, message.Arguments[0].Value); Assert.IsInstanceOf(typeof(IServiceAddress[]), message.Arguments[1].Value); }
public IMessageProcessor Connect(TcpServiceAddress address, ServiceType type) { return new MessageProcessor(this, address, type); }
public TcpProxyServiceConnector(TcpServiceAddress proxyAddress, string password) { this.proxyAddress = proxyAddress; this.password = password; }
public MessageProcessor(TcpProxyServiceConnector connector, TcpServiceAddress address, ServiceType serviceType) { this.connector = connector; this.address = address; this.serviceType = serviceType; }
public TcpProxyNetworkClient(TcpServiceAddress managerAddress, TcpServiceAddress proxyAddress, string password) : base(managerAddress, new TcpProxyServiceConnector(proxyAddress, password)) { }
public TcpAdminService(IServiceFactory serviceFactory, TcpServiceAddress address, string password) : base(address, new TcpServiceConnector(password), serviceFactory) { }
public TcpPathClientService(IServiceAddress address, TcpServiceAddress managerAddress, string password) : base(address, managerAddress, new TcpServiceConnector(password)) { }
public TcpNetworkClient(TcpServiceAddress managerAddress, string password) : base(managerAddress, new TcpServiceConnector(password)) { }
private void InvalidateConnection(TcpServiceAddress address) { lock (connections) { connections.Remove(address); } }
public TcpNetworkClient(TcpServiceAddress[] managerAddress, string password, INetworkCache cache) : base(managerAddress, new TcpServiceConnector(password), cache) { }
private TcpConnection GetConnection(TcpServiceAddress address) { TcpConnection c; lock (connectionPool) { // If there isn't, establish a connection, if (!connectionPool.TryGetValue(address, out c)) { Socket socket = new Socket(address.IsIPv4 ? AddressFamily.InterNetwork : AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.IP); socket.Connect(address.ToIPAddress(), address.Port); socket.ReceiveTimeout = (30*1000); // 30 second timeout, socket.NoDelay = true; int curSendBufSize = socket.SendBufferSize; if (curSendBufSize < 256*1024) socket.SendBufferSize = 256*1024; int curReceiveBufSize = socket.ReceiveBufferSize; if (curReceiveBufSize < 256*1024) socket.ReceiveBufferSize = 256*1024; c = new TcpConnection(this, socket); c.Connect(); connectionPool[address] = c; } else { c.AddLock(); } } return c; }