public async Task OnSessionDataReceived(TcpSocketSaeaSession session, byte[] data, int offset, int count)
 {
     if (_onSessionDataReceived != null)
     {
         await _onSessionDataReceived(session, data, offset, count);
     }
 }
 public async Task OnSessionClosed(TcpSocketSaeaSession session)
 {
     if (_onSessionClosed != null)
     {
         await _onSessionClosed(session);
     }
 }
Exemplo n.º 3
0
        public TcpSocketSaeaSession GetSession(string sessionKey)
        {
            TcpSocketSaeaSession session = null;

            _sessions.TryGetValue(sessionKey, out session);
            return(session);
        }
Exemplo n.º 4
0
        public async Task CloseSession(string sessionKey)
        {
            TcpSocketSaeaSession session = null;

            if (_sessions.TryGetValue(sessionKey, out session))
            {
                await session.Close(); // parent server close session by session-key
            }
        }
Exemplo n.º 5
0
        public async Task SendToAsync(TcpSocketSaeaSession session, byte[] data, int offset, int count)
        {
            TcpSocketSaeaSession sessionFound;

            if (_sessions.TryGetValue(session.SessionKey, out sessionFound))
            {
                await sessionFound.SendAsync(data, offset, count);
            }
            else
            {
                _log.WarnFormat("Cannot find session [{0}].", session);
            }
        }
Exemplo n.º 6
0
 public async Task SendToAsync(TcpSocketSaeaSession session, byte[] data)
 {
     await SendToAsync(session, data, 0, data.Length);
 }
Exemplo n.º 7
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);
 }