Copyright | 2010--2022 wren romano |
---|---|
License | BSD-3-Clause |
Maintainer | [email protected] |
Stability | experimental |
Portability | non-portable (POSIX.1, XPG4.2; hsc2hs, FFI) |
Safe Haskell | None |
Language | Haskell2010 |
System.Posix.Types.Iovec
Contents
Description
Imports the C struct iovec
type and provides conversion between
CIovec
s and strict ByteString
s.
Synopsis
- 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 CStringLen
except there's actually
struct definition on the C side.
Instances
unsafeByteString2CIovec :: ByteString -> CIovec Source #
O(1) construction Convert a ByteString
into an CIovec
.
This function is unsafe in two ways:
- After calling this function the
CIovec
shares the underlying byte buffer with the originalByteString
. Thus, modifying theCIovec
either in C or using poke will cause the contents of theByteString
to change, breaking referential transparency. OtherByteStrings
created by sharing (such as those produced viatake
ordrop
) will also reflect these changes. - Also, even though the
CIovec
shares the underlying byte buffer, it does so in a way that will not keep the originalByteString
alive with respect to garbage collection. Thus, the byte buffer could be collected out from under theCIovec
. To prevent this, you must usetouchByteString
after the last point where theCIovec
is needed.
touchByteString :: ByteString -> IO () Source #
Keep the ByteString
alive. See unsafeByteString2CIovec
.
unsafeUseAsCIovec :: ByteString -> (CIovec -> IO a) -> IO a Source #
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 a Source #
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.