-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | An extensible socket library. -- -- This library is a minimal and cross platform interface for BSD style -- networking. @package socket @version 0.6.0.0 module System.Socket.Unsafe -- | A generic socket type. Use socket to create a new socket. -- -- The socket is just an MVar-wrapped file descriptor. The -- Socket constructor is exported trough the unsafe module 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 f t p Socket :: (MVar Fd) -> Socket f t p unsafeSend :: Socket a t p -> Ptr a -> CSize -> MessageFlags -> IO CInt unsafeSendTo :: Socket f t p -> Ptr b -> CSize -> MessageFlags -> Ptr (SocketAddress f) -> CInt -> IO CInt unsafeReceive :: Socket a t p -> Ptr b -> CSize -> MessageFlags -> IO CInt unsafeReceiveFrom :: Socket f t p -> Ptr b -> CSize -> MessageFlags -> Ptr (SocketAddress f) -> Ptr CInt -> IO CInt unsafeGetSocketOption :: Storable a => Socket f t p -> CInt -> CInt -> IO a unsafeSetSocketOption :: Storable a => Socket f t p -> CInt -> CInt -> a -> IO () -- | Blocks until a socket should be tried for reading. -- --
--   safeSocketWaitRead = do
--     wait <- withMVar msock $ \sock-> do
--       -- Register while holding a lock on the socket descriptor.
--       unsafeSocketWaitRead sock 0 
--     -- Do the waiting without keeping the socket descriptor locked.
--     wait
--   
unsafeSocketWaitRead :: Fd -> Int -> IO (IO ()) unsafeSocketWaitWrite :: Fd -> Int -> IO (IO ()) tryWaitRetryLoop :: Socket f t p -> (Fd -> Int -> IO (IO ())) -> (Fd -> IO CInt) -> IO CInt module System.Socket.Type.Raw data Raw instance System.Socket.Internal.Socket.Type System.Socket.Type.Raw.Raw module System.Socket.Type.Datagram data Datagram instance System.Socket.Internal.Socket.Type System.Socket.Type.Datagram.Datagram module System.Socket.Type.SequentialPacket data SequentialPacket instance System.Socket.Internal.Socket.Type System.Socket.Type.SequentialPacket.SequentialPacket module System.Socket.Protocol.UDP data UDP instance System.Socket.Internal.Socket.Protocol System.Socket.Protocol.UDP.UDP module System.Socket.Protocol.TCP data TCP instance System.Socket.Internal.Socket.Protocol System.Socket.Protocol.TCP.TCP module System.Socket.Family.Inet -- | The Internet Protocol version 4. data Inet -- | To avoid errors with endianess it was decided to keep this type -- abstract. -- -- Hint: Use the Storable instance if you really need to access. -- It exposes it exactly as found within an IP packet (big endian if you -- insist on interpreting it as a number). -- -- Another hint: Use getAddressInfo for parsing and suppress -- nameserver lookups: -- --
--   > getAddressInfo (Just "127.0.0.1") Nothing aiNumericHost :: IO [AddressInfo Inet Stream TCP]
--   [AddressInfo {addressInfoFlags = AddressInfoFlags 4, socketAddress = SocketAddressInet {inetAddress = InetAddress 127.0.0.1, inetPort = InetPort 0}, canonicalName = Nothing}]
--   
data InetAddress data InetPort -- | The SocketAddress type is a data family. This allows to -- provide different data constructors depending on the socket family -- wihtout knowing all of them in advance or the need to patch this core -- library. -- --
--   SocketAddressInet  inetLoopback  8080     :: SocketAddress Inet
--   SocketAddressInet6 inet6Loopback 8080 0 0 :: SocketAddress Inet6
--   
-- |
--   224.0.0.1
--   
inetAllHostsGroup :: InetAddress -- |
--   0.0.0.0
--   
inetAny :: InetAddress -- |
--   255.255.255.255
--   
inetBroadcast :: InetAddress -- |
--   127.0.0.1
--   
inetLoopback :: InetAddress -- |
--   224.0.0.255
--   
inetMaxLocalGroup :: InetAddress -- |
--   255.255.255.255
--   
inetNone :: InetAddress -- |
--   224.0.0.0
--   
inetUnspecificGroup :: InetAddress instance GHC.Show.Show (System.Socket.Internal.Socket.SocketAddress System.Socket.Family.Inet.Inet) instance GHC.Classes.Eq (System.Socket.Internal.Socket.SocketAddress System.Socket.Family.Inet.Inet) instance GHC.Num.Num System.Socket.Family.Inet.InetPort instance GHC.Show.Show System.Socket.Family.Inet.InetPort instance GHC.Classes.Ord System.Socket.Family.Inet.InetPort instance GHC.Classes.Eq System.Socket.Family.Inet.InetPort instance GHC.Classes.Eq System.Socket.Family.Inet.InetAddress instance System.Socket.Internal.Socket.Family System.Socket.Family.Inet.Inet instance GHC.Show.Show System.Socket.Family.Inet.InetAddress instance Foreign.Storable.Storable System.Socket.Family.Inet.InetPort instance Foreign.Storable.Storable System.Socket.Family.Inet.InetAddress instance Foreign.Storable.Storable (System.Socket.Internal.Socket.SocketAddress System.Socket.Family.Inet.Inet) module System.Socket.Family.Inet6 -- | The Internet Protocol version 4. data Inet6 -- | To avoid errors with endianess it was decided to keep this type -- abstract. -- -- Hint: Use the Storable instance if you really need to access. -- It exposes it exactly as found within an IP packet (big endian if you -- insist on interpreting it as a number). -- -- Another hint: Use getAddressInfo for parsing and suppress -- nameserver lookups: -- --
--   > getAddressInfo (Just "::1") Nothing aiNumericHost :: IO [AddressInfo SocketAddressInet6 Stream TCP]
--   [AddressInfo {
--      addressInfoFlags = AddressInfoFlags 4,
--      socketAddress    = SocketAddressInet6 {inet6Address = Inet6Address 0000:0000:0000:0000:0000:0000:0000:0001, inet6Port = Inet6Port 0, inet6FlowInfo = Inet6FlowInfo 0, inet6ScopeId = Inet6ScopeId 0},
--      canonicalName    = Nothing }]
--   
data Inet6Address data Inet6Port data Inet6FlowInfo data Inet6ScopeId -- | The SocketAddress type is a data family. This allows to -- provide different data constructors depending on the socket family -- wihtout knowing all of them in advance or the need to patch this core -- library. -- --
--   SocketAddressInet  inetLoopback  8080     :: SocketAddress Inet
--   SocketAddressInet6 inet6Loopback 8080 0 0 :: SocketAddress Inet6
--   
-- |
--   ::
--   
inet6Any :: Inet6Address -- |
--   ::1
--   
inet6Loopback :: Inet6Address -- |
--   IPV6_V6ONLY
--   
data V6Only V6Only :: Bool -> V6Only instance GHC.Show.Show (System.Socket.Internal.Socket.SocketAddress System.Socket.Family.Inet6.Inet6) instance GHC.Classes.Eq (System.Socket.Internal.Socket.SocketAddress System.Socket.Family.Inet6.Inet6) instance GHC.Show.Show System.Socket.Family.Inet6.V6Only instance GHC.Classes.Ord System.Socket.Family.Inet6.V6Only instance GHC.Classes.Eq System.Socket.Family.Inet6.V6Only instance GHC.Num.Num System.Socket.Family.Inet6.Inet6ScopeId instance GHC.Show.Show System.Socket.Family.Inet6.Inet6ScopeId instance GHC.Classes.Ord System.Socket.Family.Inet6.Inet6ScopeId instance GHC.Classes.Eq System.Socket.Family.Inet6.Inet6ScopeId instance GHC.Num.Num System.Socket.Family.Inet6.Inet6FlowInfo instance GHC.Show.Show System.Socket.Family.Inet6.Inet6FlowInfo instance GHC.Classes.Ord System.Socket.Family.Inet6.Inet6FlowInfo instance GHC.Classes.Eq System.Socket.Family.Inet6.Inet6FlowInfo instance GHC.Num.Num System.Socket.Family.Inet6.Inet6Port instance GHC.Show.Show System.Socket.Family.Inet6.Inet6Port instance GHC.Classes.Ord System.Socket.Family.Inet6.Inet6Port instance GHC.Classes.Eq System.Socket.Family.Inet6.Inet6Port instance GHC.Classes.Eq System.Socket.Family.Inet6.Inet6Address instance System.Socket.Internal.Socket.Family System.Socket.Family.Inet6.Inet6 instance GHC.Show.Show System.Socket.Family.Inet6.Inet6Address instance Foreign.Storable.Storable System.Socket.Family.Inet6.Inet6Address instance Foreign.Storable.Storable System.Socket.Family.Inet6.Inet6Port instance Foreign.Storable.Storable System.Socket.Family.Inet6.Inet6FlowInfo instance Foreign.Storable.Storable System.Socket.Family.Inet6.Inet6ScopeId instance Foreign.Storable.Storable (System.Socket.Internal.Socket.SocketAddress System.Socket.Family.Inet6.Inet6) instance System.Socket.Internal.Socket.SocketOption System.Socket.Family.Inet6.V6Only -- |
--   {-# LANGUAGE OverloadedStrings #-}
--   module Main where
--   
--   import Control.Exception ( bracket, catch )
--   import Control.Monad ( forever )
--   
--   import System.Socket
--   import System.Socket.Family.Inet6
--   import System.Socket.Type.Stream
--   import System.Socket.Protocol.TCP
--   
--   main :: IO ()
--   main = bracket
--     ( socket :: IO (Socket Inet6 Stream TCP) )
--     ( \s-> do
--       close s
--       putStrLn "Listening socket closed."
--     )
--     ( \s-> do
--       setSocketOption s (ReuseAddress True)
--       setSocketOption s (V6Only False)
--       bind s (SocketAddressInet6 inet6Any 8080 0 0)
--       listen s 5
--       putStrLn "Listening socket ready..."
--       forever $ acceptAndHandle s `catch` \e-> print (e :: SocketException)
--     )
--   
--   acceptAndHandle :: Socket Inet6 Stream TCP -> IO ()
--   acceptAndHandle s = bracket
--     ( accept s )
--     ( \(p, addr)-> do
--       close p
--       putStrLn $ "Closed connection to " ++ show addr
--     )
--     ( \(p, addr)-> do
--       putStrLn $ "Accepted connection from " ++ show addr
--       sendAll p "Hello world!" msgNoSignal
--     )
--   
module System.Socket -- | A generic socket type. Use socket to create a new socket. -- -- The socket is just an MVar-wrapped file descriptor. The -- Socket constructor is exported trough the unsafe module 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: -- -- data Socket f t p -- | The SocketAddress type is a data family. This allows to -- provide different data constructors depending on the socket family -- wihtout knowing all of them in advance or the need to patch this core -- library. -- --
--   SocketAddressInet  inetLoopback  8080     :: SocketAddress Inet
--   SocketAddressInet6 inet6Loopback 8080 0 0 :: SocketAddress Inet6
--   
class Family f familyNumber :: Family f => f -> CInt class Type t typeNumber :: Type t => t -> CInt class Protocol p protocolNumber :: Protocol p => p -> CInt -- | Creates a new socket. -- -- Whereas the underlying POSIX socket operation 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 Inet Datagram UDP)
--   -- create a IPv6-TCP-streaming socket
--   sock6 <- socket :: IO (Socket Inet6 Stream TCP)
--   
-- -- -- --
--   result <- bracket (socket :: IO (Socket Inet6 Stream TCP)) close $ \sock-> do
--     somethingWith sock -- your computation here
--     return somethingelse
--   
-- -- socket :: (Family f, Type t, Protocol p) => IO (Socket f t p) -- | Connects to an remote address. -- -- connect :: (Family f, Storable (SocketAddress f)) => Socket f t p -> SocketAddress f -> IO () -- | Bind a socket to an address. -- -- bind :: (Family f, Storable (SocketAddress f)) => Socket f t p -> SocketAddress f -> IO () -- | Starts listening and queueing connection requests on a connection-mode -- socket. -- -- listen :: Socket f t p -> Int -> IO () -- | Accept a new connection. -- -- accept :: (Family f, Storable (SocketAddress f)) => Socket f t p -> IO (Socket f t p, SocketAddress f) -- | Send a message on a connected socket. -- -- send :: Socket f t p -> ByteString -> MessageFlags -> IO Int -- | Like send, but allows to specify a destination address. sendTo :: (Family f, Storable (SocketAddress f)) => Socket f t p -> ByteString -> MessageFlags -> SocketAddress f -> IO Int -- | Receive a message on a connected socket. -- -- receive :: Socket f t p -> Int -> MessageFlags -> IO ByteString -- | Like receive, but additionally yields the peer address. receiveFrom :: (Family f, Storable (SocketAddress f)) => Socket f t p -> Int -> MessageFlags -> IO (ByteString, SocketAddress f) -- | Closes a socket. -- -- close :: Socket f t p -> IO () class SocketOption o getSocketOption :: SocketOption o => Socket f t p -> IO o setSocketOption :: SocketOption o => Socket f t p -> o -> IO () -- |
--   SO_ERROR
--   
data Error Error :: SocketException -> Error -- |
--   SO_REUSEADDR
--   
data ReuseAddress ReuseAddress :: Bool -> ReuseAddress data AddressInfo f t p AddressInfo :: AddressInfoFlags -> SocketAddress f -> Maybe ByteString -> AddressInfo f t p [addressInfoFlags] :: AddressInfo f t p -> AddressInfoFlags [socketAddress] :: AddressInfo f t p -> SocketAddress f [canonicalName] :: AddressInfo f t p -> Maybe ByteString class (Family f) => HasAddressInfo f -- | Maps names to addresses (i.e. by DNS lookup). -- -- The operation throws AddressInfoExceptions. -- -- 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. -- --
--   getAddressInfo (Just "www.haskell.org") (Just "https") mempty :: IO [AddressInfo Inet Stream TCP]
--   > [AddressInfo {addressInfoFlags = AddressInfoFlags 0, socketAddress = SocketAddressInet {inetAddress = InetAddress 162.242.239.16, inetPort = InetPort 443}, canonicalName = Nothing}]
--   
-- --
--   > getAddressInfo (Just "www.haskell.org") (Just "80") aiV4Mapped :: IO [AddressInfo Inet6 Stream TCP]
--   [AddressInfo {
--      addressInfoFlags = AddressInfoFlags 8,
--      socketAddress    = SocketAddressInet6 {inet6Address = Inet6Address 2400:cb00:2048:0001:0000:0000:6ca2:cc3c, inet6Port = Inet6Port 80, inet6FlowInfo = Inet6FlowInfo 0, inet6ScopeId = Inet6ScopeId 0},
--      canonicalName    = Nothing }]
--   
-- --
--   > getAddressInfo (Just "darcs.haskell.org") Nothing aiV4Mapped :: IO [AddressInfo Inet6 Stream TCP]
--   [AddressInfo {
--      addressInfoFlags = AddressInfoFlags 8,
--      socketAddress    = SocketAddressInet6 {inet6Address = Inet6Address 0000:0000:0000:0000:0000:ffff:17fd:e1ad, inet6Port = Inet6Port 0, inet6FlowInfo = Inet6FlowInfo 0, inet6ScopeId = Inet6ScopeId 0},
--      canonicalName    = Nothing }]
--   > getAddressInfo (Just "darcs.haskell.org") Nothing mempty :: IO [AddressInfo Inet6 Stream TCP]
--   *** Exception: AddressInfoException "Name or service not known"
--   
getAddressInfo :: (HasAddressInfo f, Type t, Protocol p) => Maybe ByteString -> Maybe ByteString -> AddressInfoFlags -> IO [AddressInfo f t p] -- | A NameInfo consists of host and service name. data NameInfo NameInfo :: ByteString -> ByteString -> NameInfo [hostName] :: NameInfo -> ByteString [serviceName] :: NameInfo -> ByteString -- | Maps addresses to readable host- and service names. -- -- The operation throws AddressInfoExceptions. -- --
--   > getNameInfo (SocketAddressInet inetLoopback 80) mempty
--   NameInfo {hostName = "localhost.localdomain", serviceName = "http"}
--   
class (Family f) => HasNameInfo f getNameInfo :: HasNameInfo f => SocketAddress f -> NameInfoFlags -> IO NameInfo -- | Use the Monoid instance to combine several flags: -- --
--   mconcat [msgNoSignal, msgWaitAll]
--   
-- -- Use the Bits instance to check whether a flag is set: -- --
--   if flags .&. msgEndOfRecord /= mempty then ...
--   
data MessageFlags -- |
--   MSG_EOR
--   
msgEndOfRecord :: MessageFlags -- |
--   MSG_NOSIGNAL
--   
-- -- Suppresses the generation of PIPE signals when writing to a -- socket that is no longer connected. -- -- Although this flag is POSIX, it is not available on all platforms. Try -- --
--   msgNoSignal /= mempty
--   
-- -- in order to check whether this flag is defined on a certain platform. -- It is safe to just use this constant even if it might not have effect -- on a certain target platform. The platform independence of this flag -- is therefore fulfilled to some extent. -- -- Some more explanation on the platform specific behaviour: -- -- msgNoSignal :: MessageFlags -- |
--   MSG_OOB
--   
msgOutOfBand :: MessageFlags -- |
--   MSG_WAITALL
--   
msgWaitAll :: MessageFlags -- | Use the Monoid instance to combine several flags: -- --
--   mconcat [aiAddressConfig, aiV4Mapped]
--   
data AddressInfoFlags -- | AI_ADDRCONFIG: aiAddressConfig :: AddressInfoFlags -- | AI_ALL: Return both IPv4 (as mapped -- SocketAddressInet6) and IPv6 addresses when aiV4Mapped -- is set independent of whether IPv6 addresses exist for this name. aiAll :: AddressInfoFlags -- | AI_CANONNAME: aiCanonicalName :: AddressInfoFlags -- | AI_NUMERICHOST: aiNumericHost :: AddressInfoFlags -- | AI_NUMERICSERV: aiNumericService :: AddressInfoFlags -- | AI_PASSIVE: aiPassive :: AddressInfoFlags -- | AI_V4MAPPED: Return mapped IPv4 addresses if no IPv6 -- addresses could be found or if aiAll flag is set. aiV4Mapped :: AddressInfoFlags -- | Use the Monoid instance to combine several flags: -- --
--   mconcat [niNameRequired, niNoFullyQualifiedDomainName]
--   
data NameInfoFlags -- | NI_NAMEREQD: Throw an exception if the hostname cannot be -- determined. niNameRequired :: NameInfoFlags -- | NI_DGRAM: Service is datagram based (i.e. UDP) rather -- than stream based (i.e. TCP). niDatagram :: NameInfoFlags -- | NI_NOFQDN: Return only the hostname part of the fully -- qualified domain name for local hosts. niNoFullyQualifiedDomainName :: NameInfoFlags -- | NI_NUMERICHOST: Return the numeric form of the host address. niNumericHost :: NameInfoFlags -- | NI_NUMERICSERV: Return the numeric form of the service -- address. niNumericService :: NameInfoFlags newtype SocketException SocketException :: CInt -> SocketException eOk :: SocketException eInterrupted :: SocketException eBadFileDescriptor :: SocketException eInvalid :: SocketException ePipe :: SocketException eWouldBlock :: SocketException eAgain :: SocketException eNotSocket :: SocketException eDestinationAddressRequired :: SocketException eMessageSize :: SocketException eProtocolType :: SocketException eNoProtocolOption :: SocketException eProtocolNotSupported :: SocketException eSocketTypeNotSupported :: SocketException eOperationNotSupported :: SocketException eProtocolFamilyNotSupported :: SocketException eAddressFamilyNotSupported :: SocketException eAddressInUse :: SocketException eAddressNotAvailable :: SocketException eNetworkDown :: SocketException eNetworkUnreachable :: SocketException eNetworkReset :: SocketException eConnectionAborted :: SocketException eConnectionReset :: SocketException eNoBufferSpace :: SocketException eIsConnected :: SocketException eNotConnected :: SocketException eShutdown :: SocketException eTooManyReferences :: SocketException eTimedOut :: SocketException eConnectionRefused :: SocketException eHostDown :: SocketException eHostUnreachable :: SocketException eAlready :: SocketException eInProgress :: SocketException -- | Contains the error code that can be matched against. Use show -- to get a human readable explanation of the error. newtype AddressInfoException AddressInfoException :: CInt -> AddressInfoException -- |
--   AddressInfoException "Temporary failure in name resolution"
--   
eaiAgain :: AddressInfoException -- |
--   AddressInfoException "Bad value for ai_flags"
--   
eaiBadFlags :: AddressInfoException -- |
--   AddressInfoException "Non-recoverable failure in name resolution"
--   
eaiFail :: AddressInfoException -- |
--   AddressInfoException "ai_family not supported"
--   
eaiFamily :: AddressInfoException -- |
--   AddressInfoException "Memory allocation failure"
--   
eaiMemory :: AddressInfoException -- |
--   AddressInfoException "No such host is known"
--   
eaiNoName :: AddressInfoException -- |
--   AddressInfoException "ai_socktype not supported"
--   
eaiSocketType :: AddressInfoException -- |
--   AddressInfoException "Servname not supported for ai_socktype"
--   
eaiService :: AddressInfoException -- |
--   AddressInfoException "System error"
--   
eaiSystem :: AddressInfoException module System.Socket.Type.Stream data Stream -- | Like send, but operates on lazy ByteStrings and -- continues until all data has been sent or an exception occured. sendAll :: Socket f Stream p -> ByteString -> MessageFlags -> IO () -- | Like receive, but operates on lazy ByteStrings and -- continues until either an empty part has been received (peer closed -- the connection) or given buffer limit has been exceeded or an -- exception occured. -- -- receiveAll :: Socket f Stream p -> Int64 -> MessageFlags -> IO ByteString instance System.Socket.Internal.Socket.Type System.Socket.Type.Stream.Stream