Copyright | (c) Dong Han 2018 |
---|---|
License | BSD |
Maintainer | winterland1989@gmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
This module provides an API for creating UDP sender and receiver.
Synopsis
- data UDP = UDP {
- udpHandle :: !(Ptr UVHandle)
- udpSlot :: !UVSlot
- udpManager :: UVManager
- udpRecvLargeBuffer :: !(MutablePrimArray RealWorld Word8)
- udpRecvBufferSiz :: !Int32
- udpRecvBufferArray :: !(MutablePrimArray RealWorld (Ptr Word8))
- udpSendBuffer :: !(MutablePrimArray RealWorld Word8)
- udpClosed :: !(IORef Bool)
- initUDP :: HasCallStack => UDPConfig -> Resource UDP
- data UDPConfig = UDPConfig {
- recvMsgSize :: !Int32
- recvBatchSize :: !Int
- sendMsgSize :: !Int
- localUDPAddr :: Maybe (SockAddr, UVUDPFlag)
- defaultUDPConfig :: UDPConfig
- data UVUDPFlag where
- pattern UV_UDP_DEFAULT :: UVUDPFlag
- pattern UV_UDP_IPV6ONLY :: UVUDPFlag
- pattern UV_UDP_REUSEADDR :: UVUDPFlag
- recvUDP :: HasCallStack => UDP -> IO [(Maybe SockAddr, Bool, Bytes)]
- sendUDP :: HasCallStack => UDP -> SockAddr -> Bytes -> IO ()
- getSockName :: HasCallStack => UDP -> IO SockAddr
- data UVMembership where
- pattern UV_JOIN_GROUP :: UVMembership
- pattern UV_LEAVE_GROUP :: UVMembership
- setMembership :: HasCallStack => UDP -> CBytes -> CBytes -> UVMembership -> IO ()
- setMulticastLoop :: HasCallStack => UDP -> Bool -> IO ()
- setMulticastTTL :: HasCallStack => UDP -> Int -> IO ()
- setMulticastInterface :: HasCallStack => UDP -> CBytes -> IO ()
- setBroadcast :: HasCallStack => UDP -> Bool -> IO ()
- setTTL :: HasCallStack => UDP -> Int -> IO ()
TCP Client
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.
UDP | |
|
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.
UDPConfig | |
|
defaultUDPConfig :: UDPConfig Source #
default UDPConfig
, defaultUDPConfig = UDPConfig 512 6 512 Nothing
pattern UV_UDP_DEFAULT :: UVUDPFlag | |
pattern UV_UDP_IPV6ONLY :: UVUDPFlag | |
pattern UV_UDP_REUSEADDR :: UVUDPFlag |
Instances
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
.
getSockName :: HasCallStack => UDP -> IO SockAddr Source #
multicast and broadcast
data UVMembership where Source #
pattern UV_JOIN_GROUP :: UVMembership | |
pattern UV_LEAVE_GROUP :: UVMembership |
Instances
Eq UVMembership Source # | |
Defined in Std.IO.UV.FFI (==) :: UVMembership -> UVMembership -> Bool # (/=) :: UVMembership -> UVMembership -> Bool # | |
Ord UVMembership Source # | |
Defined in Std.IO.UV.FFI compare :: UVMembership -> UVMembership -> Ordering # (<) :: UVMembership -> UVMembership -> Bool # (<=) :: UVMembership -> UVMembership -> Bool # (>) :: UVMembership -> UVMembership -> Bool # (>=) :: UVMembership -> UVMembership -> Bool # max :: UVMembership -> UVMembership -> UVMembership # min :: UVMembership -> UVMembership -> UVMembership # | |
Show UVMembership Source # | |
Defined in Std.IO.UV.FFI showsPrec :: Int -> UVMembership -> ShowS # show :: UVMembership -> String # showList :: [UVMembership] -> ShowS # |
setMembership :: HasCallStack => UDP -> CBytes -> CBytes -> UVMembership -> IO () Source #
setMulticastLoop :: HasCallStack => UDP -> Bool -> IO () Source #
setMulticastTTL :: HasCallStack => UDP -> Int -> IO () Source #
setMulticastInterface :: HasCallStack => UDP -> CBytes -> IO () Source #
setBroadcast :: HasCallStack => UDP -> Bool -> IO () Source #