-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Low-level networking interface -- @package network @version 2.6.2.0 -- | A module containing semi-public Socket internals. Modules which -- extend the Socket module will need to use this module while -- ideally most users will be able to make do with the public interface. module Network.Socket.Internal -- | Network byte order. type HostAddress = Word32 -- | Host byte order. type HostAddress6 = (Word32, Word32, Word32, Word32) type FlowInfo = Word32 type ScopeID = Word32 -- | Use the Num instance (i.e. use a literal) to create a -- PortNumber value with the correct network-byte-ordering. You -- should not use the PortNum constructor. It will be removed in the next -- release. newtype PortNumber -- | Deprecated: Do not use the PortNum constructor. Use the Num -- instance. PortNum will be removed in the next release. PortNum :: Word16 -> PortNumber -- | The existence of a constructor does not necessarily imply that that -- socket address type is supported on your system: see -- isSupportedSockAddr. data SockAddr SockAddrInet :: PortNumber -> HostAddress -> SockAddr SockAddrInet6 :: PortNumber -> FlowInfo -> HostAddress6 -> ScopeID -> SockAddr SockAddrUnix :: String -> SockAddr SockAddrCan :: Int32 -> SockAddr -- | Read a SockAddr from the given memory location. peekSockAddr :: Ptr SockAddr -> IO SockAddr -- | Write the given SockAddr to the given memory location. pokeSockAddr :: Ptr a -> SockAddr -> IO () -- | Computes the storage requirements (in bytes) of the given -- SockAddr. This function differs from sizeOf in that the -- value of the argument is used. sizeOfSockAddr :: SockAddr -> Int -- | Computes the storage requirements (in bytes) required for a -- SockAddr with the given Family. sizeOfSockAddrByFamily :: Family -> Int -- | Use a SockAddr with a function requiring a pointer to a -- SockAddr and the length of that SockAddr. withSockAddr :: SockAddr -> (Ptr SockAddr -> Int -> IO a) -> IO a -- | Create a new SockAddr for use with a function requiring a -- pointer to a SockAddr and the length of that SockAddr. withNewSockAddr :: Family -> (Ptr SockAddr -> Int -> IO a) -> IO a -- | Address families. -- -- A constructor being present here does not mean it is supported by the -- operating system: see isSupportedFamily. data Family AF_UNSPEC :: Family AF_UNIX :: Family AF_INET :: Family AF_INET6 :: Family AF_IMPLINK :: Family AF_PUP :: Family AF_CHAOS :: Family AF_NS :: Family AF_NBS :: Family AF_ECMA :: Family AF_DATAKIT :: Family AF_CCITT :: Family AF_SNA :: Family AF_DECnet :: Family AF_DLI :: Family AF_LAT :: Family AF_HYLINK :: Family AF_APPLETALK :: Family AF_ROUTE :: Family AF_NETBIOS :: Family AF_NIT :: Family AF_802 :: Family AF_ISO :: Family AF_OSI :: Family AF_NETMAN :: Family AF_X25 :: Family AF_AX25 :: Family AF_OSINET :: Family AF_GOSSIP :: Family AF_IPX :: Family Pseudo_AF_XTP :: Family AF_CTF :: Family AF_WAN :: Family AF_SDL :: Family AF_NETWARE :: Family AF_NDD :: Family AF_INTF :: Family AF_COIP :: Family AF_CNT :: Family Pseudo_AF_RTIP :: Family Pseudo_AF_PIP :: Family AF_SIP :: Family AF_ISDN :: Family Pseudo_AF_KEY :: Family AF_NATM :: Family AF_ARP :: Family Pseudo_AF_HDRCMPLT :: Family AF_ENCAP :: Family AF_LINK :: Family AF_RAW :: Family AF_RIF :: Family AF_NETROM :: Family AF_BRIDGE :: Family AF_ATMPVC :: Family AF_ROSE :: Family AF_NETBEUI :: Family AF_SECURITY :: Family AF_PACKET :: Family AF_ASH :: Family AF_ECONET :: Family AF_ATMSVC :: Family AF_IRDA :: Family AF_PPPOX :: Family AF_WANPIPE :: Family AF_BLUETOOTH :: Family AF_CAN :: Family -- | Throw an IOError corresponding to the current socket error. throwSocketError :: String -> IO a -- | Like throwSocketError, but the error code is supplied as an -- argument. -- -- On Windows, do not use errno. Use a system error code instead. throwSocketErrorCode :: String -> CInt -> IO a -- | Throw an IOError corresponding to the current socket error if -- the IO action returns a result of -1. Discards the result of -- the IO action after error handling. throwSocketErrorIfMinus1_ :: (Eq a, Num a) => String -> IO a -> IO () -- | Throw an IOError corresponding to the current socket error if -- the IO action returns a result of -1, but retries in case of -- an interrupted operation. throwSocketErrorIfMinus1Retry :: (Eq a, Num a) => String -> IO a -> IO a -- | Throw an IOError corresponding to the current socket error if -- the IO action returns a result of -1, but retries in case of -- an interrupted operation. Discards the result of the IO action after -- error handling. throwSocketErrorIfMinus1Retry_ :: (Eq a, Num a) => String -> IO a -> IO () -- | Throw an IOError corresponding to the current socket error if -- the IO action returns a result of -1, but retries in case of -- an interrupted operation. Checks for operations that would block and -- executes an alternative action before retrying in that case. throwSocketErrorIfMinus1RetryMayBlock :: (Eq a, Num a) => String -> IO b -> IO a -> IO a -- | Like throwSocketErrorIfMinus1Retry, but if the action fails -- with EWOULDBLOCK or similar, wait for the socket to be -- read-ready, and try again. throwSocketErrorWaitRead :: (Eq a, Num a) => Socket -> String -> IO a -> IO a -- | Like throwSocketErrorIfMinus1Retry, but if the action fails -- with EWOULDBLOCK or similar, wait for the socket to be -- write-ready, and try again. throwSocketErrorWaitWrite :: (Eq a, Num a) => Socket -> String -> IO a -> IO a -- | With older versions of the network library on Windows -- operating systems, the networking subsystem must be initialised using -- withSocketsDo before any networking operations can be used. eg. -- --
-- main = withSocketsDo $ do {...}
--
--
-- It is fine to nest calls to withSocketsDo, and to perform
-- networking operations after withSocketsDo has returned.
--
-- In newer versions of the network library it is only necessary
-- to call withSocketsDo if you are calling the MkSocket
-- constructor directly. However, for compatibility with older versions
-- on Windows, it is good practice to always call withSocketsDo
-- (it's very cheap).
withSocketsDo :: IO a -> IO a
-- | Zero a structure.
zeroMemory :: Ptr a -> CSize -> IO ()
-- | The Network.Socket module is for when you want full control
-- over sockets. Essentially the entire C socket API is exposed through
-- this module; in general the operations follow the behaviour of the C
-- functions of the same name (consult your favourite Unix networking
-- book).
--
-- A higher level interface to networking operations is provided through
-- the module Network.
module Network.Socket
-- | Represents a socket. The fields are, respectively:
--
--
-- myHints = defaultHints { addrFlags = [AI_ADDRCONFIG, AI_CANONNAME] }
--
--
-- Values for addrFlags control query behaviour. The supported
-- flags are as follows:
--
--
-- main = withSocketsDo $ do {...}
--
--
-- It is fine to nest calls to withSocketsDo, and to perform
-- networking operations after withSocketsDo has returned.
--
-- In newer versions of the network library it is only necessary
-- to call withSocketsDo if you are calling the MkSocket
-- constructor directly. However, for compatibility with older versions
-- on Windows, it is good practice to always call withSocketsDo
-- (it's very cheap).
withSocketsDo :: IO a -> IO a
fdSocket :: Socket -> CInt
mkSocket :: CInt -> Family -> SocketType -> ProtocolNumber -> SocketStatus -> IO Socket
-- | Deprecated alias for bind.
bindSocket :: Socket -> SockAddr -> IO ()
-- | Deprecated alias for close.
sClose :: Socket -> IO ()
-- | Deprecated alias for isConnected.
sIsConnected :: Socket -> IO Bool
-- | Deprecated alias for isBound.
sIsBound :: Socket -> IO Bool
-- | Deprecated alias for isListening.
sIsListening :: Socket -> IO Bool
-- | Deprecated alias for isReadable.
sIsReadable :: Socket -> IO Bool
-- | Deprecated alias for isWritable.
sIsWritable :: Socket -> IO Bool
packFamily :: Family -> CInt
unpackFamily :: CInt -> Family
packSocketType :: SocketType -> CInt
instance Typeable SocketOption
instance Typeable ShutdownCmd
instance Typeable AddrInfoFlag
instance Typeable AddrInfo
instance Typeable NameInfoFlag
instance Show SocketOption
instance Eq AddrInfoFlag
instance Read AddrInfoFlag
instance Show AddrInfoFlag
instance Eq AddrInfo
instance Show AddrInfo
instance Eq NameInfoFlag
instance Read NameInfoFlag
instance Show NameInfoFlag
instance Storable AddrInfo
instance Show SockAddr
-- | This module provides access to the BSD socket interface. This
-- module is generally more efficient than the String based
-- network functions in Socket. For detailed documentation,
-- consult your favorite POSIX socket reference. All functions
-- communicate failures by converting the error number to IOError.
--
-- This module is made to be imported with Socket like so:
--
-- -- import Network.Socket hiding (send, sendTo, recv, recvFrom) -- import Network.Socket.ByteString --module Network.Socket.ByteString -- | Send data to the socket. The socket must be connected to a remote -- socket. Returns the number of bytes sent. Applications are responsible -- for ensuring that all data has been sent. send :: Socket -> ByteString -> IO Int -- | Send data to the socket. The socket must be connected to a remote -- socket. Unlike send, this function continues to send data until -- either all data has been sent or an error occurs. On error, an -- exception is raised, and there is no way to determine how much data, -- if any, was successfully sent. sendAll :: Socket -> ByteString -> IO () -- | Send data to the socket. The recipient can be specified explicitly, so -- the socket need not be in a connected state. Returns the number of -- bytes sent. Applications are responsible for ensuring that all data -- has been sent. sendTo :: Socket -> ByteString -> SockAddr -> IO Int -- | Send data to the socket. The recipient can be specified explicitly, so -- the socket need not be in a connected state. Unlike sendTo, -- this function continues to send data until either all data has been -- sent or an error occurs. On error, an exception is raised, and there -- is no way to determine how much data, if any, was successfully sent. sendAllTo :: Socket -> ByteString -> SockAddr -> IO () -- | Send data to the socket. The socket must be in a connected state. The -- data is sent as if the parts have been concatenated. This function -- continues to send data until either all data has been sent or an error -- occurs. On error, an exception is raised, and there is no way to -- determine how much data, if any, was successfully sent. sendMany :: Socket -> [ByteString] -> IO () -- | Send data to the socket. The recipient can be specified explicitly, so -- the socket need not be in a connected state. The data is sent as if -- the parts have been concatenated. This function continues to send data -- until either all data has been sent or an error occurs. On error, an -- exception is raised, and there is no way to determine how much data, -- if any, was successfully sent. sendManyTo :: Socket -> [ByteString] -> SockAddr -> IO () -- | Receive data from the socket. The socket must be in a connected state. -- This function may return fewer bytes than specified. If the message is -- longer than the specified length, it may be discarded depending on the -- type of socket. This function may block until a message arrives. -- -- Considering hardware and network realities, the maximum number of -- bytes to receive should be a small power of 2, e.g., 4096. -- -- For TCP sockets, a zero length return value means the peer has closed -- its half side of the connection. recv :: Socket -> Int -> IO ByteString -- | Receive data from the socket. The socket need not be in a connected -- state. Returns (bytes, address) where bytes is a -- ByteString representing the data received and address -- is a SockAddr representing the address of the sending socket. recvFrom :: Socket -> Int -> IO (ByteString, SockAddr) -- | This module provides access to the BSD socket interface. This -- module is generally more efficient than the String based -- network functions in Socket. For detailed documentation, -- consult your favorite POSIX socket reference. All functions -- communicate failures by converting the error number to IOError. -- -- This module is made to be imported with Socket like so: -- --
-- import Network.Socket hiding (send, sendTo, recv, recvFrom) -- import Network.Socket.ByteString.Lazy -- import Prelude hiding (getContents) --module Network.Socket.ByteString.Lazy send :: Socket -> ByteString -> IO Int64 sendAll :: Socket -> ByteString -> IO () -- | Receive data from the socket. The socket must be in a connected state. -- Data is received on demand, in chunks; each chunk will be sized to -- reflect the amount of data received by individual recv calls. -- -- All remaining data from the socket is consumed. When there is no more -- data to be received, the receiving side of the socket is shut down. If -- there is an error and an exception is thrown, the socket is not shut -- down. getContents :: Socket -> IO ByteString -- | Receive data from the socket. The socket must be in a connected state. -- This function may return fewer bytes than specified. If the received -- data is longer than the specified length, it may be discarded -- depending on the type of socket. This function may block until a -- message arrives. -- -- If there is no more data to be received, returns an empty -- ByteString. recv :: Socket -> Int64 -> IO ByteString -- | The Network.BSD module defines Haskell bindings to network -- programming functionality provided by BSD Unix derivatives. module Network.BSD -- | Either a host name e.g., "haskell.org" or a numeric host -- address string consisting of a dotted decimal IPv4 address or an IPv6 -- address e.g., "192.168.0.1". type HostName = String -- | Calling getHostName returns the standard host name for the current -- processor, as set at boot time. getHostName :: IO HostName data HostEntry HostEntry :: HostName -> [HostName] -> Family -> [HostAddress] -> HostEntry hostName :: HostEntry -> HostName hostAliases :: HostEntry -> [HostName] hostFamily :: HostEntry -> Family hostAddresses :: HostEntry -> [HostAddress] -- | Resolve a HostName to IPv4 address. getHostByName :: HostName -> IO HostEntry -- | Get a HostEntry corresponding to the given address and family. -- Note that only IPv4 is currently supported. getHostByAddr :: Family -> HostAddress -> IO HostEntry hostAddress :: HostEntry -> HostAddress getHostEntries :: Bool -> IO [HostEntry] setHostEntry :: Bool -> IO () getHostEntry :: IO HostEntry endHostEntry :: IO () data ServiceEntry ServiceEntry :: ServiceName -> [ServiceName] -> PortNumber -> ProtocolName -> ServiceEntry serviceName :: ServiceEntry -> ServiceName serviceAliases :: ServiceEntry -> [ServiceName] servicePort :: ServiceEntry -> PortNumber serviceProtocol :: ServiceEntry -> ProtocolName type ServiceName = String -- | Get service by name. getServiceByName :: ServiceName -> ProtocolName -> IO ServiceEntry -- | Get the service given a PortNumber and ProtocolName. getServiceByPort :: PortNumber -> ProtocolName -> IO ServiceEntry -- | Get the PortNumber corresponding to the ServiceName. getServicePortNumber :: ServiceName -> IO PortNumber getServiceEntries :: Bool -> IO [ServiceEntry] getServiceEntry :: IO ServiceEntry setServiceEntry :: Bool -> IO () endServiceEntry :: IO () type ProtocolName = String type ProtocolNumber = CInt data ProtocolEntry ProtocolEntry :: ProtocolName -> [ProtocolName] -> ProtocolNumber -> ProtocolEntry protoName :: ProtocolEntry -> ProtocolName protoAliases :: ProtocolEntry -> [ProtocolName] protoNumber :: ProtocolEntry -> ProtocolNumber getProtocolByName :: ProtocolName -> IO ProtocolEntry getProtocolByNumber :: ProtocolNumber -> IO ProtocolEntry getProtocolNumber :: ProtocolName -> IO ProtocolNumber -- | This is the default protocol for a given service. defaultProtocol :: ProtocolNumber getProtocolEntries :: Bool -> IO [ProtocolEntry] setProtocolEntry :: Bool -> IO () getProtocolEntry :: IO ProtocolEntry endProtocolEntry :: IO () -- | Use the Num instance (i.e. use a literal) to create a -- PortNumber value with the correct network-byte-ordering. You -- should not use the PortNum constructor. It will be removed in the next -- release. data PortNumber type NetworkName = String type NetworkAddr = CULong data NetworkEntry NetworkEntry :: NetworkName -> [NetworkName] -> Family -> NetworkAddr -> NetworkEntry networkName :: NetworkEntry -> NetworkName networkAliases :: NetworkEntry -> [NetworkName] networkFamily :: NetworkEntry -> Family networkAddress :: NetworkEntry -> NetworkAddr getNetworkByName :: NetworkName -> IO NetworkEntry getNetworkByAddr :: NetworkAddr -> Family -> IO NetworkEntry -- | Get the list of network entries. getNetworkEntries :: Bool -> IO [NetworkEntry] -- | Open the network name database. The parameter specifies whether a -- connection is maintained open between various networkEntry calls setNetworkEntry :: Bool -> IO () getNetworkEntry :: IO NetworkEntry -- | Close the connection to the network name database. endNetworkEntry :: IO () ifNameToIndex :: String -> IO (Maybe Int) instance Typeable ServiceEntry instance Typeable ProtocolEntry instance Typeable HostEntry instance Typeable NetworkEntry instance Show ServiceEntry instance Read ProtocolEntry instance Show ProtocolEntry instance Read HostEntry instance Show HostEntry instance Read NetworkEntry instance Show NetworkEntry instance Storable NetworkEntry instance Storable HostEntry instance Storable ProtocolEntry instance Storable ServiceEntry -- | This module is kept for backwards-compatibility. New users are -- encouraged to use Network.Socket instead. -- -- Network was intended as a "higher-level" interface to -- networking facilities, and only supports TCP. module Network -- | Represents a socket. The fields are, respectively: -- --
-- main = withSocketsDo $ do {...}
--
--
-- It is fine to nest calls to withSocketsDo, and to perform
-- networking operations after withSocketsDo has returned.
--
-- In newer versions of the network library it is only necessary
-- to call withSocketsDo if you are calling the MkSocket
-- constructor directly. However, for compatibility with older versions
-- on Windows, it is good practice to always call withSocketsDo
-- (it's very cheap).
withSocketsDo :: IO a -> IO a
-- | Creates the server side socket which has been bound to the specified
-- port.
--
-- maxListenQueue (typically 128) is specified to the listen
-- queue. This is good enough for normal network servers but is too small
-- for high performance servers.
--
-- To avoid the "Address already in use" problems, the ReuseAddr
-- socket option is set on the listening socket.
--
-- If available, the IPv6Only socket option is set to 0 so that
-- both IPv4 and IPv6 can be accepted with this socket.
--
-- If you don't like the behavior above, please use the lower level
-- listen instead.
listenOn :: PortID -> IO Socket
-- | Accept a connection on a socket created by listenOn. Normal I/O
-- operations (see System.IO) can be used on the Handle
-- returned to communicate with the client. Notice that although you can
-- pass any Socket to Network.accept, only sockets of either AF_UNIX,
-- AF_INET, or AF_INET6 will work (this shouldn't be a problem, though).
-- When using AF_UNIX, HostName will be set to the path of the socket and
-- PortNumber to -1.
accept :: Socket -> IO (Handle, HostName, PortNumber)
-- | Close the socket. All future operations on the socket object will
-- fail. The remote end will receive no more data (after queued data is
-- flushed).
sClose :: Socket -> IO ()
-- | Calling connectTo creates a client side socket which is
-- connected to the given host and port. The Protocol and socket type is
-- derived from the given port identifier. If a port number is given then
-- the result is always an internet family Stream socket.
connectTo :: HostName -> PortID -> IO Handle
sendTo :: HostName -> PortID -> String -> IO ()
recvFrom :: HostName -> PortID -> IO String
-- | Returns the PortID associated with a given socket.
socketPort :: Socket -> IO PortID
instance Show PortID
instance Eq PortID