Beispiel #1
0
 public void Close()
 {
     lock (_syncObject)
     {
         _socket.Close();
     }
 }
Beispiel #2
0
 public void Close()
 {
     _closing = true;
     lock (_syncObject)
     {
         _socket.Close();
     }
 }
Beispiel #3
0
        private void IOLoop()
        {
            while (!_closing)
            {
                try
                {
                    bool active = false;

                    _socket.Tick();
                    State = _socket.State;

                    SmartPacketToSend packetToSend = new SmartPacketToSend();
                    if (_sendQueue.Count > 0)
                    {
                        active = true;

                        packetToSend = _sendQueue.Take();
                        _socket.Send(packetToSend.EndPoint, packetToSend.Buffer, packetToSend.Offset, packetToSend.Length, packetToSend.Reliable);
                        if (packetToSend.PutBufferToPool)
                        {
                            _buffersPool.Put(packetToSend.Buffer);
                        }
                    }

                    ReceivedSmartPacket receivedPacket = new ReceivedSmartPacket();
                    if (_socket.Receive(ref receivedPacket))
                    {
                        active = true;

                        _recvQueue.Add(receivedPacket);
                    }

                    if (!active)
                    {
                        Thread.Sleep(10);
                    }
                }
                catch (Exception)
                {
                    _closing = true;
                }
            }

            _socket.Close();
            State = PixocketState.NotConnected;
        }