 bytes received


-- TODO limit number of `Fd`s to be sent to 28.
sendToWayland :: Fd -> BS.ByteString -> [Fd] -> IO CInt
sendToWayland socket bs fds = do
    CC.threadWaitWrite $ fromIntegral socket
    BS.useAsCStringLen bs sendData
    where
        c_fds = map fromIntegral fds
        sendData (bytePtr, byteLen) = withArrayLen c_fds $ \fdLen fdArray -> do
            let c_byteLen = fromIntegral byteLen
            let c_fdLen = fromIntegral fdLen
            len <- c_sendmsg_wayland (fromIntegral socket) bytePtr c_byteLen fdArray c_fdLen
            if len < 0
                then ioError $ userError "sendmsg failed"
                else return len


sendToWayland :: Fd -> BS.ByteString -> [Fd] -> IO CInt
sendToWayland socket bs fds = do
    CC.threadWaitWrite $ fromIntegral socket
    BS.useAsCStringLen bs sendData
    where
        c_fds = map fromIntegral fds
        sendData (bytePtr, byteLen) = withArrayLen c_fds $ \fdLen fdArray -> do
            let c_byteLen = fromIntegral byteLen
            let c_fdLen = fromIntegral fdLen
            len <- c_sendmsg_wayland (fromIntegral socket) bytePtr c_byteLen fdArray c_fdLen
            if len < 0
                then ioError $ userError "sendmsg failed"
                else return len
sendToWayland socket bs fds = do
    CC.threadWaitWrite $ fromIntegral socket
    BS.useAsCStringLen bs sendData
    where
        c_fds = map fromIntegral fds
        sendData (bytePtr, byteLen) = withArrayLen c_fds $ \fdLen fdArray -> do
            let c_byteLen = fromIntegral byteLen
            let c_fdLen = fromIntegral fdLen
            len <- c_sendmsg_wayland (fromIntegral socket) bytePtr c_byteLen fdArray c_fdLen
            if len < 0
                then ioError $ userError "sendmsg failed"
                else return len