public AsyncSocketSession(IoService service, IoProcessor<SocketSession> processor, System.Net.Sockets.Socket socket,
     SocketAsyncEventArgsBuffer readBuffer, SocketAsyncEventArgsBuffer writeBuffer, Boolean reuseBuffer)
     : base(service, processor, new SessionConfigImpl(socket), socket, socket.LocalEndPoint, socket.RemoteEndPoint, reuseBuffer)
 {
     _readBuffer = readBuffer;
     _readBuffer.SocketAsyncEventArgs.UserToken = this;
     _writeBuffer = writeBuffer;
     _writeBuffer.SocketAsyncEventArgs.UserToken = this;
     _completeHandler = saea_Completed;
 }
            public SocketContext(System.Net.Sockets.Socket socket, IoSessionConfig config)
            {
                _socket = socket;

                _completeHandler = OnCompleted;

                Byte[] writeBuffer = new Byte[config.ReadBufferSize];
                _writeBuffer = SocketAsyncEventArgsBufferAllocator.Instance.Wrap(writeBuffer);
                _writeBuffer.SocketAsyncEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(OnCompleted);
                _writeBuffer.SocketAsyncEventArgs.UserToken = this;
            }
        private void InitBuffer()
        {
            Int32 bufferSize = SessionConfig.ReadBufferSize;
            if (_bufferManager == null || _bufferManager.BufferSize != bufferSize)
            {
                // TODO free previous pool

                _bufferManager = new BufferManager(bufferSize * MaxConnections * opsToPreAlloc, bufferSize);
                _bufferManager.InitBuffer();

                var list = new List<SocketAsyncEventArgsBuffer>(MaxConnections * opsToPreAlloc);
                for (Int32 i = 0; i < MaxConnections * opsToPreAlloc; i++)
                {
                    SocketAsyncEventArgs readWriteEventArg = new SocketAsyncEventArgs();
                    _bufferManager.SetBuffer(readWriteEventArg);
                    SocketAsyncEventArgsBuffer buf = new SocketAsyncEventArgsBuffer(readWriteEventArg);
                    list.Add(buf);

                    readWriteEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(readWriteEventArg_Completed);
                }
                _readWritePool = new Pool<SocketAsyncEventArgsBuffer>(list);
            }
        }