stdio-0.2.0.0: A simple and high performance IO toolkit for Haskell

Copyright(c) Dong Han 2018
LicenseBSD
Maintainerwinterland1989@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Std.IO.UDP

Contents

Description

This module provides an API for creating UDP sender and receiver.

Synopsis

TCP Client

data UDP Source #

UDP socket.

UDP socket is not thread safe, don't use it among multiple thread! UDP is not a sequential protocol, thus not an instance of 'Input/Output'. Message are received or sent individually, we do provide batch receiving to improve performance under high load.

Instances
Show UDP Source # 
Instance details

Defined in Std.IO.UDP

Methods

showsPrec :: Int -> UDP -> ShowS #

show :: UDP -> String #

showList :: [UDP] -> ShowS #

initUDP :: HasCallStack => UDPConfig -> Resource UDP Source #

Initialize a UDP socket.

data UDPConfig Source #

UDP options.

Though technically message length field in the UDP header is a max of 65535, but large packets could be more likely dropped by routers, usually a packet(IPV4) with a payload <= 508 bytes is considered safe.

Constructors

UDPConfig 

Fields

  • recvMsgSize :: !Int32

    maximum size of a received message

  • recvBatchSize :: !Int

    how many messages we want to receive per uv loop, inside each uv_run, we do batch receiving, increase this number can improve receiving performance, at the cost of memory and potential GHC thread starving.

  • sendMsgSize :: !Int

    maximum size of sending buffer

  • localUDPAddr :: Maybe (SockAddr, UVUDPFlag)

    do we want bind a local address before receiving & sending? set to Nothing to let OS pick a random one.

Instances
Eq UDPConfig Source # 
Instance details

Defined in Std.IO.UDP

Ord UDPConfig Source # 
Instance details

Defined in Std.IO.UDP

Show UDPConfig Source # 
Instance details

Defined in Std.IO.UDP

defaultUDPConfig :: UDPConfig Source #

default UDPConfig, defaultUDPConfig = UDPConfig 512 6 512 Nothing

data UVUDPFlag where Source #

Bundled Patterns

pattern UV_UDP_DEFAULT :: UVUDPFlag 
pattern UV_UDP_IPV6ONLY :: UVUDPFlag 
pattern UV_UDP_REUSEADDR :: UVUDPFlag 
Instances
Eq UVUDPFlag Source # 
Instance details

Defined in Std.IO.UV.FFI

Num UVUDPFlag Source # 
Instance details

Defined in Std.IO.UV.FFI

Ord UVUDPFlag Source # 
Instance details

Defined in Std.IO.UV.FFI

Show UVUDPFlag Source # 
Instance details

Defined in Std.IO.UV.FFI

Storable UVUDPFlag Source # 
Instance details

Defined in Std.IO.UV.FFI

Bits UVUDPFlag Source # 
Instance details

Defined in Std.IO.UV.FFI

FiniteBits UVUDPFlag Source # 
Instance details

Defined in Std.IO.UV.FFI

recvUDP :: HasCallStack => UDP -> IO [(Maybe SockAddr, Bool, Bytes)] Source #

Recv messages from UDP socket, return source address if available, and a Bool to indicate if the message is partial (larger than receive buffer size).

sendUDP :: HasCallStack => UDP -> SockAddr -> Bytes -> IO () Source #

Send a UDP message to target address.

WARNING: A InvalidArgument with errno UV_EMSGSIZE will be thrown if message is larger than sendMsgSize.

multicast and broadcast