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
{ serverPort :: !Int
, serverHost :: !HostPreference
, serverSocket :: !(Maybe Socket)
, serverAfterBind :: !(Socket -> IO ())
, serverNeedLocalAddr :: !Bool
}
data ClientSettings = ClientSettings
{ clientPort :: !Int
, clientHost :: !ByteString
, clientAddrFamily :: !Family
}
data HostPreference =
HostAny
| HostIPv4
| HostIPv4Only
| HostIPv6
| HostIPv6Only
| Host String
deriving (Eq, Ord, Show, Read)
instance IsString HostPreference where
fromString s'@('*':s) =
case s of
[] -> HostAny
['4'] -> HostIPv4
['6'] -> HostIPv6
_ -> Host s'
fromString s'@('!':s) =
case s of
['4'] -> HostIPv4Only
['6'] -> HostIPv6Only
_ -> Host s'
fromString s = Host s
#if !WINDOWS
data ServerSettingsUnix = ServerSettingsUnix
{ serverPath :: !FilePath
, serverAfterBindUnix :: !(Socket -> IO ())
}
data ClientSettingsUnix = ClientSettingsUnix
{ clientPath :: !FilePath
}
data AppDataUnix = AppDataUnix
{ appReadUnix :: !(IO ByteString)
, appWriteUnix :: !(ByteString -> IO ())
}
#endif
data Message = Message { msgData :: !ByteString
, msgSender :: !SockAddr
}
data AppData = AppData
{ appRead' :: !(IO ByteString)
, appWrite' :: !(ByteString -> IO ())
, appSockAddr' :: !SockAddr
, appLocalAddr' :: !(Maybe SockAddr)
, appCloseConnection' :: !(IO ())
}