Ejemplo n.º 1
0
        private static void CreateManager()
        {
            serverList = memCachedConfigInfo.ServerList.Split(new char[2] { '\n', '\r' });

            pool = SockIOPool.GetInstance(memCachedConfigInfo.PoolName);
            pool.SetServers(serverList);
            pool.InitConnections = memCachedConfigInfo.IntConnections;//初始化链接数
            pool.MinConnections = memCachedConfigInfo.MinConnections;//最少链接数
            pool.MaxConnections = memCachedConfigInfo.MaxConnections;//最大连接数
            pool.SocketConnectTimeout = memCachedConfigInfo.SocketConnectTimeout;//Socket链接超时时间
            pool.SocketTimeout = memCachedConfigInfo.SocketTimeout;// Socket超时时间
            pool.MaintenanceSleep = memCachedConfigInfo.MaintenanceSleep;//维护线程休息时间
            pool.Failover = memCachedConfigInfo.FailOver; //失效转移(一种备份操作模式)
            pool.Nagle = memCachedConfigInfo.Nagle;//是否用nagle算法启动socket
            pool.HashingAlgorithm = HashingAlgorithm.NewCompatibleHash;
            pool.Initialize();


            mc = new MemcachedClient();
            mc.PoolName = memCachedConfigInfo.PoolName;
            mc.EnableCompression = false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// creates a new SockIO object wrapping a socket
        /// connection to host:port, and its input and output streams
        /// </summary>
        /// <param name="pool">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;
        }
Ejemplo n.º 3
0
        public static SockIOPool GetInstance(String poolName)
        {
            if(Pools.ContainsKey(poolName))
                return (SockIOPool)Pools[poolName];

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

            return pool;
        }
Ejemplo n.º 4
0
 public MaintenanceThread(SockIOPool pool)
 {
     _thread = new Thread(new ThreadStart(Maintain));
     _pool = pool;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// creates a new SockIO object wrapping a socket
        /// connection to host:port, and its input and output streams
        /// </summary>
        /// <param name="pool">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;
        }