Safe Haskell | None |
---|
- 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
- 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
- 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
- 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
- getSocketGen :: SocketType -> String -> Int -> IO (Socket, AddrInfo)
- acceptSafe :: Socket -> IO (Socket, SockAddr)
- bindPortTCP :: Int -> HostPreference -> IO Socket
- getSocketTCP :: ByteString -> Int -> 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
- 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 Source
Settings for a TCP server. It takes a port to listen on, and an optional hostname to bind to.
data ClientSettings Source
Settings for a TCP client, specifying how to connect to the server.
data HostPreference Source
Which host to bind.
Note: The IsString
instance recognizes the following special values:
-
*
meansHostAny
-
*4
meansHostIPv4
-
!4
meansHostIPv4Only
-
*6
meansHostIPv6
-
!6
meansHostIPv6Only
Representation of a single UDP message
Message | |
|
data ServerSettingsUnix Source
Settings for a Unix domain sockets server.
data AppDataUnix Source
The data passed to a Unix domain sockets Application
.
Smart constructors
:: Int | port to bind to |
-> HostPreference | host binding preferences |
-> ServerSettings |
Smart constructor.
:: Int | port to connect to |
-> ByteString | host to connect to |
-> ClientSettings |
Smart constructor.
:: Int | port to bind to |
-> HostPreference | host binding preferences |
-> ServerSettings |
Smart constructor.
:: Int | port to connect to |
-> ByteString | host to connect to |
-> ClientSettings |
Smart constructor.
message :: ByteString -> SockAddr -> MessageSource
Classes
class HasAfterBind a whereSource
class HasReadWrite a whereSource
readLens :: Functor f => (IO ByteString -> f (IO ByteString)) -> a -> f aSource
writeLens :: Functor f => ((ByteString -> IO ()) -> f (ByteString -> IO ())) -> a -> f aSource
Setters
setAfterBind :: HasAfterBind a => (Socket -> IO ()) -> a -> aSource
Getters
getAfterBind :: HasAfterBind a => a -> Socket -> IO ()Source
appRead :: HasReadWrite a => a -> IO ByteStringSource
appWrite :: HasReadWrite a => a -> ByteString -> IO ()Source
appSockAddr :: AppData -> SockAddrSource
Functions
General
bindPortGen :: SocketType -> Int -> HostPreference -> IO SocketSource
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.
getSocketGen :: SocketType -> String -> Int -> IO (Socket, AddrInfo)Source
Attempt to connect to the given host/port using given SocketType
.
acceptSafe :: Socket -> IO (Socket, SockAddr)Source
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.
TCP
bindPortTCP :: Int -> HostPreference -> IO SocketSource
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.
getSocketTCP :: ByteString -> Int -> IO (Socket, SockAddr)Source
Attempt to connect to the given host/port.
runTCPServer :: ServerSettings -> (AppData -> IO ()) -> IO ()Source
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 aSource
Run an Application
by connecting to the specified server.
runTCPServerWithHandle :: ServerSettings -> ConnectionHandle -> IO ()Source
UDP
bindPortUDP :: Int -> HostPreference -> IO SocketSource
Attempt to bind a listening Socket
on the given host/port. If no host is
given, will use the first address available.
getSocketUDP :: String -> Int -> IO (Socket, AddrInfo)Source
Attempt to connect to the given host/port.
Unix
bindPath :: FilePath -> IO SocketSource
Attempt to bind a listening Unix domain socket at the given path.
getSocketUnix :: FilePath -> IO SocketSource
Attempt to connect to the given Unix domain socket path.
runUnixServer :: ServerSettingsUnix -> (AppDataUnix -> IO ()) -> IO ()Source
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 aSource
Run an Application
by connecting to the specified server.