-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A binding to the POSIX sockets interface -- @package socket @version 0.2.0.0 module System.Socket.Protocol class Protocol p protocolNumber :: Protocol p => p -> CInt instance Protocol () module System.Socket.Protocol.UDP data UDP instance Protocol UDP module System.Socket.Protocol.TCP data TCP instance Protocol TCP module System.Socket.Protocol.SCTP data SCTP instance Protocol SCTP module System.Socket.Type class Type t typeNumber :: Type t => t -> CInt module System.Socket.Type.STREAM data STREAM instance Type STREAM module System.Socket.Type.DGRAM data DGRAM instance Type DGRAM module System.Socket.Type.SEQPACKET data SEQPACKET instance Type SEQPACKET module System.Socket.Address class Storable a => Address a addressFamilyNumber :: Address a => a -> CInt module System.Socket.Address.SockAddrUn data SockAddrUn SockAddrUn :: ByteString -> SockAddrUn sunPath :: SockAddrUn -> ByteString instance Eq SockAddrUn instance Ord SockAddrUn instance Show SockAddrUn instance Storable SockAddrUn instance Address SockAddrUn module System.Socket.Address.SockAddrIn data SockAddrIn SockAddrIn :: Word16 -> ByteString -> SockAddrIn sinPort :: SockAddrIn -> Word16 sinAddr :: SockAddrIn -> ByteString instance Eq SockAddrIn instance Ord SockAddrIn instance Storable SockAddrIn instance Show SockAddrIn instance Address SockAddrIn module System.Socket.Address.SockAddrIn6 data SockAddrIn6 SockAddrIn6 :: Word16 -> Word32 -> ByteString -> Word32 -> SockAddrIn6 sin6Port :: SockAddrIn6 -> Word16 sin6Flowinfo :: SockAddrIn6 -> Word32 sin6Addr :: SockAddrIn6 -> ByteString sin6ScopeId :: SockAddrIn6 -> Word32 instance Eq SockAddrIn6 instance Ord SockAddrIn6 instance Storable SockAddrIn6 instance Show SockAddrIn6 instance Address SockAddrIn6 module System.Socket.Unsafe unsafeSend :: (Address a, Type t, Protocol p) => Socket a t p -> Ptr b -> CSize -> MsgFlags -> IO CInt unsafeSendTo :: (Address a, Type t, Protocol p) => Socket a t p -> Ptr b -> CSize -> MsgFlags -> Ptr a -> CInt -> IO CInt unsafeRecv :: (Address a, Type t, Protocol p) => Socket a t p -> Ptr b -> CSize -> MsgFlags -> IO CInt unsafeRecvFrom :: (Address a, Type t, Protocol p) => Socket a t p -> Ptr b -> CSize -> MsgFlags -> Ptr a -> Ptr CInt -> IO CInt -- | This starts a TCP server on localhost, sends "Hello world!" -- to connecting peers and closes the connection immediately. -- --
--   {-# LANGUAGE OverloadedStrings #-}
--   module Main where
--   
--   import System.Socket
--   import Data.ByteString
--   import Control.Monad
--   import Control.Concurrent
--   import Control.Exception
--   
--   main :: IO ()
--   main = do
--     s <- socket :: IO (Socket SockAddrIn STREAM TCP)
--     bind s (SockAddrIn 8080 (pack [127,0,0,1]))
--     listen s 5
--     forever $ do
--       (peer,addr) <- accept s
--       forkIO $ do
--         sendAll peer "Hello world!" mempty `finally` close peer
--   
-- -- This downloads the [Haskell website](http://www.haskell.org) and shows -- how to handle exceptions. Note the use of IPv4-mapped IPv6 addresses: -- This will work even if you don't have IPv6 connectivity yet and is the -- preferred method when new applications. -- --
--   {-# LANGUAGE OverloadedStrings #-}
--   module Main where
--   
--   import Control.Monad
--   import Control.Exception
--   
--   import Data.Function (fix)
--   import qualified Data.ByteString as BS
--   
--   import System.IO
--   import System.Exit
--   import System.Socket
--   
--   main :: IO ()
--   main = fetch
--     `catch` (\e-> do
--       hPutStr   stderr "Something failed when resolving the name: "
--       hPutStrLn stderr $ show (e :: AddrInfoException)
--       exitFailure
--     )
--     `catch` (\e-> do
--       hPutStr   stderr "Something went wrong with the socket: "
--       hPutStrLn stderr $ show (e :: SocketException)
--       exitFailure
--     )
--   
--   fetch :: IO ()
--   fetch = do
--     addrs <- getAddrInfo (Just "www.haskell.org") (Just "80") aiV4MAPPED :: IO [AddrInfo SockAddrIn6 STREAM TCP]
--     case addrs of
--       (addr:_) ->
--         -- always use the `bracket` pattern to reliably release resources!
--         bracket
--           ( socket :: IO (Socket SockAddrIn6 STREAM TCP) )
--           ( close )
--           ( \s-> do connect s (addrAddress addr)
--                     sendAll s "GET / HTTP/1.0\r\nHost: www.haskell.org\r\n\r\n" mempty
--                     fix $ \recvMore-> do
--                       bs <- recv s 4096 mempty
--                       BS.putStr bs
--                       if BS.length bs == 0 -- an empty string means the peer terminated the connection
--                         then exitSuccess
--                         else recvMore
--            )
--       _ -> error "Illegal state: getAddrInfo yields non-empty list or exception."
--   
module System.Socket data AddrInfo a t p AddrInfo :: AddrInfoFlags -> a -> Maybe ByteString -> AddrInfo a t p addrInfoFlags :: AddrInfo a t p -> AddrInfoFlags addrAddress :: AddrInfo a t p -> a addrCanonName :: AddrInfo a t p -> Maybe ByteString -- | Maps names to addresses (i.e. by DNS lookup). -- -- The operation throws AddrInfoExceptions. -- -- Contrary to the underlying getaddrinfo operation this wrapper -- is typesafe and thus only returns records that match the address, type -- and protocol encoded in the type. This is the price we have to pay for -- typesafe sockets and extensibility. -- -- If you need different types of records, you need to start several -- queries. If you want to connect to both IPv4 and IPV6 addresses use -- aiV4MAPPED and use IPv6-sockets. -- --
--   > getAddrInfo (Just "www.haskell.org") (Just "80") aiV4MAPPED :: IO [AddrInfo SockAddrIn6 STREAM TCP]
--   [AddrInfo {addrInfoFlags = AddrInfoFlags 8, addrAddress = "[2400:cb00:2048:0001:0000:0000:6ca2:cc3c]:80", addrCanonName = Nothing}]
--   > getAddrInfo (Just "darcs.haskell.org") Nothing aiV4MAPPED :: IO [AddrInfo SockAddrIn6 STREAM TCP]
--   [AddrInfo {addrInfoFlags = AddrInfoFlags 8, addrAddress = "[0000:0000:0000:0000:0000:ffff:17fd:e1ad]:0", addrCanonName = Nothing}]
--   > getAddrInfo (Just "darcs.haskell.org") Nothing mempty :: IO [AddrInfo SockAddrIn6 STREAM TCP]
--   *** Exception: AddrInfoException (-2) "Name or service not known"
--   
getAddrInfo :: (Address a, Type t, Protocol p) => Maybe ByteString -> Maybe ByteString -> AddrInfoFlags -> IO [AddrInfo a t p] -- | Maps addresss to readable host- and service names. -- -- The operation throws AddrInfoExceptions. -- --
--   > getNameInfo (SockAddrIn 80 $ pack [23,253,242,70]) mempty
--   ("haskell.org","http")
--   
getNameInfo :: Address a => a -> NameInfoFlags -> IO (ByteString, ByteString) -- | Creates a new socket. -- -- Whereas the underlying POSIX socket function takes 3 parameters, this -- library encodes this information in the type variables. This rules out -- several kinds of errors and escpecially simplifies the handling of -- addresses (by using associated type families). Examples: -- --
--   -- create a IPv4-UDP-datagram socket
--   sock <- socket :: IO (Socket SockAddrIn DGRAM UDP)
--   -- create a IPv6-TCP-streaming socket
--   sock6 <- socket :: IO (Socket SockAddrIn6 STREAM TCP)
--   
-- -- socket :: (Address a, Type t, Protocol p) => IO (Socket a t p) -- | Bind a socket to an address. -- -- bind :: (Address a, Type t, Protocol p) => Socket a t p -> a -> IO () -- | Accept connections on a connection-mode socket. -- -- listen :: (Address a, Type t, Protocol p) => Socket a t p -> Int -> IO () -- | Accept a new connection. -- -- accept :: (Address a, Type t, Protocol p) => Socket a t p -> IO (Socket a t p, a) -- | Connects to an remote address. -- -- connect :: (Address a, Type t, Protocol p) => Socket a t p -> a -> IO () -- | Send a message on a connected socket. -- -- send :: (Address a, Type t, Protocol p) => Socket a t p -> ByteString -> MsgFlags -> IO Int -- | Like send, but continues until all data has been sent. -- --
--   sendAll sock data flags = do
--     sent <- send sock data flags
--     when (sent < length data) $ sendAll sock (drop sent data) flags
--   
sendAll :: (Address a, Type t, Protocol p) => Socket a t p -> ByteString -> MsgFlags -> IO () -- | Send a message on a socket with a specific destination address. -- -- sendTo :: (Address a, Type t, Protocol p) => Socket a t p -> ByteString -> MsgFlags -> a -> IO Int -- | Receive a message on a connected socket. -- -- recv :: (Address a, Type t, Protocol p) => Socket a t p -> Int -> MsgFlags -> IO ByteString -- | Receive a message on a socket and additionally yield the peer address. -- -- recvFrom :: (Address a, Type t, Protocol p) => Socket a t p -> Int -> MsgFlags -> IO (ByteString, a) -- | Closes a socket. -- -- close :: (Address a, Type t, Protocol p) => Socket a t p -> IO () -- | A generic socket type. Also see socket for details. -- -- The socket is just an MVar-wrapped file descriptor. It is -- exposed in order to make this library easily extensible, but it is -- usually not necessary nor advised to work directly on the file -- descriptor. If you do, the following rules must be obeyed: -- -- newtype Socket d t p Socket :: (MVar Fd) -> Socket d t p class Storable a => Address a addressFamilyNumber :: Address a => a -> CInt data SockAddrIn SockAddrIn :: Word16 -> ByteString -> SockAddrIn sinPort :: SockAddrIn -> Word16 sinAddr :: SockAddrIn -> ByteString data SockAddrIn6 SockAddrIn6 :: Word16 -> Word32 -> ByteString -> Word32 -> SockAddrIn6 sin6Port :: SockAddrIn6 -> Word16 sin6Flowinfo :: SockAddrIn6 -> Word32 sin6Addr :: SockAddrIn6 -> ByteString sin6ScopeId :: SockAddrIn6 -> Word32 data SockAddrUn SockAddrUn :: ByteString -> SockAddrUn sunPath :: SockAddrUn -> ByteString class Type t typeNumber :: Type t => t -> CInt data DGRAM data STREAM data SEQPACKET class Protocol p protocolNumber :: Protocol p => p -> CInt data UDP data TCP data SCTP newtype SocketException SocketException :: Errno -> SocketException -- | Contains the error code that can be matched against and a readable -- description taken from eia_strerr. data AddrInfoException AddrInfoException :: CInt -> String -> AddrInfoException class GetSockOpt o getSockOpt :: GetSockOpt o => Socket f t p -> IO o class SetSockOpt o setSockOpt :: SetSockOpt o => Socket f t p -> o -> IO () data SO_ACCEPTCONN SO_ACCEPTCONN :: Bool -> SO_ACCEPTCONN -- | Use the Monoid instance to combine several flags: -- --
--   mconcat [msgNOSIGNAL, msgWAITALL]
--   
newtype MsgFlags MsgFlags :: CInt -> MsgFlags msgEOR :: MsgFlags msgNOSIGNAL :: MsgFlags msgOOB :: MsgFlags msgWAITALL :: MsgFlags -- | Use the Monoid instance to combine several flags: -- --
--   mconcat [aiADDRCONFIG, aiV4MAPPED]
--   
newtype AddrInfoFlags AddrInfoFlags :: CInt -> AddrInfoFlags aiADDRCONFIG :: AddrInfoFlags aiALL :: AddrInfoFlags aiCANONNAME :: AddrInfoFlags aiNUMERICHOST :: AddrInfoFlags aiNUMERICSERV :: AddrInfoFlags aiPASSIVE :: AddrInfoFlags aiV4MAPPED :: AddrInfoFlags -- | Use the Monoid instance to combine several flags: -- --
--   mconcat [niNAMEREQD, niNOFQDN]
--   
newtype NameInfoFlags NameInfoFlags :: CInt -> NameInfoFlags -- | Throw an exception if the hostname cannot be determined. niNAMEREQD :: NameInfoFlags -- | Service is datagram based (UDP) rather than stream based (TCP). niDGRAM :: NameInfoFlags -- | Return only the hostname part of the fully qualified domain name for -- local hosts. niNOFQDN :: NameInfoFlags -- | Return the numeric form of the host address. niNUMERICHOST :: NameInfoFlags -- | Return the numeric form of the service address. niNUMERICSERV :: NameInfoFlags