private void Initialize() { _bufferManager = new GrowingByteBufferManager(_configuration.InitialPooledBufferCount, _configuration.ReceiveBufferSize); _saeaPool = 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); } }); }
public TcpSocketSaeaSession( TcpSocketSaeaServerConfiguration configuration, IBufferManager bufferManager, SaeaPool saeaPool, ITcpSocketSaeaServerMessageDispatcher 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; _receiveBuffer = _bufferManager.BorrowBuffer(); _receiveBufferOffset = 0; }
private static void StartAccepting() { var acceptArgs = SaeaPool.Get(); acceptArgs.Completed += Accepted; if (!Socket.AcceptAsync(acceptArgs)) { Accepted(null, acceptArgs); } }
private void IOSendCompleted(object sender, SocketAsyncEventArgs saea) { try { } finally { saea.Completed -= IOSendCompleted; SaeaPool.Add(saea); } }
private static void Accepted(object sender, SocketAsyncEventArgs e) { var receiveArgs = SaeaPool.Get(); receiveArgs.UserToken = new ClientSocket(BufferSize); var client = (ClientSocket)receiveArgs.UserToken; client.Socket = e.AcceptSocket; client.IsConnected = true; client.OnPacket += OnPacket; client.Receive(); client.Diffie = new DiffieHellman(); e.Completed -= Accepted; e.AcceptSocket = null; SaeaPool.Return(e); StartAccepting(); }
public void Send(Package package) { if (Status == ListenerStatus.Stopped) { return; } var saea = SaeaPool.Take(); saea.Completed += IOSendCompleted; saea.SetBuffer(package.Data, 0, package.Data.Length); saea.RemoteEndPoint = package.EndPoint; var async = Listener.SendToAsync(saea); if (!async) { IOSendCompleted(null, saea); } }
public TcpSocketSaeaSession( TcpSocketSaeaServerConfiguration configuration, IBufferManager bufferManager, SaeaPool saeaPool, ITcpSocketSaeaServerMessageDispatcher 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; _receiveBuffer = _bufferManager.BorrowBuffer(); _receiveBufferOffset = 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); } }); }
private void Initialize() { _bufferManager = new GrowingByteBufferManager(_configuration.InitialBufferAllocationCount, _configuration.ReceiveBufferSize); _saeaPool = 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); } }); }
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); } }); }