Exemplo n.º 1
0
        public TcpSocketSaeaSession(
            TcpSocketSaeaServerConfiguration configuration,
            ISegmentBufferManager bufferManager,
            SaeaPool saeaPool,
            ITcpSocketSaeaServerEventDispatcher dispatcher,
            TcpSocketSaeaServer server)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            if (bufferManager == null)
            {
                throw new ArgumentNullException("bufferManager");
            }
            if (saeaPool == null)
            {
                throw new ArgumentNullException("saeaPool");
            }
            if (dispatcher == null)
            {
                throw new ArgumentNullException("dispatcher");
            }
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            _configuration = configuration;
            _bufferManager = bufferManager;
            _saeaPool      = saeaPool;
            _dispatcher    = dispatcher;
            _server        = server;

            if (_receiveBuffer == default(ArraySegment <byte>))
            {
                _receiveBuffer = _bufferManager.BorrowBuffer();
            }
            _receiveBufferOffset = 0;
        }
Exemplo n.º 2
0
 private void Initialize()
 {
     _saeaPool = new SaeaPool(
         () =>
     {
         var saea = new SaeaAwaitable();
         return(saea);
     },
         (saea) =>
     {
         try
         {
             saea.Saea.AcceptSocket = null;
             saea.Saea.SetBuffer(EmptyArray, 0, 0);
             saea.Saea.RemoteEndPoint = null;
             saea.Saea.SocketFlags    = SocketFlags.None;
         }
         catch (Exception ex)     // initialize SAEA error occurred
         {
             _log.Error(ex.Message, ex);
         }
     })
                 .Initialize(256);
 }
Exemplo n.º 3
0
 private void Initialize()
 {
     _acceptSaeaPool = new SaeaPool(
         () =>
     {
         var saea = new SaeaAwaitable();
         return(saea);
     },
         (saea) =>
     {
         try
         {
             saea.Saea.AcceptSocket = null;
             saea.Saea.SetBuffer(0, 0);
             saea.Saea.RemoteEndPoint = null;
             saea.Saea.SocketFlags    = SocketFlags.None;
         }
         catch (Exception ex)
         {
             _log.Error(ex.Message, ex);
         }
     })
                       .Initialize(16);
     _handleSaeaPool = new SaeaPool(
         () =>
     {
         var saea = new SaeaAwaitable();
         return(saea);
     },
         (saea) =>
     {
         try
         {
             saea.Saea.AcceptSocket = null;
             saea.Saea.SetBuffer(EmptyArray, 0, 0);
             saea.Saea.RemoteEndPoint = null;
             saea.Saea.SocketFlags    = SocketFlags.None;
         }
         catch (Exception ex)
         {
             _log.Error(ex.Message, ex);
         }
     })
                       .Initialize(1024);
     _sessionPool = new SessionPool(
         () =>
     {
         var session = new TcpSocketSaeaSession(_configuration, _configuration.BufferManager, _handleSaeaPool, _dispatcher, this);
         return(session);
     },
         (session) =>
     {
         try
         {
             session.Detach();
         }
         catch (Exception ex)
         {
             _log.Error(ex.Message, ex);
         }
     })
                    .Initialize(512);
 }