cvFromWayland :: Fd -> IO (BS.ByteString, [Fd])
recvFromWayland socket = allocaArray 4096 $ \cbuf -> do
    CC.threadWaitRead $ fromIntegral socket
    alloca $ \nFds_ptr ->
        allocaArray (4*28) $ \fdArray -> do
            len <- c_recvmsg_wayland (fromIntegral socket) cbuf 4096 fdArray (4*28) nFds_ptr
            if len < 0
                then ioError $ userError "recvmsg failed"
                else do
                    bs <- BS.packCStringLen (cbuf, fromIntegral len)
                    nFds <- peek nFds_ptr
                    fds <- peekArray (fromIntegral nFds) fdArray
                    return (bs, map fromIntegral fds)

recvFromWayland :: Fd -> IO (BS.ByteString, [Fd])
recvFromWayland socket = allocaArray 4096 $ \cbuf -> do
    CC.threadWaitRead $ fromIntegral socket
    alloca $ \nFds_ptr ->
        allocaArray (4*28) $ \fdArray -> do
            len <- c_recvmsg_wayland (fromIntegral socket) cbuf 4096 fdArray (4*28) nFds_ptr
            if len < 0
                then ioError $ userError "recvmsg failed"
                else do
                    bs <- BS.packCStringLen (cbuf, fromIntegral len)
                    nFds <- peek nFds_ptr
                    fds <- peekArray (fromIntegral nFds) fdArray
                    return (bs, map fromIntegral fds)
recvFromWayland socket = allocaArray 4096 $ \cbuf -> do
    CC.threadWaitRead $ fromIntegral socket
    alloca $ \nFds_ptr ->
        allocaArray (4*28) $ \fdArray -> do
            len <- c_recvmsg_wayland (fromIntegral socket) cbuf 4096 fdArray (4*28) nFds_ptr
            if len < 0
                then ioError $ userError "recvmsg failed"
                else do
                    bs <- BS.packCStringLen (cbuf, fromIntegral len)
                    nFds <- peek nFds_ptr
                    fds <- peekArray (fromIntegral nFds) fdArray
                    return (bs, map fromIntegral fds)