/// <summary> /// Connection on which an IoFlowAgent listens. /// </summary> /// <param name="callbacks"></param> public Connection(IConnectionCallback callbacks) { this.callbacks = callbacks; receiveContext = new CallbackContext(sock); this.locPort = AgentPort; sendBuffer = new byte[SOCK_SEND_BUFFER_SIZE]; locEndPoint = new IPEndPoint(IPAddress.Any, locPort); receiveBuffer = new byte[SOCK_RCV_BUFFER_SIZE]; messageHeader = new MessageHeader(); sockListen = new Socket(locEndPoint.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); ListSock.Add(sockListen); sockListen.Bind(locEndPoint); const int LISTEN_BACKLOG = 256; sockListen.Listen(LISTEN_BACKLOG); sockListen.BeginAccept(new AsyncCallback(acceptComplete), new CallbackContext(sockListen)); }
/// <summary> /// Connection through which rate controller conects to network agent socket app. /// </summary> /// <param name="callbacks"></param> /// <param name="hostName"></param> /// <param name="locPort"></param> /// <param name="remPort"></param> public Connection(IConnectionCallback callbacks, string hostName, int locPort, int remPort) { this.callbacks = callbacks; ListQueues = new List<OktoQueue>(); ListRap = new List<RAP>(); DictIoFlows = new Dictionary<uint, Flow>(); sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); receiveContext = new CallbackContext(sock); this.hostName = hostName; this.locPort = locPort; this.remPort = remPort; sendBuffer = new byte[SOCK_SEND_BUFFER_SIZE]; locEndPoint = new IPEndPoint(IPAddress.Any, locPort); receiveBuffer = new byte[SOCK_RCV_BUFFER_SIZE]; messageHeader = new MessageHeader(); // Avoid winsock buffering and Nagle delays on small TCP sends. // Ref http://msdn.microsoft.com/en-us/library/ms817942.aspx #if gregos // ToDo: one or both sockopts sometimes stalling master->agent connection sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, 0); sock.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true); sock.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.Linger, false); #endif sock.Connect(hostName, remPort); }