[Haskell-cafe] ByteStrings, FFI, iovec

Donn Cave donn at avvanta.com
Sat Mar 28 17:05:28 EDT 2009


Quoth Antoine Latter <aslatter at gmail.com>,

> ...  I haven't put this into practice yet,

Really?  haven't even tried it?

Well, this is just a comment, since I'm not a qualified guru or
anything, but I have been using the foreign array functions to do
some of the things you're doing by hand, which I suppose in your
case means you would need to make a Storable instance for IOVec.
Maybe c2hs does this for you?  dunno.

That done, I would have something like

 withIOVec :: [P.ByteString] -> ((Ptr IOVec) -> CInt -> IO a) -> IO a
 withIOVec ss f = wv ss []
   where
     wv [] si = withArray (reverse si) $ \ pa -> f pa (length si)
     wv (a:ax) si = P.useAsCStringLen a $ \ (p, n) -> wv ax ((IOVec p n):si)

 writev fd ss = withIOVec ss $ c_writev fd

	Donn



More information about the Haskell-Cafe mailing list