Safe Haskell | None |
---|---|
Language | Haskell98 |
Data.Streaming.Network
- data ServerSettings
- data ClientSettings
- data HostPreference
- data Message = Message {
- msgData :: !ByteString
- msgSender :: !SockAddr
- data AppData
- data ServerSettingsUnix
- data ClientSettingsUnix
- data AppDataUnix
- serverSettingsTCP :: Int -> HostPreference -> ServerSettings
- serverSettingsTCPSocket :: Socket -> ServerSettings
- clientSettingsTCP :: Int -> ByteString -> ClientSettings
- serverSettingsUDP :: Int -> HostPreference -> ServerSettings
- clientSettingsUDP :: Int -> ByteString -> ClientSettings
- serverSettingsUnix :: FilePath -> ServerSettingsUnix
- clientSettingsUnix :: FilePath -> ClientSettingsUnix
- message :: ByteString -> SockAddr -> Message
- class HasPort a where
- class HasAfterBind a where
- class HasReadWrite a where
- readLens :: Functor f => (IO ByteString -> f (IO ByteString)) -> a -> f a
- writeLens :: Functor f => ((ByteString -> IO ()) -> f (ByteString -> IO ())) -> a -> f a
- class HasPath a where
- setPort :: HasPort a => Int -> a -> a
- setHost :: ByteString -> ClientSettings -> ClientSettings
- setAddrFamily :: Family -> ClientSettings -> ClientSettings
- setAfterBind :: HasAfterBind a => (Socket -> IO ()) -> a -> a
- setNeedLocalAddr :: Bool -> ServerSettings -> ServerSettings
- setPath :: HasPath a => FilePath -> a -> a
- getPort :: HasPort a => a -> Int
- getHost :: ClientSettings -> ByteString
- getAddrFamily :: ClientSettings -> Family
- getAfterBind :: HasAfterBind a => a -> Socket -> IO ()
- getNeedLocalAddr :: ServerSettings -> Bool
- getPath :: HasPath a => a -> FilePath
- appRead :: HasReadWrite a => a -> IO ByteString
- appWrite :: HasReadWrite a => a -> ByteString -> IO ()
- appSockAddr :: AppData -> SockAddr
- appLocalAddr :: AppData -> Maybe SockAddr
- bindPortGen :: SocketType -> Int -> HostPreference -> IO Socket
- bindRandomPortGen :: SocketType -> HostPreference -> IO (Int, Socket)
- getSocketGen :: SocketType -> String -> Int -> IO (Socket, AddrInfo)
- getSocketFamilyGen :: SocketType -> String -> Int -> Family -> IO (Socket, AddrInfo)
- acceptSafe :: Socket -> IO (Socket, SockAddr)
- unassignedPorts :: UArray Int Int
- getUnassignedPort :: IO Int
- bindPortTCP :: Int -> HostPreference -> IO Socket
- bindRandomPortTCP :: HostPreference -> IO (Int, Socket)
- getSocketTCP :: ByteString -> Int -> IO (Socket, SockAddr)
- getSocketFamilyTCP :: ByteString -> Int -> Family -> IO (Socket, SockAddr)
- safeRecv :: Socket -> Int -> IO ByteString
- runTCPServer :: ServerSettings -> (AppData -> IO ()) -> IO ()
- runTCPClient :: ClientSettings -> (AppData -> IO a) -> IO a
- type ConnectionHandle = Socket -> SockAddr -> Maybe SockAddr -> IO ()
- runTCPServerWithHandle :: ServerSettings -> ConnectionHandle -> IO ()
- bindPortUDP :: Int -> HostPreference -> IO Socket
- bindRandomPortUDP :: HostPreference -> IO (Int, Socket)
- getSocketUDP :: String -> Int -> IO (Socket, AddrInfo)
- bindPath :: FilePath -> IO Socket
- getSocketUnix :: FilePath -> IO Socket
- runUnixServer :: ServerSettingsUnix -> (AppDataUnix -> IO ()) -> IO ()
- runUnixClient :: ClientSettingsUnix -> (AppDataUnix -> IO a) -> IO a
Types
data ServerSettings
Settings for a TCP server. It takes a port to listen on, and an optional hostname to bind to.
Instances
data HostPreference
Which host to bind.
Note: The IsString
instance recognizes the following special values:
*
meansHostAny
*4
meansHostIPv4
!4
meansHostIPv4Only
*6
meansHostIPv6
!6
meansHostIPv6Only
data Message
Representation of a single UDP message
Constructors
Message | |
Fields
|
data ServerSettingsUnix
Settings for a Unix domain sockets server.
Smart constructors
Arguments
:: Int | port to bind to |
-> HostPreference | host binding preferences |
-> ServerSettings |
Smart constructor.
serverSettingsTCPSocket :: Socket -> ServerSettings
Create a server settings that uses an already available listening socket. Any port and host modifications made to this value will be ignored.
Since 0.1.1
Arguments
:: Int | port to connect to |
-> ByteString | host to connect to |
-> ClientSettings |
Smart constructor.
Arguments
:: Int | port to bind to |
-> HostPreference | host binding preferences |
-> ServerSettings |
Smart constructor.
Arguments
:: Int | port to connect to |
-> ByteString | host to connect to |
-> ClientSettings |
Smart constructor.
message :: ByteString -> SockAddr -> Message
Classes
class HasPort a where
Instances
class HasAfterBind a where
class HasReadWrite a where
Methods
readLens :: Functor f => (IO ByteString -> f (IO ByteString)) -> a -> f a
writeLens :: Functor f => ((ByteString -> IO ()) -> f (ByteString -> IO ())) -> a -> f a
Instances
class HasPath a where
Setters
setHost :: ByteString -> ClientSettings -> ClientSettings
setAddrFamily :: Family -> ClientSettings -> ClientSettings
Set the address family for the given settings.
Since 0.1.3
setAfterBind :: HasAfterBind a => (Socket -> IO ()) -> a -> a
setNeedLocalAddr :: Bool -> ServerSettings -> ServerSettings
Getters
getHost :: ClientSettings -> ByteString
getAddrFamily :: ClientSettings -> Family
Get the address family for the given settings.
Since 0.1.3
getAfterBind :: HasAfterBind a => a -> Socket -> IO ()
appRead :: HasReadWrite a => a -> IO ByteString
appWrite :: HasReadWrite a => a -> ByteString -> IO ()
appSockAddr :: AppData -> SockAddr
appLocalAddr :: AppData -> Maybe SockAddr
Functions
General
bindPortGen :: SocketType -> Int -> HostPreference -> IO Socket
Attempt to bind a listening Socket
on the given host/port using given
SocketType
. If no host is given, will use the first address available.
bindRandomPortGen :: SocketType -> HostPreference -> IO (Int, Socket)
Bind to a random port number. Especially useful for writing network tests.
This will attempt 30 different port numbers before giving up and throwing an exception.
Since 0.1.1
getSocketGen :: SocketType -> String -> Int -> IO (Socket, AddrInfo)
Attempt to connect to the given host/port using given SocketType
.
getSocketFamilyGen :: SocketType -> String -> Int -> Family -> IO (Socket, AddrInfo)
Attempt to connect to the given hostportaddress family using given SocketType
.
Since 0.1.3
acceptSafe :: Socket -> IO (Socket, SockAddr)
Try to accept a connection, recovering automatically from exceptions.
As reported by Kazu against Warp, "resource exhausted (Too many open files)" may be thrown by accept(). This function will catch that exception, wait a second, and then try again.
Get a port from the IANA list of unassigned ports.
Internally, this function uses an IORef
to cycle through the list of ports
TCP
bindPortTCP :: Int -> HostPreference -> IO Socket
Attempt to bind a listening Socket
on the given host/port. If no host is
given, will use the first address available.
maxListenQueue
is topically 128 which is too short for
high performance servers. So, we specify 'max 2048 maxListenQueue' to
the listen queue.
bindRandomPortTCP :: HostPreference -> IO (Int, Socket)
getSocketTCP :: ByteString -> Int -> IO (Socket, SockAddr)
Attempt to connect to the given host/port.
getSocketFamilyTCP :: ByteString -> Int -> Family -> IO (Socket, SockAddr)
Attempt to connect to the given hostportaddress family.
Since 0.1.3
safeRecv :: Socket -> Int -> IO ByteString
runTCPServer :: ServerSettings -> (AppData -> IO ()) -> IO ()
Run an Application
with the given settings. This function will create a
new listening socket, accept connections on it, and spawn a new thread for
each connection.
runTCPClient :: ClientSettings -> (AppData -> IO a) -> IO a
Run an Application
by connecting to the specified server.
runTCPServerWithHandle :: ServerSettings -> ConnectionHandle -> IO ()
UDP
bindPortUDP :: Int -> HostPreference -> IO Socket
Attempt to bind a listening Socket
on the given host/port. If no host is
given, will use the first address available.
bindRandomPortUDP :: HostPreference -> IO (Int, Socket)
Unix
getSocketUnix :: FilePath -> IO Socket
Attempt to connect to the given Unix domain socket path.
runUnixServer :: ServerSettingsUnix -> (AppDataUnix -> IO ()) -> IO ()
Run an Application
with the given settings. This function will create a
new listening socket, accept connections on it, and spawn a new thread for
each connection.
runUnixClient :: ClientSettingsUnix -> (AppDataUnix -> IO a) -> IO a
Run an Application
by connecting to the specified server.