{-# LANGUAGE CPP #-}
module Data.Streaming.Network.Internal
( ServerSettings (..)
, ClientSettings (..)
, HostPreference (..)
, Message (..)
, AppData (..)
#if !WINDOWS
, ServerSettingsUnix (..)
, ClientSettingsUnix (..)
, AppDataUnix (..)
#endif
) where
import Data.String (IsString (..))
import Data.ByteString (ByteString)
import Network.Socket (Socket, SockAddr, Family)
data ServerSettings = ServerSettings
{ ServerSettings -> Int
serverPort :: !Int
, ServerSettings -> HostPreference
serverHost :: !HostPreference
, ServerSettings -> Maybe Socket
serverSocket :: !(Maybe Socket)
, ServerSettings -> Socket -> IO ()
serverAfterBind :: !(Socket -> IO ())
, ServerSettings -> Bool
serverNeedLocalAddr :: !Bool
, ServerSettings -> Int
serverReadBufferSize :: !Int
}
data ClientSettings = ClientSettings
{ ClientSettings -> Int
clientPort :: !Int
, ClientSettings -> ByteString
clientHost :: !ByteString
, ClientSettings -> Family
clientAddrFamily :: !Family
, ClientSettings -> Int
clientReadBufferSize :: !Int
}
data HostPreference =
HostAny
| HostIPv4
| HostIPv4Only
| HostIPv6
| HostIPv6Only
| Host String
deriving (HostPreference -> HostPreference -> Bool
(HostPreference -> HostPreference -> Bool)
-> (HostPreference -> HostPreference -> Bool) -> Eq HostPreference
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HostPreference -> HostPreference -> Bool
$c/= :: HostPreference -> HostPreference -> Bool
== :: HostPreference -> HostPreference -> Bool
$c== :: HostPreference -> HostPreference -> Bool
Eq, Eq HostPreference
Eq HostPreference
-> (HostPreference -> HostPreference -> Ordering)
-> (HostPreference -> HostPreference -> Bool)
-> (HostPreference -> HostPreference -> Bool)
-> (HostPreference -> HostPreference -> Bool)
-> (HostPreference -> HostPreference -> Bool)
-> (HostPreference -> HostPreference -> HostPreference)
-> (HostPreference -> HostPreference -> HostPreference)
-> Ord HostPreference
HostPreference -> HostPreference -> Bool
HostPreference -> HostPreference -> Ordering
HostPreference -> HostPreference -> HostPreference
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: HostPreference -> HostPreference -> HostPreference
$cmin :: HostPreference -> HostPreference -> HostPreference
max :: HostPreference -> HostPreference -> HostPreference
$cmax :: HostPreference -> HostPreference -> HostPreference
>= :: HostPreference -> HostPreference -> Bool
$c>= :: HostPreference -> HostPreference -> Bool
> :: HostPreference -> HostPreference -> Bool
$c> :: HostPreference -> HostPreference -> Bool
<= :: HostPreference -> HostPreference -> Bool
$c<= :: HostPreference -> HostPreference -> Bool
< :: HostPreference -> HostPreference -> Bool
$c< :: HostPreference -> HostPreference -> Bool
compare :: HostPreference -> HostPreference -> Ordering
$ccompare :: HostPreference -> HostPreference -> Ordering
$cp1Ord :: Eq HostPreference
Ord, Int -> HostPreference -> ShowS
[HostPreference] -> ShowS
HostPreference -> String
(Int -> HostPreference -> ShowS)
-> (HostPreference -> String)
-> ([HostPreference] -> ShowS)
-> Show HostPreference
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HostPreference] -> ShowS
$cshowList :: [HostPreference] -> ShowS
show :: HostPreference -> String
$cshow :: HostPreference -> String
showsPrec :: Int -> HostPreference -> ShowS
$cshowsPrec :: Int -> HostPreference -> ShowS
Show, ReadPrec [HostPreference]
ReadPrec HostPreference
Int -> ReadS HostPreference
ReadS [HostPreference]
(Int -> ReadS HostPreference)
-> ReadS [HostPreference]
-> ReadPrec HostPreference
-> ReadPrec [HostPreference]
-> Read HostPreference
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HostPreference]
$creadListPrec :: ReadPrec [HostPreference]
readPrec :: ReadPrec HostPreference
$creadPrec :: ReadPrec HostPreference
readList :: ReadS [HostPreference]
$creadList :: ReadS [HostPreference]
readsPrec :: Int -> ReadS HostPreference
$creadsPrec :: Int -> ReadS HostPreference
Read)
instance IsString HostPreference where
fromString :: String -> HostPreference
fromString String
"*" = HostPreference
HostAny
fromString String
"*4" = HostPreference
HostIPv4
fromString String
"!4" = HostPreference
HostIPv4Only
fromString String
"*6" = HostPreference
HostIPv6
fromString String
"!6" = HostPreference
HostIPv6Only
fromString String
s = String -> HostPreference
Host String
s
#if !WINDOWS
data ServerSettingsUnix = ServerSettingsUnix
{ ServerSettingsUnix -> String
serverPath :: !FilePath
, ServerSettingsUnix -> Socket -> IO ()
serverAfterBindUnix :: !(Socket -> IO ())
, ServerSettingsUnix -> Int
serverReadBufferSizeUnix :: !Int
}
data ClientSettingsUnix = ClientSettingsUnix
{ ClientSettingsUnix -> String
clientPath :: !FilePath
, ClientSettingsUnix -> Int
clientReadBufferSizeUnix :: !Int
}
data AppDataUnix = AppDataUnix
{ AppDataUnix -> IO ByteString
appReadUnix :: !(IO ByteString)
, AppDataUnix -> ByteString -> IO ()
appWriteUnix :: !(ByteString -> IO ())
}
#endif
data Message = Message { Message -> ByteString
msgData :: {-# UNPACK #-} !ByteString
, Message -> SockAddr
msgSender :: !SockAddr
}
data AppData = AppData
{ AppData -> IO ByteString
appRead' :: !(IO ByteString)
, AppData -> ByteString -> IO ()
appWrite' :: !(ByteString -> IO ())
, AppData -> SockAddr
appSockAddr' :: !SockAddr
, AppData -> Maybe SockAddr
appLocalAddr' :: !(Maybe SockAddr)
, AppData -> IO ()
appCloseConnection' :: !(IO ())
, AppData -> Maybe Socket
appRawSocket' :: Maybe Socket
}