Esempio n. 1
0
 public void Setup()
 {
     _cbs        = new MockSmartCallbacks();
     _bareSock   = new MockSock();
     _bufferPool = new ByteBufferPool();
     _sock       = new SmartSock(_bufferPool, _bareSock, _cbs);
 }
Esempio n. 2
0
 public BareSock(BufferPoolBase buffersPool, AddressFamily addressFamily, ILogger logger)
 {
     SysSock          = new Socket(addressFamily, SocketType.Dgram, ProtocolType.Udp);
     SysSock.Blocking = false;
     _buffersPool     = buffersPool;
     _logger          = logger;
 }
Esempio n. 3
0
        public static ArraySegment <byte> ToBuffer(byte[] array, BufferPoolBase bufferPool)
        {
            var buffer = bufferPool.Get(array.Length);

            Array.Copy(array, buffer, array.Length);
            return(new ArraySegment <byte>(buffer, 0, array.Length));
        }
Esempio n. 4
0
        public static ArraySegment <byte> ToBuffer(MemoryStream ms, BufferPoolBase bufferPool)
        {
            var buffer = bufferPool.Get((int)ms.Length);
            var array  = ms.ToArray();

            Array.Copy(array, buffer, array.Length);
            return(new ArraySegment <byte>(buffer, 0, array.Length));
        }
Esempio n. 5
0
 public void Init(BufferPoolBase buffersPool, Pool <FragmentedPacket> fragPacketsPool, Pool <PacketHeader> headersPool, ushort sessionId)
 {
     _buffersPool     = buffersPool;
     _fragPacketsPool = fragPacketsPool;
     _headersPool     = headersPool;
     LastActive       = Environment.TickCount;
     SessionId        = sessionId;
 }
        public ThreadSmartSock(SmartSock socket, BufferPoolBase buffersPool)
        {
            _socket      = socket;
            _buffersPool = buffersPool;

            _ioThread = new Thread(IOLoop);
            _ioThread.IsBackground = true;
        }
Esempio n. 7
0
        public void Setup()
        {
            _cbs        = new MockSmartCallbacks();
            _bareSock   = new MockSock();
            _bufferPool = new ByteBufferPool();
            _sock       = new SmartSock(_bufferPool, _bareSock, _cbs);
            _endPoint   = new IPEndPoint(IPAddress.Loopback, 23452);

            Utils.SendConnectRequest(_bareSock, _endPoint, _bufferPool);
        }
Esempio n. 8
0
        public ThreadSock(BufferPoolBase buffersPool, AddressFamily addressFamily, ILogger logger)
        {
            SysSock  = new Socket(addressFamily, SocketType.Dgram, ProtocolType.Udp);
            _closing = false;

            _buffersPool             = buffersPool;
            _logger                  = logger;
            _sendThread              = new Thread(SendLoop);
            _sendThread.IsBackground = true;
            _sendThread.Start();
            _receiveThread = new Thread(ReceiveLoop);
            _receiveThread.IsBackground = true;
        }
Esempio n. 9
0
 public SmartSock(BufferPoolBase buffersPool, SockBase subSock, SmartReceiverBase callbacks)
 {
     _buffersPool = buffersPool;
     SubSock      = subSock;
     if (callbacks != null)
     {
         _callbacks = callbacks;
     }
     else
     {
         _callbacks = new NullSmartReceiver();
     }
 }
Esempio n. 10
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;
        }
Esempio n. 11
0
 public void SetSocket(SmartSock socket, BufferPoolBase bufferPool)
 {
     _servSock   = socket;
     _bufferPool = bufferPool;
 }
Esempio n. 12
0
        public static void SendDisconnectResponse(MockSock bareSock, IPEndPoint endPoint, BufferPoolBase bufferPool)
        {
            ushort sessionId = 427;
            var    header    = new PacketHeader();

            header.SetSessionId(sessionId);
            header.SetDisconnect();

            var buffer = bufferPool.Get(header.HeaderLength);

            header.Length = (ushort)header.HeaderLength;
            header.WriteTo(buffer, 0);

            bareSock.FakeReceive(buffer, 0, header.HeaderLength, endPoint);
        }
Esempio n. 13
0
 public static void SendDisconnectRequest(MockSock bareSock, IPEndPoint endPoint, BufferPoolBase bufferPool)
 {
     SendDisconnectResponse(bareSock, endPoint, bufferPool);
 }
Esempio n. 14
0
 public AsyncSock(BufferPoolBase buffersPool, AddressFamily addressFamily)
     : this(buffersPool, addressFamily, new LoggerStub())
 {
 }
Esempio n. 15
0
 public void Init(BufferPoolBase buffersPool, Pool <FragmentedPacket> fragPacketsPool, Pool <PacketHeader> headersPool)
 {
     Init(buffersPool, fragPacketsPool, headersPool, (ushort)(Rnd.Next(ushort.MaxValue) + 1));
 }
Esempio n. 16
0
        public static void SendConnectRequest(MockSock bareSock, IPEndPoint endPoint, BufferPoolBase bufferPool)
        {
            var header = new PacketHeader();

            header.SetSessionId(PacketHeader.EmptySessionId);
            header.SetConnect();

            var buffer = bufferPool.Get(header.HeaderLength);

            header.Length = (ushort)header.HeaderLength;
            header.WriteTo(buffer, 0);

            bareSock.FakeReceive(buffer, 0, header.HeaderLength, endPoint);
        }
Esempio n. 17
0
 public AsyncSock(BufferPoolBase buffersPool, AddressFamily addressFamily, ILogger logger)
 {
     _buffersPool   = buffersPool;
     _addressFamily = addressFamily;
     _logger        = logger;
 }