Esempio n. 1
0
        IPooledSocket Create()
        {
            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("Creating a socket on {0}", _node.EndPoint);
            }
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
            {
                ReceiveTimeout = (int)_config.ReceiveTimeout.TotalMilliseconds,
                SendTimeout    = (int)_config.ReceiveTimeout.TotalMilliseconds,
                NoDelay        = true
            };

            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, (int)_config.ReceiveTimeout.TotalMilliseconds);
            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, true);
            socket.Connect(_node.EndPoint);

            var pooledSocket = new CouchbasePooledSocket(this, socket);

            if (_provider != null && !Authenticate(pooledSocket))
            {
                throw new SecurityException(String.Format("Authentication failed on {0}", _node.EndPoint));
            }
            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("Created socket Id={0} on {1}", pooledSocket.InstanceId, _node.EndPoint);
            }
            _refs.Add(pooledSocket);
            return(pooledSocket);
        }
        public AsyncSocketHelper2(CouchbasePooledSocket socket)
        {
            this.socket = socket;
            this.asyncBuffer = new SlidingBuffer(ChunkSize);

            this.readEvent = new SocketAsyncEventArgs();
            this.readEvent.Completed += new EventHandler<SocketAsyncEventArgs>(AsyncReadCompleted);
            this.readEvent.SetBuffer(new byte[ChunkSize], 0, ChunkSize);

            this.readInProgressEvent = new ManualResetEvent(false);
        }
        public AsyncSocketHelper2(CouchbasePooledSocket socket)
        {
            this.socket      = socket;
            this.asyncBuffer = new SlidingBuffer(ChunkSize);

            this.readEvent            = new SocketAsyncEventArgs();
            this.readEvent.Completed += new EventHandler <SocketAsyncEventArgs>(AsyncReadCompleted);
            this.readEvent.SetBuffer(new byte[ChunkSize], 0, ChunkSize);

            this.readInProgressEvent = new ManualResetEvent(false);
        }
Esempio n. 4
0
        IPooledSocket Create()
        {
            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("Creating a socket on {0}", _node.EndPoint);
            }
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
            {
                ReceiveTimeout = (int)_config.ReceiveTimeout.TotalMilliseconds,
                SendTimeout = (int)_config.ReceiveTimeout.TotalMilliseconds,
                NoDelay = true
            };

            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, (int)_config.ReceiveTimeout.TotalMilliseconds);
            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, true);
            socket.Connect(_node.EndPoint);

            var pooledSocket = new CouchbasePooledSocket(this, socket);
            if (_provider != null && !Authenticate(pooledSocket))
            {
                throw new SecurityException(String.Format("Authentication failed on {0}", _node.EndPoint));
            }
            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("Created socket Id={0} on {1}", pooledSocket.InstanceId, _node.EndPoint);
            }
            _refs.Add(pooledSocket);
            return pooledSocket;
        }