strerror() public static method

public static strerror ( int errnum ) : string
errnum int
return string
コード例 #1
0
ファイル: BluezStream.cs プロジェクト: zipa/wiidevicelibrary
        private void Connect(NativeMethods.bdaddr_t bdaddress)
        {
            // get bluetooth address
            NativeMethods.bdaddr_t dongleAddr;
            int deviceId = NativeMethods.hci_get_route(IntPtr.Zero);

            NativeMethods.hci_devba(deviceId, out dongleAddr);

            // create l2cap address
            NativeMethods.sockaddr_l2 address;
            address.l2_family = NativeMethods.AF_BLUETOOTH;
            address.l2_cid    = 0;

            // allocate sockets
            _ControlSocket = -1;
            while (_ControlSocket == -1)
            {
                _ControlSocket = NativeMethods.socket(NativeMethods.AF_BLUETOOTH, NativeMethods.SOCK_SEQPACKET, NativeMethods.BTPROTO_L2CAP);
                int error = Marshal.GetLastWin32Error();
                if (_ControlSocket == -1)
                {
                    if (error != NativeMethods.EINTR)
                    {
                        throw new WiiDeviceLibrary.DeviceConnectException("Failed to allocate the control socket: " + NativeMethods.strerror(error));
                    }
                }
            }

            _InterruptSocket = -1;
            while (_InterruptSocket == -1)
            {
                _InterruptSocket = NativeMethods.socket(NativeMethods.AF_BLUETOOTH, NativeMethods.SOCK_SEQPACKET, NativeMethods.BTPROTO_L2CAP);
                int error = Marshal.GetLastWin32Error();
                if (_InterruptSocket == -1)
                {
                    if (error != NativeMethods.EINTR)
                    {
                        NativeMethods.close(_ControlSocket);
                        throw new WiiDeviceLibrary.DeviceConnectException("Failed to allocate the interrupt socket: " + NativeMethods.strerror(error));
                    }
                }
            }

            // bind the bluetooth socket
            address.l2_psm = 0x0;
            address.bdaddr = dongleAddr;
            if (NativeMethods.bind(_ControlSocket, ref address, (uint)Marshal.SizeOf(address)) == -1)
            {
                int error = Marshal.GetLastWin32Error();
                NativeMethods.close(_ControlSocket);
                NativeMethods.close(_InterruptSocket);
                throw new WiiDeviceLibrary.DeviceConnectException("Failed to bind the control socket: " + NativeMethods.strerror(error));
            }

            // connect the control socket
            address.bdaddr = bdaddress;
            address.l2_psm = 0x11;
            while (NativeMethods.connect(_ControlSocket, ref address, (uint)Marshal.SizeOf(address)) == -1)
            {
                int error = Marshal.GetLastWin32Error();
                if (error != NativeMethods.EINTR)
                {
                    NativeMethods.close(_ControlSocket);
                    NativeMethods.close(_InterruptSocket);
                    throw new WiiDeviceLibrary.DeviceConnectException("Failed to connect the control socket: " + NativeMethods.strerror(error));
                }
            }

            // connect the interrupt socket
            address.bdaddr = bdaddress;
            address.l2_psm = 0x13;
            while (NativeMethods.connect(_InterruptSocket, ref address, (uint)Marshal.SizeOf(address)) == -1)
            {
                int error = Marshal.GetLastWin32Error();
                if (error != NativeMethods.EINTR)
                {
                    NativeMethods.close(_ControlSocket);
                    NativeMethods.close(_InterruptSocket);
                    throw new WiiDeviceLibrary.DeviceConnectException("Failed to connect the interrupt socket: " + NativeMethods.strerror(error));
                }
            }
            _Connected = true;
        }
コード例 #2
0
ファイル: BluezStream.cs プロジェクト: zipa/wiidevicelibrary
 public override void Write(byte[] buffer, int offset, int count)
 {
     if (!_Connected)
     {
         throw new IOException("The control socket is not connected");
     }
     _SendBuffer[0] = 0x52;
     Array.Copy(buffer, offset, _SendBuffer, 1, count);
     while (NativeMethods.send(_ControlSocket, _SendBuffer, count + 1, 0) == -1)
     {
         int error = Marshal.GetLastWin32Error();
         if (error != NativeMethods.EINTR)
         {
             NativeMethods.close(_InterruptSocket);
             NativeMethods.close(_ControlSocket);
             _Connected = false;
             throw new IOException("Failed to write to the control socket: " + NativeMethods.strerror(error));
         }
     }
 }