public void Close() { lock (_syncObject) { _socket.Close(); } }
public void Close() { _closing = true; lock (_syncObject) { _socket.Close(); } }
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; }