This class is a connection sockIOPool for maintaning a sockIOPool of persistent connections to memcached servers. The sockIOPool must be initialized prior to use. This should typically be early on in the lifecycle of the application instance.
예제 #1
0
        /// <summary>
        /// creates a new SockIO object wrapping a socket
        /// connection to host:port, and its input and output streams
        /// </summary>
        /// <param name="sockIOPool">Pool this object is tied to</param>
        /// <param name="host">host to connect to</param>
        /// <param name="port">port to connect to</param>
        /// <param name="timeout">int ms to block on data for read</param>
        /// <param name="connectTimeout">timeout (in ms) for initial connection</param>
        /// <param name="noDelay">TCP NODELAY option?</param>
        public SockIO(SockIOPool pool, String host, int port, int timeout, int connectTimeout, bool noDelay)
            : this()
        {
            if (host == null || host.Length == 0)
                throw new ArgumentNullException(GetLocalizedString("host"), GetLocalizedString("null host"));

            _pool = pool;


            if (connectTimeout > 0)
            {
                _socket = GetSocket(host, port, connectTimeout);
            }
            else
            {
                _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                _socket.Connect(new IPEndPoint(IPAddress.Parse(host), port));
            }

            _networkStream = new BufferedStream(new NetworkStreamIgnoreSeek(_socket));

            _host = host + ":" + port;
        }
예제 #2
0
        /// <summary>
        /// creates a new SockIO object wrapping a socket
        /// connection to host:port, and its input and output streams
        /// </summary>
        /// <param name="sockIOPool">Pool this object is tied to</param>
        /// <param name="host">hostname:port</param>
        /// <param name="timeout">read timeout value for connected socket</param>
        /// <param name="connectTimeout">timeout for initial connections</param>
        /// <param name="noDelay">TCP NODELAY option?</param>
        public SockIO(SockIOPool pool, String host, int timeout, int connectTimeout, bool noDelay)
            : this()
        {
            if (host == null || host.Length == 0)
                throw new ArgumentNullException(GetLocalizedString("host"), GetLocalizedString("null host"));

            _pool = pool;


            String[] ip = host.Split(':');

            // get socket: default is to use non-blocking connect
            if (connectTimeout > 0)
            {
                _socket = GetSocket(ip[0], int.Parse(ip[1], new System.Globalization.NumberFormatInfo()), connectTimeout);
            }
            else
            {
                _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                _socket.Connect(new IPEndPoint(IPAddress.Parse(ip[0]), int.Parse(ip[1], new System.Globalization.NumberFormatInfo())));
            }

            _networkStream = new BufferedStream(new NetworkStreamIgnoreSeek(_socket));

            _host = host;
        }
예제 #3
0
        public static SockIOPool GetInstance(String poolName)
        {
            if(Pools.ContainsKey(poolName))
                return (SockIOPool)Pools[poolName];

            SockIOPool pool = new SockIOPool();
            pool.Name = poolName;
            Pools[poolName] = pool;

            return pool;
        }
예제 #4
0
 public MaintenanceThread(SockIOPool pool)
 {
     _thread = new Thread(new ThreadStart(Maintain));
     _pool = pool;
 }