Exemple #1
0
 public SmartSock(BufferPoolBase buffersPool, SockBase subSock, SmartReceiverBase callbacks)
 {
     _buffersPool = buffersPool;
     SubSock      = subSock;
     if (callbacks != null)
     {
         _callbacks = callbacks;
     }
     else
     {
         _callbacks = new NullSmartReceiver();
     }
 }
Exemple #2
0
        public ThreadSmartSock(BufferPoolBase buffersPool, SockBase subSock, SmartReceiverBase callbacks)
        {
            _socket      = new SmartSock(buffersPool, subSock, this);
            _buffersPool = buffersPool;
            if (callbacks != null)
            {
                _callbacks = callbacks;
            }
            else
            {
                _callbacks = new NullSmartReceiver();
            }

            _ioThread = new Thread(IOLoop);
            _ioThread.IsBackground = true;
        }
Exemple #3
0
        public void Tick(IPEndPoint endPoint, SockBase sock, int now, int ackTimeout, int fragmentTimeout)
        {
            var notAckedCount = _notAcked.Count;

            for (int i = 0; i < notAckedCount; ++i)
            {
                var packet = _notAcked[i];
                if (now - packet.SendTicks > ackTimeout)
                {
                    sock.Send(endPoint, packet.Buffer, packet.Offset, packet.Length, false);
                    packet.SendTicks = now;
                    _notAcked[i]     = packet;
                }
            }

            var packetsCount = _frags.Count;

            for (int i = packetsCount - 1; i >= 0; --i)
            {
                var frag = _frags[i];
                if (SmartSock.TimeDelta(frag.LastActive, now) > fragmentTimeout)
                {
                    _frags.RemoveAt(i);
                    _fragPacketsPool.Put(frag);
                }
            }

            while (_ackQueue.Count > 0)
            {
                var header = _headersPool.Get();
                AddAcks(header);
                header.SetSessionId(SessionId);
                header.Length = (ushort)header.HeaderLength;
                var buffer = _buffersPool.Get(header.Length);
                header.WriteTo(buffer, 0);
                sock.Send(endPoint, buffer, 0, header.Length, true);
                _headersPool.Put(header);
            }
        }