-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A binding to the POSIX sockets interface -- @package socket @version 0.1.0.1 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 f => Address f addressFamilyNumber :: Address f => f -> 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 Show SockAddrIn instance Storable 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 Show SockAddrIn6 instance Storable SockAddrIn6 instance Address SockAddrIn6 module System.Socket.Internal.FFI newtype MsgFlags MsgFlags :: CInt -> MsgFlags c_socket :: CInt -> CInt -> CInt -> IO Fd c_close :: Fd -> IO CInt c_bind :: Fd -> Ptr a -> CInt -> IO CInt c_connect :: Fd -> Ptr a -> CSize -> IO CInt c_accept :: Fd -> Ptr a -> Ptr CInt -> IO Fd c_listen :: Fd -> CInt -> IO CInt c_send :: Fd -> Ptr a -> CSize -> MsgFlags -> IO CInt c_sendto :: Fd -> Ptr a -> CSize -> MsgFlags -> Ptr b -> CInt -> IO CInt c_recv :: Fd -> Ptr a -> CSize -> MsgFlags -> IO CInt c_recvfrom :: Fd -> Ptr a -> CSize -> MsgFlags -> Ptr b -> Ptr CInt -> IO CInt c_getsockopt :: Fd -> CInt -> CInt -> Ptr a -> Ptr Int -> IO CInt c_setnonblocking :: Fd -> IO CInt instance Monoid MsgFlags module System.Socket.Internal.Socket -- | 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 newtype SocketException SocketException :: Errno -> SocketException newtype MsgFlags MsgFlags :: CInt -> MsgFlags msgEOR :: MsgFlags msgOOB :: MsgFlags msgNOSIGNAL :: MsgFlags 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 instance Typeable SocketException instance GetSockOpt SO_ACCEPTCONN instance Show SocketException instance Exception SocketException module System.Socket.Internal.Event threadWaitWrite' :: Fd -> IO (IO ()) threadWaitRead' :: Fd -> IO (IO ()) 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 -- |
--   {-# LANGUAGE OverloadedStrings #-}
--   module Main where
--   
--   import System.Socket
--   import Data.ByteString
--   import Control.Monad
--   import Control.Concurrent
--   
--   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
--         send peer "Hello world!"
--         close peer
--   
module System.Socket -- | 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 -- | 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: -- -- data Socket d t p class Storable f => Address f addressFamilyNumber :: Address f => f -> CInt data SockAddrUn SockAddrUn :: ByteString -> SockAddrUn sunPath :: SockAddrUn -> ByteString 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 class Type t typeNumber :: Type t => t -> CInt data STREAM data DGRAM data SEQPACKET class Protocol p protocolNumber :: Protocol p => p -> CInt data UDP data TCP data SCTP data MsgFlags msgEOR :: MsgFlags msgOOB :: MsgFlags msgNOSIGNAL :: MsgFlags 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 newtype SocketException SocketException :: Errno -> SocketException