Exemplo n.º 1
0
        public int parsePacket(out uint remoteIpAddress, out ushort remotePort)
        {
            Thread.Yield();

            int packetLength = 0;

            remoteIpAddress = 0;
            remotePort      = 0;
            ReceiveResult result = new ReceiveResult();

            lock (_receivedPackets)
            {
                if (_receivedPackets.Count > 0)
                {
                    result = _receivedPackets.Dequeue();
                }
                else
                {
                    return(packetLength);
                }
            }

            if (result.RemoteEndPoint != null)
            {
                var ep    = result.RemoteEndPoint;
                var bytes = ep.Address.GetAddressBytes();
                remoteIpAddress = BitConverter.ToUInt32(bytes, 0);
                remotePort      = (ushort)ep.Port;
            }
            if (result.Buffer != null)
            {
                packetLength = result.Buffer.Length;
            }

            _receiveQueue.Clear();
            _receiveQueue.Enqueue(result.Buffer, 0, packetLength);

            return(packetLength);
        }
Exemplo n.º 2
0
 public void ClearBuffers()
 {
     lock (m_Output) {
         m_Output.Clear();
         m_OutputReady.Reset();
         m_OutputEmpty.Set();
         m_OutputAccepts.Set();
     }
     lock (m_Input) {
         m_Input.Clear();
         m_InputReady.Reset();
         m_InputEmpty.Set();
         m_InputAccepts.Set();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Close the connection.
        /// </summary>
        public void close()
        {
            if (_client != null)
            {
                // signal and wait for thread handleClient() has finished
                _treadActive = false;
                _mreHandleClient.WaitOne();

                _client.Close();
                _client = null;

                _sendQueue.Clear();
                _receiveQueue.Clear();
            }
            Allocated = false;
        }