recv() private method

private recv ( int socket, Array buffer, int length, int flags ) : int
socket int
buffer Array
length int
flags int
return int
Ejemplo n.º 1
0
        private void DiscoverFunction()
        {
            byte[] buffer = new byte[255];
            _DiscoverSocket = CreateDiscoverSocket();
            if (_DiscoverSocket == -1)
            {
                return;
            }
            InitiateInquiry();


            while (_DiscoverThread != null)
            {
                int bytes = NativeMethods.recv(_DiscoverSocket, buffer, 255, 0);
                if (bytes == -1)
                {
                    NativeMethods.hci_close_dev(_DiscoverSocket);
                    _DiscoverSocket = CreateDiscoverSocket();
                    if (_DiscoverSocket == -1)
                    {
                        return;
                    }
                    InitiateInquiry();
                    continue;
                }
                ParseEvent(buffer, bytes);
            }
            NativeMethods.hci_close_dev(_DiscoverSocket);
        }
Ejemplo n.º 2
0
 private void FlushSocket()
 {
     byte[] buffer = new byte[255];
     while (NativeMethods.recv(_DiscoverSocket, buffer, 255, NativeMethods.MSG_DONTWAIT) != -1)
     {
         ;
     }
 }
Ejemplo n.º 3
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            int receivedByteCount = NativeMethods.recv(_InterruptSocket, _ReceiveBuffer, _ReceiveBuffer.Length, 0);

            if (receivedByteCount > 0)
            {
                // with bluez you get a hid byte, this must not be copied into the buffer
                count = Math.Min(count, receivedByteCount - 1);
                Array.Copy(_ReceiveBuffer, 1, buffer, offset, count);
                return(count);
            }
            else if (receivedByteCount <= 0)
            {
                NativeMethods.close(_InterruptSocket);
                NativeMethods.close(_ControlSocket);
                _Connected = false;
                if (receivedByteCount < 0)
                {
                    throw new IOException("Failed to read from the interrupt socket.");
                }
            }
            return(0);
        }