Exemplo n.º 1
0
        public ThreadSmartSock(SmartSock socket, BufferPoolBase buffersPool)
        {
            _socket      = socket;
            _buffersPool = buffersPool;

            _ioThread = new Thread(IOLoop);
            _ioThread.IsBackground = true;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 4
0
 public ThreadSafeSmartSock(SmartSock socket)
 {
     _socket = socket;
 }