[Haskell-cafe] Re: POSIX AIO (asych I/O) ...

Galchin, Vasili vigalchin at gmail.com
Wed Jul 2 02:47:46 EDT 2008


Thanks, Brandon!! I understand most of what you say but let me ponder!

Kind regards, Vasili

On Wed, Jul 2, 2008 at 1:07 AM, Brandon S. Allbery KF8NH <
allbery at ece.cmu.edu> wrote:

>
> On 2008 Jul 2, at 1:42, Galchin, Vasili wrote:
>
>       errno <- throwErrnoIfMinus1 "aioError" (c_aio_error  p_aiocb)
>
> "ghc" thinks that "Errno" should be an instance of "Num":
>
> System/Posix/Aio.hsc:117:15:
>     No instance for (Num Errno)
>
>
> I expect so it can compare it to -1(throwErrnoIfMinusOne).  But if the
> return value is actually an errno and not -1 to indicate error (which it is
> if I read the manpage correctly), you don't want throwErrnoIfMinus1 anyway;
> I suspect you want to wrap the return value of c_aio_return (which should be
> IO CInt) in an Errno constructor, then use errnoToIOError if you really want
> to raise an IOError.
>
> (What were you expecting for "count"?  I see none, just an errno.)
>
> Note that it *never* returns -1; it returns 0 for successful completion for
> the aiocb, EINPROGRESS if it's still working, and the appropriate errno if
> it failed.
>
> You might want to decide if you want to use the aio_return style interface
> or something more Haskell-ish before designing this part of the API.  If you
> want to stick close to the C interface:
>
> aioReturn :: AIOCB -> IO (AIOCB, Errno)
> aioReturn aiocb = do
>    allocaBytes (#const sizeof(struct aiocb)) $ \ p_aiocb -> do
>       poke p_aiocb aiocb
>       err <- c_aio_return  p_aiocb
>       aiocb <- peek p_aiocb
>       return (aiocb, Errno err)
> I'd actually consider something more Haskellish, e.g. a variant of StateT
> IO where the state is the aiocb and errno, the errno initialized to
> eINPROGRESS and set by aioReturn and aioError (and once aioReturn is called,
> it can't be called again so return the cached value if needed).
>
> --
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
> system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
> electrical and computer engineering, carnegie mellon university    KF8NH
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080702/3de1571c/attachment.htm


More information about the Haskell-Cafe mailing list