public async Task OnSessionClosed(TcpSocketSaeaSession session)
 {
     if (_onSessionClosed != null)
     {
         await _onSessionClosed(session);
     }
 }
 public async Task OnSessionDataReceived(TcpSocketSaeaSession session, byte[] data, int offset, int count)
 {
     if (_onSessionDataReceived != null)
     {
         await _onSessionDataReceived(session, data, offset, count);
     }
 }
            public Task OnSessionStarted(TcpSocketSaeaSession session)
            {
#if NET45 || NET451
                return Task.FromResult(1);
#else
            return Task.CompletedTask;
#endif
            }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
        private void Initialize()
        {
            _bufferManager = new GrowingByteBufferManager(_configuration.InitialPooledBufferCount, _configuration.ReceiveBufferSize);

            _acceptSaeaPool = new SaeaPool(16, 32,
                () =>
                {
                    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);
                    }
                });
            _handleSaeaPool = new SaeaPool(1024, int.MaxValue,
                () =>
                {
                    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);
                    }
                });
            _sessionPool = new SessionPool(1024, int.MaxValue,
                () =>
                {
                    var session = new TcpSocketSaeaSession(_configuration, _bufferManager, _handleSaeaPool, _dispatcher, this);
                    return session;
                },
                (session) =>
                {
                    try
                    {
                        session.Clear();
                    }
                    catch (Exception ex)
                    {
//                        _log.Error(ex.Message, ex);
                    }
                });
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
 public async Task SendToAsync(TcpSocketSaeaSession session, byte[] data)
 {
     await SendToAsync(session, data, 0, data.Length);
 }
            public Task OnSessionDataReceived(TcpSocketSaeaSession session, byte[] data, int offset, int count)
            {
                if (_logger.IsEnabled(LogLevel.Information))
                    _logger.LogInformation("接收到数据包。");
                var message = _transportMessageDecoder.Decode(data.Skip(offset).Take(count).ToArray());
                if (_logger.IsEnabled(LogLevel.Information))
                    _logger.LogInformation("接收到消息:" + message.Id);
                _readAction(session, message);
#if NET45 || NET451
                return Task.FromResult(1);
#else
            return Task.CompletedTask;
#endif
            }
Esempio n. 9
0
 public async Task SendToAsync(TcpSocketSaeaSession session, byte[] data)
 {
     await SendToAsync(session, data, 0, data.Length);
 }
Esempio n. 10
0
        private void Initialize()
        {
            _bufferManager = new GrowingByteBufferManager(_configuration.InitialPooledBufferCount, _configuration.ReceiveBufferSize);

            _acceptSaeaPool = new SaeaPool(16, 32,
                                           () =>
            {
                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);
                }
            });
            _handleSaeaPool = new SaeaPool(1024, int.MaxValue,
                                           () =>
            {
                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);
                }
            });
            _sessionPool = new SessionPool(1024, int.MaxValue,
                                           () =>
            {
                var session = new TcpSocketSaeaSession(_configuration, _bufferManager, _handleSaeaPool, _dispatcher, this);
                return(session);
            },
                                           (session) =>
            {
                try
                {
                    session.Clear();
                }
                catch (Exception ex)
                {
//                        _log.Error(ex.Message, ex);
                }
            });
        }
 public async Task OnSessionClosed(TcpSocketSaeaSession session)
 {
     if (_onSessionClosed != null)
         await _onSessionClosed(session);
 }
 public async Task OnSessionDataReceived(TcpSocketSaeaSession session, byte[] data, int offset, int count)
 {
     if (_onSessionDataReceived != null)
         await _onSessionDataReceived(session, data, offset, count);
 }
Esempio n. 13
0
 public SimpleServerMessageSender(ITransportMessageEncoder transportMessageEncoder, TcpSocketSaeaSession session, ILogger logger) : base(transportMessageEncoder)
 {
     _session = session;
     _logger = logger;
 }