| Portability | non-portable (POSIX.1, XPG4.2; hsc2hs, FFI) |
|---|---|
| Stability | experimental |
| Maintainer | wren@community.haskell.org |
| Safe Haskell | None |
System.Posix.Types.Iovec
Contents
Description
Imports the C struct iovec type and provides conversion between
CIovecs and strict ByteStrings.
- data CIovec = CIovec {}
- unsafeByteString2CIovec :: ByteString -> CIovec
- touchByteString :: ByteString -> IO ()
- unsafeUseAsCIovec :: ByteString -> (CIovec -> IO a) -> IO a
- useAsCIovec :: ByteString -> (CIovec -> IO a) -> IO a
The struct iovec type
Haskell type representing the C struct iovec type. This is
exactly like except there's actually struct
definition on the C side.
CStringLen
unsafeByteString2CIovec :: ByteString -> CIovecSource
O(1) construction Convert a ByteString into an CIovec.
This function is unsafe in two ways:
- After calling this function the
CIovecshares the underlying byte buffer with the originalByteString. Thus, modifying theCIoveceither in C or using poke will cause the contents of theByteStringto change, breaking referential transparency. OtherByteStringscreated by sharing (such as those produced viatakeordrop) will also reflect these changes. - Also, even though the
CIovecshares the underlying byte buffer, it does so in a way that will not keep the originalByteStringalive with respect to garbage collection. Thus, the byte buffer could be collected out from under theCIovec. To prevent this, you must usetouchByteStringafter the last point where theCIovecis needed.
touchByteString :: ByteString -> IO ()Source
Keep the ByteString alive. See unsafeByteString2CIovec.
unsafeUseAsCIovec :: ByteString -> (CIovec -> IO a) -> IO aSource
O(1) construction Use a ByteString with a function requiring
a CIovec.
This function does zero copying, and merely unwraps a ByteString
to appear as an CIovec. It is unsafe in the same way as
unsafeByteString2CIovec.
useAsCIovec :: ByteString -> (CIovec -> IO a) -> IO aSource
O(n) construction Use a ByteString with a function requiring
a CIovec.
As with useAsCString and useAsCStringLen, this function
makes a copy of the original ByteString via memcpy(3). The
copy will be freed automatically. See unsafeUseAsCIovec for a
zero-copying version.