conduit-extra-1.1.17: Batteries included conduit: adapters for common libraries.

Safe Haskell | None
Language | Haskell98

Data.Conduit.Network.UDP

Contents

- UDP message representation
- Basic utilities
- Helper Utilities

Synopsis

- data Message :: * = Message {
  - msgData :: ~ByteString
  - msgSender :: ~SockAddr
  }
- sourceSocket :: MonadIO m => Socket -> Int -> Producer m Message
- sinkSocket :: MonadIO m => Socket -> Consumer ByteString m ()
- sinkAllSocket :: MonadIO m => Socket -> Consumer ByteString m ()
- sinkToSocket :: MonadIO m => Socket -> Consumer Message m ()
- sinkAllToSocket :: MonadIO m => Socket -> Consumer Message m ()
- data HostPreference :: *

# UDP message representation

data Message :: * #

Representation of a single UDP message

Constructors

Message |

Fields

- msgData :: ~ByteString
- msgSender :: ~SockAddr

# Basic utilities

sourceSocket :: MonadIO m => Socket -> Int -> Producer m Message Source #

Stream messages from the socket.

The given `len` defines the maximum packet size. Every produced item contains the message payload and the origin address.

This function does not automatically close the socket.

sinkSocket :: MonadIO m => Socket -> Consumer ByteString m () Source #

Stream messages to the connected socket.

The payload is sent using `send`, so some of it might be lost.

This function does not automatically close the socket.

sinkAllSocket :: MonadIO m => Socket -> Consumer ByteString m () Source #

Stream messages to the connected socket.

The payload is sent using `sendAll`, so it might end up in multiple packets.

This function does not automatically close the socket.

sinkToSocket :: MonadIO m => Socket -> Consumer Message m () Source #

Stream messages to the socket.

Every handled item contains the message payload and the destination address. The payload is sent using `sendTo`, so some of it might be lost.

This function does not automatically close the socket.

sinkAllToSocket :: MonadIO m => Socket -> Consumer Message m () Source #

Stream messages to the socket.

Every handled item contains the message payload and the destination address. The payload is sent using `sendAllTo`, so it might end up in multiple packets.

This function does not automatically close the socket.

# Helper Utilities

data HostPreference :: * #

Which host to bind.

Note: The `IsString` instance recognizes the following special values:

- `*` means `HostAny` - "any IPv4 or IPv6 hostname"
- `*4` means `HostIPv4` - "any IPv4 or IPv6 hostname, IPv4 preferred"
- `!4` means `HostIPv4Only` - "any IPv4 hostname"
- `*6` means `HostIPv6`@ - "any IPv4 or IPv6 hostname, IPv6 preferred"
- `!6` means `HostIPv6Only` - "any IPv6 hostname"

Note that the permissive `*` values allow binding to an IPv4 or an IPv6 hostname, which means you might be able to successfully bind to a port more times than you expect (eg once on the IPv4 localhost 127.0.0.1 and again on the IPv6 localhost 0:0:0:0:0:0:0:1).

Any other value is treated as a hostname. As an example, to bind to the IPv4 local host only, use "127.0.0.1".

Instances

Eq HostPreference |
Methods (==) :: HostPreference -> HostPreference -> Bool # (/=) :: HostPreference -> HostPreference -> Bool #
Ord HostPreference |
Methods compare :: HostPreference -> HostPreference -> Ordering # (<) :: HostPreference -> HostPreference -> Bool # (<=) :: HostPreference -> HostPreference -> Bool # (>) :: HostPreference -> HostPreference -> Bool # (>=) :: HostPreference -> HostPreference -> Bool # max :: HostPreference -> HostPreference -> HostPreference # min :: HostPreference -> HostPreference -> HostPreference #
Read HostPreference |
Methods readsPrec :: Int -> ReadS HostPreference # readList :: ReadS [HostPreference] # readPrec :: ReadPrec HostPreference # readListPrec :: ReadPrec [HostPreference] #
Show HostPreference |
Methods showsPrec :: Int -> HostPreference -> ShowS # show :: HostPreference -> String # showList :: [HostPreference] -> ShowS #
IsString HostPreference |
Methods fromString :: String -> HostPreference #