Hi Brandon,<br><br> Most of what you say makes sense. However, at some places in your narrative aren't you mixing up my aioError and aioReturn?(or aio_error and aio_return, respectively). E.g. aioReturn should return the byte count and not errno?<br>
<br> If you want to stick close to the C interface:<div><br></div><div>aioReturn :: AIOCB -> IO (AIOCB, Errno)</div><div class="Ih2E3d"><div>aioReturn aiocb = do</div> allocaBytes (#const sizeof(struct aiocb)) $ \ p_aiocb -> do<br>
poke p_aiocb aiocb<br></div> err <- c_aio_return p_aiocb<br> aiocb <- peek p_aiocb<br> return (aiocb, Errno err)<div><br></div><br><br>Vasili<br><br><div class="gmail_quote">On Wed, Jul 2, 2008 at 1:07 AM, Brandon S. Allbery KF8NH <<a href="mailto:allbery@ece.cmu.edu">allbery@ece.cmu.edu</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style=""><br><div><div class="Ih2E3d"><div>On 2008 Jul 2, at 1:42, Galchin, Vasili wrote:</div>
<br></div><blockquote type="cite"><div class="Ih2E3d"> errno <- throwErrnoIfMinus1 "aioError" (c_aio_error p_aiocb)<br><br></div><div class="Ih2E3d">"ghc" thinks that "Errno" should be an instance of "Num":<br>
<br>System/Posix/Aio.hsc:117:15:<br> No instance for (Num Errno)<br></div></blockquote><br></div><div>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.</div>
<div><br></div><div>(What were you expecting for "count"? I see none, just an errno.)</div><div><br></div><div>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.</div>
<div><br></div><div>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:</div><div>
<br></div><div>aioReturn :: AIOCB -> IO (AIOCB, Errno)</div><div class="Ih2E3d"><div>aioReturn aiocb = do</div> allocaBytes (#const sizeof(struct aiocb)) $ \ p_aiocb -> do<br> poke p_aiocb aiocb<br></div> err <- c_aio_return p_aiocb<br>
aiocb <- peek p_aiocb<br> return (aiocb, Errno err)<div><br></div><div>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).</div>
<div><br></div><div> <span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div style="">
<span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div>
<font face="Monaco"><span style="font-family: Monaco;"><span style="font-family: Monaco;">-- </span></span></font></div><div><font face="Monaco"><span style="font-family: Monaco;"><span style="font-family: Monaco;">brandon s. allbery [solaris,freebsd,perl,pugs,haskell] <a href="mailto:allbery@kf8nh.com" target="_blank">allbery@kf8nh.com</a></span></span></font></div>
<div><font face="Monaco"><span style="font-family: Monaco;"><span style="font-family: Monaco;">system administrator [openafs,heimdal,too many hats] <a href="mailto:allbery@ece.cmu.edu" target="_blank">allbery@ece.cmu.edu</a></span></span></font></div>
<div><font face="Monaco"><span style="font-family: Monaco;"><span style="font-family: Monaco;">electrical and computer engineering, carnegie mellon university KF8NH</span></span></font></div><span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><br>
</span></span></span></div></span> </div><br></div></blockquote></div><br>