| threaded = Event.threadDelay time
#endif
| otherwise = IO $ \s ->
- case fromIntegral time of { I# time# ->
+ case time of { I# time# ->
case delay# time# s of { s' -> (# s', () #)
}}
import GHC.Ptr
import Data.Word
import GHC.Num
-import GHC.Real
import Data.Maybe
-- import GHC.IO
import GHC.IO.Device as IODevice
readBuf dev bbuf = do
let bytes = bufferAvailable bbuf
res <- withBuffer bbuf $ \ptr ->
- RawIO.read dev (ptr `plusPtr` bufR bbuf) (fromIntegral bytes)
- let res' = fromIntegral res
- return (res', bbuf{ bufR = bufR bbuf + res' })
+ RawIO.read dev (ptr `plusPtr` bufR bbuf) bytes
+ return (res, bbuf{ bufR = bufR bbuf + res })
-- zero indicates end of file
readBufNonBlocking :: RawIO dev => dev -> Buffer Word8
readBufNonBlocking dev bbuf = do
let bytes = bufferAvailable bbuf
res <- withBuffer bbuf $ \ptr ->
- IODevice.readNonBlocking dev (ptr `plusPtr` bufR bbuf) (fromIntegral bytes)
+ IODevice.readNonBlocking dev (ptr `plusPtr` bufR bbuf) bytes
case res of
Nothing -> return (Nothing, bbuf)
- Just n -> return (Just n, bbuf{ bufR = bufR bbuf + fromIntegral n })
+ Just n -> return (Just n, bbuf{ bufR = bufR bbuf + n })
writeBuf :: RawIO dev => dev -> Buffer Word8 -> IO (Buffer Word8)
writeBuf dev bbuf = do
let bytes = bufferElems bbuf
withBuffer bbuf $ \ptr ->
- IODevice.write dev (ptr `plusPtr` bufL bbuf) (fromIntegral bytes)
+ IODevice.write dev (ptr `plusPtr` bufL bbuf) bytes
return bbuf{ bufL=0, bufR=0 }
-- XXX ToDo
writeBufNonBlocking dev bbuf = do
let bytes = bufferElems bbuf
res <- withBuffer bbuf $ \ptr ->
- IODevice.writeNonBlocking dev (ptr `plusPtr` bufL bbuf)
- (fromIntegral bytes)
+ IODevice.writeNonBlocking dev (ptr `plusPtr` bufL bbuf) bytes
return (res, bufferAdjustL res bbuf)
-- always returns EISDIR if the file is a directory and was opened
-- for writing, so I think we're ok with a single open() here...
fd <- throwErrnoIfMinus1Retry "openFile"
- (c_open f (fromIntegral oflags) 0o666)
+ (c_open f oflags 0o666)
(fD,fd_type) <- mkFD fd iomode Nothing{-no stat-}
False{-not a socket-}
-- Reading and Writing
fdRead :: FD -> Ptr Word8 -> Int -> IO Int
-fdRead fd ptr bytes = do
- r <- readRawBufferPtr "GHC.IO.FD.fdRead" fd ptr 0 (fromIntegral bytes)
- return (fromIntegral r)
+fdRead fd ptr bytes
+ = readRawBufferPtr "GHC.IO.FD.fdRead" fd ptr 0 (fromIntegral bytes)
fdReadNonBlocking :: FD -> Ptr Word8 -> Int -> IO (Maybe Int)
fdReadNonBlocking fd ptr bytes = do
0 (fromIntegral bytes)
case r of
(-1) -> return (Nothing)
- n -> return (Just (fromIntegral n))
+ n -> return (Just n)
fdWrite :: FD -> Ptr Word8 -> Int -> IO ()
) where
import GHC.Base
-import GHC.Real
import GHC.Show
import Data.Maybe
-- import Control.Monad
Just RegularFile -> Nothing
-- no stat required for streams etc.:
Just other -> Just (other,0,0)
- (fd,fd_type) <- FD.mkFD (fromIntegral fdint) iomode mb_stat
+ (fd,fd_type) <- FD.mkFD fdint iomode mb_stat
is_socket
is_socket
mkHandleFromFD fd fd_type filepath iomode is_socket
-- translation instead.
fdToHandle :: Posix.FD -> IO Handle
fdToHandle fdint = do
- iomode <- Posix.fdGetMode (fromIntegral fdint)
- (fd,fd_type) <- FD.mkFD (fromIntegral fdint) iomode Nothing
+ iomode <- Posix.fdGetMode fdint
+ (fd,fd_type) <- FD.mkFD fdint iomode Nothing
False{-is_socket-}
-- NB. the is_socket flag is False, meaning that:
-- on Windows we're guessing this is not a socket (XXX)
-- just copy the data in and update bufR.
then do withRawBuffer raw $ \praw ->
copyToRawBuffer old_raw (w*charSize)
- praw (fromIntegral (count*charSize))
+ praw (count*charSize)
writeIORef ref old_buf{ bufR = w + count }
return (emptyBuffer raw sz WriteBuffer)
-- There's enough room in the buffer:
-- just copy the data in and update bufR.
then do debugIO ("hPutBuf: copying to buffer, w=" ++ show w)
- copyToRawBuffer old_raw w ptr (fromIntegral count)
+ copyToRawBuffer old_raw w ptr count
writeIORef haByteBuffer old_buf{ bufR = w + count }
return count
return (so_far + count)
else do
- copyFromRawBuffer ptr raw (fromIntegral r) (fromIntegral avail)
+ copyFromRawBuffer ptr raw r avail
let buf' = buf{ bufR=0, bufL=0 }
writeIORef haByteBuffer buf'
let remaining = count - avail
loop :: FD -> Int -> Int -> IO Int
loop fd off bytes | bytes <= 0 = return (so_far + off)
loop fd off bytes = do
- r <- RawIO.read (fd::FD) (ptr `plusPtr` off) (fromIntegral bytes)
+ r <- RawIO.read (fd::FD) (ptr `plusPtr` off) bytes
if r == 0
then return (so_far + off)
else loop fd (off + r) (bytes - r)
return (so_far + count)
else do
- copyFromRawBuffer ptr raw (fromIntegral r) (fromIntegral avail)
+ copyFromRawBuffer ptr raw r avail
let buf' = buf{ bufR=0, bufL=0 }
writeIORef haByteBuffer buf'
let remaining = count - avail
#ifdef __GLASGOW_HASKELL__
import GHC.Base
-import GHC.Real
import GHC.IO hiding ( onException )
import GHC.IO.IOMode
import GHC.IO.Handle.FD
else ioError (errnoToIOError loc errno Nothing (Just tmp_dir))
else do
- (fD,fd_type) <- FD.mkFD (fromIntegral fd) ReadWriteMode Nothing{-no stat-}
+ (fD,fd_type) <- FD.mkFD fd ReadWriteMode Nothing{-no stat-}
False{-is_socket-}
True{-is_nonblock-}