Пример #1
0
 internal void Start()
 {
     if (AddState(State.INIT))
     {
         if ((_state & (int)State.CLOSE) != 0)
         {
             return;
         }
         _loop.Retain();
         if (_settings.timeout != Timeout.Infinite)
         {
             _timer = new Loop.Timer(_settings.timeout, false, () =>
             {
                 int dtime = (int)((Application.Now - _alivetime) / 1000);
                 if (dtime >= _settings.timeout)
                 {
                     Close();
                 }
                 else
                 {
                     _timer.Time = _settings.timeout - dtime;
                     _timer.Start();
                 }
             });
             _timer.Start();
         }
         SocketAsyncEventArgs readargs = new SocketAsyncEventArgs();
         readargs.SetBuffer(new byte[_settings.buffersize], 0, _settings.buffersize);
         readargs.Completed += (sender, args) =>
         {
             ProcessReceive(args);
         };
         PostReceive(readargs);
     }
 }
Пример #2
0
        protected Session(Loop loop, ISettings settings, Socket socket)
        {
            _loop      = loop;
            _settings  = settings;
            _socket    = socket;
            _timer     = null;
            _alivetime = Application.Now;
            _state     = (int)State.NONE;

            _sendqueue = new ConcurrentQueue <ArraySegment <byte> >();
            _sendbytes = null;
            _sendargs  = new SocketAsyncEventArgs {
                BufferList = new List <ArraySegment <byte> >()
            };
            _sendargs.Completed += (sender, args) =>
            {
                ProcessSend();
            };
        }