Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- uninterruptibleReceiveMultipleMessageA :: Fd -> CSize -> CUInt -> MessageFlags Receive -> IO (Either Errno (CUInt, UnliftedArray ByteArray))
- uninterruptibleReceiveMultipleMessageB :: Fd -> CInt -> CSize -> CUInt -> MessageFlags Receive -> IO (Either Errno (CInt, ByteArray, CUInt, UnliftedArray ByteArray))
- uninterruptibleReceiveMultipleMessageC :: Fd -> MutablePrimArray RealWorld CInt -> MutablePrimArray RealWorld SocketAddressInternet -> MutableUnliftedArray RealWorld (MutableByteArray RealWorld) -> CUInt -> MessageFlags Receive -> IO (Either Errno CInt)
- uninterruptibleReceiveMultipleMessageD :: Fd -> MutablePrimArray RealWorld CInt -> MutableUnliftedArray RealWorld (MutableByteArray RealWorld) -> CUInt -> MessageFlags Receive -> IO (Either Errno CInt)
- uninterruptibleAccept4 :: Fd -> CInt -> SocketFlags -> IO (Either Errno (CInt, SocketAddress, Fd))
- newtype SocketFlags = SocketFlags CInt
- headerInclude :: OptionName
- dontWait :: MessageFlags m
- truncate :: MessageFlags Receive
- controlTruncate :: MessageFlags Receive
- closeOnExec :: SocketFlags
- nonblocking :: SocketFlags
- applySocketFlags :: SocketFlags -> Type -> Type
- sizeofUdpHeader :: CInt
- pokeUdpHeaderSourcePort :: Addr -> Word16 -> IO ()
- pokeUdpHeaderDestinationPort :: Addr -> Word16 -> IO ()
- pokeUdpHeaderLength :: Addr -> Word16 -> IO ()
- pokeUdpHeaderChecksum :: Addr -> Word16 -> IO ()
- sizeofIpHeader :: CInt
- pokeIpHeaderVersionIhl :: Addr -> Word8 -> IO ()
- pokeIpHeaderTypeOfService :: Addr -> Word8 -> IO ()
- pokeIpHeaderTotalLength :: Addr -> Word16 -> IO ()
- pokeIpHeaderIdentifier :: Addr -> Word16 -> IO ()
- pokeIpHeaderFragmentOffset :: Addr -> Word16 -> IO ()
- pokeIpHeaderTimeToLive :: Addr -> Word8 -> IO ()
- pokeIpHeaderProtocol :: Addr -> Word8 -> IO ()
- pokeIpHeaderChecksum :: Addr -> Word16 -> IO ()
- pokeIpHeaderSourceAddress :: Addr -> Word32 -> IO ()
- pokeIpHeaderDestinationAddress :: Addr -> Word32 -> IO ()
Functions
uninterruptibleReceiveMultipleMessageA Source #
:: Fd | Socket |
-> CSize | Maximum bytes per message |
-> CUInt | Maximum number of messages |
-> MessageFlags Receive | Flags |
-> IO (Either Errno (CUInt, UnliftedArray ByteArray)) |
Receive multiple messages. This does not provide the socket
addresses or the control messages. It does not use any of the
input-scattering that recvmmsg
offers, meaning that a single
datagram is never split across noncontiguous memory. It supplies
NULL
for the timeout argument. All of the messages must have the
same maximum size. All resulting byte arrays have been explicitly
pinned. In addition to bytearrays corresponding to each datagram,
this also provides the maximum msg_len
that recvmmsg
wrote
back out. This is provided so that users of MSG_TRUNC
can detect
when bytes were dropped from the end of a message (although it does
let the user figure out which message had bytes dropped).
uninterruptibleReceiveMultipleMessageB Source #
:: Fd | Socket |
-> CInt | Expected |
-> CSize | Maximum bytes per message |
-> CUInt | Maximum number of messages |
-> MessageFlags Receive | Flags |
-> IO (Either Errno (CInt, ByteArray, CUInt, UnliftedArray ByteArray)) |
Receive multiple messages. This is similar to
uninterruptibleReceiveMultipleMessageA
. However, it also
provides the sockaddr
s of the remote endpoints. These are
written in contiguous memory to a bytearray of length
max_num_msgs * expected_sockaddr_sz
. The sockaddr
s must
all be expected to be of the same length. This function
provides a sockaddr
size check that is non-zero when any
sockaddr
had a length other than the expected length.
This can be used to detect if the sockaddr
array has one or
more corrupt sockaddr
s in it. All byte arrays returned by
this function are pinned.
The values in the returned tuple are:
- Error-checking number for
sockaddr
size. Non-zero indicates that at least onesockaddr
required a number of bytes other than the expected number. - Pinned bytearray with all of the
sockaddr
s in it as a array of structures. - The size of the largest message received. If
MSG_TRUNC
is used this lets the caller know if one or more messages were truncated. - The message data of each message.
The sockaddr
s bytearray and the unlifted array of messages are
guaranteed to have the same number of elements.
uninterruptibleReceiveMultipleMessageC Source #
:: Fd | Socket |
-> MutablePrimArray RealWorld CInt | Buffer for payload lengths |
-> MutablePrimArray RealWorld SocketAddressInternet | Buffer for |
-> MutableUnliftedArray RealWorld (MutableByteArray RealWorld) | Buffers for payloads |
-> CUInt | Maximum number of datagrams to receive, length of buffers |
-> MessageFlags Receive | Flags |
-> IO (Either Errno CInt) |
All three buffer arguments need to have the same length (in elements, not bytes).
uninterruptibleReceiveMultipleMessageD Source #
:: Fd | Socket |
-> MutablePrimArray RealWorld CInt | Buffer for payload lengths |
-> MutableUnliftedArray RealWorld (MutableByteArray RealWorld) | Buffers for payloads |
-> CUInt | Maximum number of datagrams to receive, length of buffers |
-> MessageFlags Receive | Flags |
-> IO (Either Errno CInt) |
All three buffer arguments need to have the same length (in elements, not bytes). This discards the source addresses.
uninterruptibleAccept4 Source #
:: Fd | Listening socket |
-> CInt | Maximum socket address size |
-> SocketFlags | Set non-blocking and close-on-exec without extra syscall |
-> IO (Either Errno (CInt, SocketAddress, Fd)) | Peer information and connected socket |
Variant of uninterruptibleAccept
that allows setting
flags on the newly-accepted connection.
Types
newtype SocketFlags Source #
Instances
Option Names
headerInclude :: OptionName Source #
If enabled, the user supplies an IP header in front of the
user data. Valid only for SOCK_RAW
sockets.
Message Flags
dontWait :: MessageFlags m Source #
The MSG_DONTWAIT
receive flag or send flag.
truncate :: MessageFlags Receive Source #
The MSG_TRUNC
receive flag.
controlTruncate :: MessageFlags Receive Source #
The MSG_CTRUNC
receive flag.
Socket Flags
closeOnExec :: SocketFlags Source #
The SOCK_CLOEXEC
receive flag or send flag.
nonblocking :: SocketFlags Source #
The SOCK_NONBLOCK
receive flag or send flag.
Twiddle
applySocketFlags :: SocketFlags -> Type -> Type Source #
Linux extends the type
argument of
socket to allow
setting two socket flags on socket creation: SOCK_CLOEXEC
and
SOCK_NONBLOCK
. It is advisable to set SOCK_CLOEXEC
on when
opening a socket on linux. For example, we may open a TCP Internet
socket with:
uninterruptibleSocket internet (applySocketFlags closeOnExec stream) defaultProtocol
To additionally open the socket in nonblocking mode
(e.g. with SOCK_NONBLOCK
):
uninterruptibleSocket internet (applySocketFlags (closeOnExec <> nonblocking) stream) defaultProtocol
UDP Header
sizeofUdpHeader :: CInt Source #
The size of a udphdr
struct.
IPv4 Header
sizeofIpHeader :: CInt Source #
The size of an iphdr
struct.
pokeIpHeaderVersionIhl :: Addr -> Word8 -> IO () Source #
This poke function requires the user to pack the version and the internet header length (IHL), each 4 bits, into a single 8-bit word. The version should be in the most significant bits. This function will marshal the value appropriately depending on the platform's bit-endianness.