     portRange L2CAP  = [4097, 4099 .. 32767]
     portRange RFCOMM = [1 .. 30]
 
+setNonBlockIfNeeded :: CInt -> IO ()
+setNonBlockIfNeeded = flip setNonBlockingFD True
+
 {#fun unsafe bind as c_bind
   `SockAddrBluetooth a' =>
   { id               `CInt'

    callAccept :: SockAddrBluetooth a => Socket -> Ptr a -> Int -> IO (Socket, BluetoothAddr)
    callAccept sock'@(MkSocket fd _ _ _ _) sockaddrPtr size = do
          newFd <- throwSocketErrorWaitRead sock' "accept" . fmap fst $ c_accept fd sockaddrPtr size
          bdaddr <- fmap sockAddrBluetoothAddr $ peek sockaddrPtr
          newStatus <- newMVar Connected
          return (MkSocket newFd family sockType proto newStatus, bdaddr)

import Network.Bluetooth.Utils
import Network.Socket
import Network.Socket.Internal

import System.Posix.Internals (setNonBlockingFD)

#include <bluetooth/bluetooth.h>
#include <sys/socket.h>
