posix-api-0.3.0.0: posix bindings

Safe HaskellNone
LanguageHaskell2010

Linux.Socket

Contents

Synopsis

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 sockaddr size

-> 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 sockaddr size. Non-zero indicates that at least one sockaddr required 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_TRUNC is 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.

uninterruptibleReceiveMultipleMessageC Source #

Arguments

:: Fd

Socket

-> MutablePrimArray RealWorld CInt

Buffer for payload lengths

-> MutablePrimArray RealWorld SocketAddressInternet

Buffer for sockaddr_ins

-> 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 #

Arguments

:: 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 #

Arguments

:: 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 #

Constructors

SocketFlags CInt 
Instances
Eq SocketFlags Source # 
Instance details

Defined in Linux.Socket.Types

Semigroup SocketFlags Source # 
Instance details

Defined in Linux.Socket.Types

Monoid SocketFlags Source # 
Instance details

Defined in Linux.Socket.Types

Bits SocketFlags Source # 
Instance details

Defined in Linux.Socket.Types

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.