[Haskell-cafe] eyes again please .... on my POSIX aio code

Galchin, Vasili vigalchin at gmail.com
Sat Jul 5 00:06:12 EDT 2008


Hello,

      I have modified my aioError and aioReturn to hopefully be more in line
with the actual aio_error and aio_return signatures, respectively. In the
first implementation I had suffered a serious brain f**t ... oh well .....
The implementations below are still somewhat preliminary. Not seemingly
rocket science .... I am still not getting a correct count from aioReturn ..
should be 20 but I get 0! I have a C program which behaves properly giving
20 for aio_return! grrrrrr!

aioReturn :: AIOCB -> IO (AIOCB, ByteCount)
aioReturn aiocb = do
   allocaBytes (#const sizeof(struct aiocb)) $ \ p_aiocb -> do
      poke p_aiocb aiocb
-- DO A PEEK HERE!!!!!
--      count <- throwErrnoIfMinus1 "aioReturn" (c_aio_return  p_aiocb)
      count <- (c_aio_return  p_aiocb)
      putStrLn ("count -> " ++ (show count))
      aiocb <- peek p_aiocb
      putStrLn "aioReturn"
      aiocb1 <- peek p_aiocb
      dumpAIOCB aiocb1
      return (aiocb, fromIntegral count)

foreign import ccall safe "aio.h aio_return"
    c_aio_return :: Ptr AIOCB -> IO CInt



aioError :: AIOCB -> IO (Errno)
aioError aiocb = do
   allocaBytes (#const sizeof(struct aiocb)) $ \ p_aiocb -> do
      poke p_aiocb aiocb
      --throwErrnoIfMinus1 "aioError" (c_aio_error  p_aiocb)
      errno <- (c_aio_error  p_aiocb)
      putStrLn ("errno -> " ++ (show errno))
      putStrLn "aioError"
      aiocb1 <- peek p_aiocb
      dumpAIOCB aiocb1
      return (Errno errno)

foreign import ccall safe "aio.h aio_error"
    c_aio_error :: Ptr AIOCB -> IO CInt



I added an internal helper function dumpAIOCB to print out the aiocb at
points for sanity checking!!

dumpAIOCB :: AIOCB -> IO ()
dumpAIOCB (AIOCB aioFd aioLioOpcode aioReqPrio aioOffset aioBuf aioBytes
aioSigevent) = do
               putStrLn "aiocb dump"
               putStrLn ("fd => " ++ (show aioFd))
               putStrLn ("opcode => " ++ (show aioLioOpcode))
               putStrLn ("prio => " ++ (show aioReqPrio))
               putStrLn ("offset => " ++ (show aioOffset))
               -- aioBuf
               putStrLn ("nbytes => " ++ (show aioBytes) ++ "\n")
               -- aioSigevent


Kind regards, Vasili
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080704/7a816677/attachment.htm


More information about the Haskell-Cafe mailing list