| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Linux.Socket
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))
- 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 #
Arguments
| :: 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 #
Arguments
| :: 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 sockaddrs of the remote endpoints. These are
written in contiguous memory to a bytearray of length
max_num_msgs * expected_sockaddr_sz. The sockaddrs 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 sockaddrs in it. All byte arrays returned by
this function are pinned.
The values in the returned tuple are:
- Error-checking number for
sockaddrsize. Non-zero indicates that at least onesockaddrrequired a number of bytes other than the expected number. - Pinned bytearray with all of the
sockaddrs in it as a array of structures. - The size of the largest message received. If
MSG_TRUNCis used this lets the caller know if one or more messages were truncated. - The message data of each message.
The sockaddrs bytearray and the unlifted array of messages are
guaranteed to have the same number of elements.
Types
newtype SocketFlags Source #
Constructors
| SocketFlags CInt |
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.