unix-bytestring-0.4.0.1: Unix/Posix-specific functions for ByteStrings.
Copyright2010--2022 wren romano
LicenseBSD-3-Clause
Maintainerwren@cpan.org
Stabilityexperimental
Portabilitynon-portable (POSIX.1, XPG4.2; hsc2hs, FFI)
Safe HaskellSafe-Inferred
LanguageHaskell2010

System.Posix.Types.Iovec

Description

Imports the C struct iovec type and provides conversion between CIovecs and strict ByteStrings.

Synopsis

The struct iovec type

data CIovec Source #

Haskell type representing the C struct iovec type. This is exactly like CStringLen except there's actually struct definition on the C side.

Constructors

CIovec 

Fields

Instances

Instances details
Storable CIovec Source # 
Instance details

Defined in System.Posix.Types.Iovec

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 original ByteString. Thus, modifying the CIovec either in C or using poke will cause the contents of the ByteString to change, breaking referential transparency. Other ByteStrings created by sharing (such as those produced via take or drop) 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 original ByteString alive with respect to garbage collection. Thus, the byte buffer could be collected out from under the CIovec. To prevent this, you must use touchByteString after the last point where the CIovec 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.