-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Low-level networking interface -- -- Low-level networking interface @package network @version 2.3.0.11 -- | This module defines functions for handling URIs. It presents -- substantially the same interface as the older GHC Network.URI module, -- but is implemented using Parsec rather than a Regex library that is -- not available with Hugs. The internal representation of URI has been -- changed so that URI strings are more completely preserved when -- round-tripping to a URI value and back. -- -- In addition, four methods are provided for parsing different kinds of -- URI string (as noted in RFC3986): parseURI, -- parseURIReference, parseRelativeReference and -- parseAbsoluteURI. -- -- Further, four methods are provided for classifying different kinds of -- URI string (as noted in RFC3986): isURI, isURIReference, -- isRelativeReference and isAbsoluteURI. -- -- The long-standing official reference for URI handling was RFC2396 [1], -- as updated by RFC 2732 [2], but this was replaced by a new -- specification, RFC3986 [3] in January 2005. This latter specification -- has been used as the primary reference for constructing the URI parser -- implemented here, and it is intended that there is a direct -- relationship between the syntax definition in that document and this -- parser implementation. -- -- RFC 1808 [4] contains a number of test cases for relative URI -- handling. Dan Connolly's Python module uripath.py [5] also -- contains useful details and test cases. -- -- Some of the code has been copied from the previous GHC implementation, -- but the parser is replaced with one that performs more complete syntax -- checking of the URI itself, according to RFC3986 [3]. -- -- References -- --
    --
  1. http://www.ietf.org/rfc/rfc2396.txt
  2. --
  3. http://www.ietf.org/rfc/rfc2732.txt
  4. --
  5. http://www.ietf.org/rfc/rfc3986.txt
  6. --
  7. http://www.ietf.org/rfc/rfc1808.txt
  8. --
  9. http://www.w3.org/2000/10/swap/uripath.py
  10. --
module Network.URI -- | Represents a general universal resource identifier using its component -- parts. -- -- For example, for the URI -- --
--   foo://anonymous@www.haskell.org:42/ghc?query#frag
--   
-- -- the components are: data URI URI :: String -> Maybe URIAuth -> String -> String -> String -> URI -- |
--   foo:
--   
uriScheme :: URI -> String -- |
--   //anonymous@www.haskell.org:42
--   
uriAuthority :: URI -> Maybe URIAuth -- |
--   /ghc
--   
uriPath :: URI -> String -- |
--   ?query
--   
uriQuery :: URI -> String -- |
--   #frag
--   
uriFragment :: URI -> String -- | Type for authority value within a URI data URIAuth URIAuth :: String -> String -> String -> URIAuth -- |
--   anonymous@
--   
uriUserInfo :: URIAuth -> String -- |
--   www.haskell.org
--   
uriRegName :: URIAuth -> String -- |
--   :42
--   
uriPort :: URIAuth -> String -- | Blank URI nullURI :: URI -- | Turn a string containing a URI into a URI. Returns -- Nothing if the string is not a valid URI; (an absolute URI with -- optional fragment identifier). -- -- NOTE: this is different from the previous network.URI, whose -- parseURI function works like parseURIReference in this -- module. parseURI :: String -> Maybe URI -- | Parse a URI reference to a URI value. Returns Nothing if -- the string is not a valid URI reference. (an absolute or relative URI -- with optional fragment identifier). parseURIReference :: String -> Maybe URI -- | Parse a relative URI to a URI value. Returns Nothing if -- the string is not a valid relative URI. (a relative URI with optional -- fragment identifier). parseRelativeReference :: String -> Maybe URI -- | Parse an absolute URI to a URI value. Returns Nothing if -- the string is not a valid absolute URI. (an absolute URI without a -- fragment identifier). parseAbsoluteURI :: String -> Maybe URI -- | Test if string contains a valid URI (an absolute URI with optional -- fragment identifier). isURI :: String -> Bool -- | Test if string contains a valid URI reference (an absolute or relative -- URI with optional fragment identifier). isURIReference :: String -> Bool -- | Test if string contains a valid relative URI (a relative URI with -- optional fragment identifier). isRelativeReference :: String -> Bool -- | Test if string contains a valid absolute URI (an absolute URI without -- a fragment identifier). isAbsoluteURI :: String -> Bool -- | Test if string contains a valid IPv6 address isIPv6address :: String -> Bool -- | Test if string contains a valid IPv4 address isIPv4address :: String -> Bool -- | Compute an absolute URI for a supplied URI relative to a given -- base. relativeTo :: URI -> URI -> Maybe URI -- | Returns a new URI which represents the value of the first -- URI interpreted as relative to the second URI. For -- example: -- --
--   "foo" `relativeTo` "http://bar.org/" = "http://bar.org/foo"
--   "http:foo" `nonStrictRelativeTo` "http://bar.org/" = "http://bar.org/foo"
--   
-- -- Algorithm from RFC3986 [3], section 5.2.2 nonStrictRelativeTo :: URI -> URI -> Maybe URI -- | Returns a new URI which represents the relative location of the -- first URI with respect to the second URI. Thus, the -- values supplied are expected to be absolute URIs, and the result -- returned may be a relative URI. -- -- Example: -- --
--   "http://example.com/Root/sub1/name2#frag"
--     `relativeFrom` "http://example.com/Root/sub2/name2#frag"
--     == "../sub1/name2#frag"
--   
-- -- There is no single correct implementation of this function, but any -- acceptable implementation must satisfy the following: -- --
--   (uabs `relativeFrom` ubase) `relativeTo` ubase == uabs
--   
-- -- For any valid absolute URI. (cf. -- http://lists.w3.org/Archives/Public/uri/2003Jan/0008.html -- http://lists.w3.org/Archives/Public/uri/2003Jan/0005.html) relativeFrom :: URI -> URI -> URI -- | Turn a URI into a string. -- -- Uses a supplied function to map the userinfo part of the URI. -- -- The Show instance for URI uses a mapping that hides any password that -- may be present in the URI. Use this function with argument id -- to preserve the password in the formatted output. uriToString :: (String -> String) -> URI -> ShowS -- | Returns True if the character is a "reserved" character in a -- URI. To include a literal instance of one of these characters in a -- component of a URI, it must be escaped. isReserved :: Char -> Bool -- | Returns True if the character is an "unreserved" character in a -- URI. These characters do not need to be escaped in a URI. The only -- characters allowed in a URI are either "reserved", "unreserved", or an -- escape sequence (% followed by two hex digits). isUnreserved :: Char -> Bool -- | Returns True if the character is allowed in a URI. isAllowedInURI :: Char -> Bool -- | Returns True if the character is allowed unescaped in a URI. isUnescapedInURI :: Char -> Bool -- | Escape character if supplied predicate is not satisfied, otherwise -- return character as singleton string. escapeURIChar :: (Char -> Bool) -> Char -> String -- | Can be used to make a string valid for use in a URI. escapeURIString :: (Char -> Bool) -> String -> String -- | Turns all instances of escaped characters in the string back into -- literal characters. unEscapeString :: String -> String -- | Case normalization; cf. RFC3986 section 6.2.2.1 NOTE: authority case -- normalization is not performed normalizeCase :: String -> String -- | Encoding normalization; cf. RFC3986 section 6.2.2.2 normalizeEscape :: String -> String -- | Path segment normalization; cf. RFC3986 section 6.2.2.4 normalizePathSegments :: String -> String parseabsoluteURI :: String -> Maybe URI escapeString :: String -> (Char -> Bool) -> String reserved :: Char -> Bool unreserved :: Char -> Bool scheme :: URI -> String authority :: URI -> String path :: URI -> String query :: URI -> String fragment :: URI -> String instance Typeable URIAuth instance Typeable URI instance Eq URIAuth instance Data URIAuth instance Eq URI instance Data URI instance Show URI -- | 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 newtype PortNumber PortNum :: Word16 -> PortNumber data SockAddr SockAddrInet :: PortNumber -> HostAddress -> SockAddr SockAddrInet6 :: PortNumber -> FlowInfo -> HostAddress6 -> ScopeID -> SockAddr SockAddrUnix :: String -> 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 -- | This data type might have different constructors depending on what is -- supported by the operating system. data Family AF_UNSPEC :: Family AF_UNIX :: Family AF_INET :: Family AF_INET6 :: Family AF_SNA :: Family AF_DECnet :: Family AF_APPLETALK :: Family AF_ROUTE :: Family AF_X25 :: Family AF_AX25 :: Family AF_IPX :: Family AF_ISDN :: 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 -- | Throw an IOError corresponding to the current socket error. throwSocketError :: String -> 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. 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 -- | On Windows operating systems, the networking subsystem has to be -- initialised using withSocketsDo before any networking -- operations can be used. eg. -- --
--   main = withSocketsDo $ do {...}
--   
-- -- Although this is only strictly necessary on Windows platforms, it is -- harmless on other platforms, so for portability it is good practice to -- use it all the time. withSocketsDo :: IO a -> IO a -- | Zero a structure. zeroMemory :: Ptr a -> CSize -> IO () instance Typeable PortNumber instance Typeable SockAddr instance Eq PortNumber instance Ord PortNumber instance Eq SockAddr instance Eq Family instance Ord Family instance Read Family instance Show Family instance Storable HostAddress6 -- | 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 data Socket MkSocket :: CInt -> Family -> SocketType -> ProtocolNumber -> (MVar SocketStatus) -> Socket -- | This data type might have different constructors depending on what is -- supported by the operating system. data Family AF_UNSPEC :: Family AF_UNIX :: Family AF_INET :: Family AF_INET6 :: Family AF_SNA :: Family AF_DECnet :: Family AF_APPLETALK :: Family AF_ROUTE :: Family AF_X25 :: Family AF_AX25 :: Family AF_IPX :: Family AF_ISDN :: 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 -- | Socket Types. -- -- This data type might have different constructors depending on what is -- supported by the operating system. data SocketType NoSocketType :: SocketType Stream :: SocketType Datagram :: SocketType Raw :: SocketType RDM :: SocketType SeqPacket :: SocketType data SockAddr SockAddrInet :: PortNumber -> HostAddress -> SockAddr SockAddrInet6 :: PortNumber -> FlowInfo -> HostAddress6 -> ScopeID -> SockAddr SockAddrUnix :: String -> SockAddr data SocketStatus NotConnected :: SocketStatus Bound :: SocketStatus Listening :: SocketStatus Connected :: SocketStatus ConvertedToHandle :: SocketStatus Closed :: SocketStatus -- | Network byte order. type HostAddress = Word32 -- | Host byte order. type HostAddress6 = (Word32, Word32, Word32, Word32) type FlowInfo = Word32 type ScopeID = Word32 data ShutdownCmd ShutdownReceive :: ShutdownCmd ShutdownSend :: ShutdownCmd ShutdownBoth :: ShutdownCmd type ProtocolNumber = CInt -- | This is the default protocol for a given service. defaultProtocol :: ProtocolNumber newtype PortNumber PortNum :: Word16 -> PortNumber -- | 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 type ServiceName = String data AddrInfo AddrInfo :: [AddrInfoFlag] -> Family -> SocketType -> ProtocolNumber -> SockAddr -> Maybe String -> AddrInfo addrFlags :: AddrInfo -> [AddrInfoFlag] addrFamily :: AddrInfo -> Family addrSocketType :: AddrInfo -> SocketType addrProtocol :: AddrInfo -> ProtocolNumber addrAddress :: AddrInfo -> SockAddr addrCanonName :: AddrInfo -> Maybe String -- | Flags that control the querying behaviour of getAddrInfo. data AddrInfoFlag AI_ADDRCONFIG :: AddrInfoFlag AI_ALL :: AddrInfoFlag AI_CANONNAME :: AddrInfoFlag AI_NUMERICHOST :: AddrInfoFlag AI_NUMERICSERV :: AddrInfoFlag AI_PASSIVE :: AddrInfoFlag AI_V4MAPPED :: AddrInfoFlag -- | Indicate whether the given AddrInfoFlag will have any effect on -- this system. addrInfoFlagImplemented :: AddrInfoFlag -> Bool -- | Default hints for address lookup with getAddrInfo. The values -- of the addrAddress and addrCanonName fields are -- undefined, and are never inspected by getAddrInfo. defaultHints :: AddrInfo -- | Resolve a host or service name to one or more addresses. The -- AddrInfo values that this function returns contain -- SockAddr values that you can pass directly to connect or -- bindSocket. -- -- This function is protocol independent. It can return both IPv4 and -- IPv6 address information. -- -- The AddrInfo argument specifies the preferred query behaviour, -- socket options, or protocol. You can override these conveniently using -- Haskell's record update syntax on defaultHints, for example as -- follows: -- --
--   myHints = defaultHints { addrFlags = [AI_ADDRCONFIG, AI_CANONNAME] }
--   
-- -- Values for addrFlags control query behaviour. The supported -- flags are as follows: -- -- -- -- Note: Although the following flags are required by RFC 3493, -- they may not have an effect on all platforms, because the underlying -- network stack may not support them. To see whether a flag from the -- list below will have any effect, call addrInfoFlagImplemented. -- -- -- -- You must provide a Just value for at least one of the -- HostName or ServiceName arguments. HostName can -- be either a numeric network address (dotted quad for IPv4, -- colon-separated hex for IPv6) or a hostname. In the latter case, its -- addresses will be looked up unless AI_NUMERICHOST is specified -- as a hint. If you do not provide a HostName value and do -- not set AI_PASSIVE as a hint, network addresses in the result -- will contain the address of the loopback interface. -- -- If the query fails, this function throws an IO exception instead of -- returning an empty list. Otherwise, it returns a non-empty list of -- AddrInfo values. -- -- There are several reasons why a query might result in several values. -- For example, the queried-for host could be multihomed, or the service -- might be available via several protocols. -- -- Note: the order of arguments is slightly different to that defined for -- getaddrinfo in RFC 2553. The AddrInfo parameter comes -- first to make partial application easier. -- -- Example: let hints = defaultHints { addrFlags = [AI_ADDRCONFIG, -- AI_CANONNAME] } addrs <- getAddrInfo (Just hints) (Just -- www.haskell.org) (Just http) let addr = head addrs sock -- <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol -- addr) connect sock (addrAddress addr) getAddrInfo :: Maybe AddrInfo -> Maybe HostName -> Maybe ServiceName -> IO [AddrInfo] data NameInfoFlag NI_DGRAM :: NameInfoFlag NI_NAMEREQD :: NameInfoFlag NI_NOFQDN :: NameInfoFlag NI_NUMERICHOST :: NameInfoFlag NI_NUMERICSERV :: NameInfoFlag -- | Resolve an address to a host or service name. This function is -- protocol independent. -- -- The list of NameInfoFlag values controls query behaviour. The -- supported flags are as follows: -- -- -- -- Hostname and service name lookups can be expensive. You can specify -- which lookups to perform via the two Bool arguments. If one of -- these is False, the corresponding value in the returned tuple -- will be Nothing, and no lookup will be performed. -- -- If a host or service's name cannot be looked up, then the numeric form -- of the address or service will be returned. -- -- If the query fails, this function throws an IO exception. -- -- Example: (hostName, _) <- getNameInfo [] True False myAddress -- getNameInfo :: [NameInfoFlag] -> Bool -> Bool -> SockAddr -> IO (Maybe HostName, Maybe ServiceName) -- | Create a new socket using the given address family, socket type and -- protocol number. The address family is usually AF_INET, -- AF_INET6, or AF_UNIX. The socket type is usually -- Stream or Datagram. The protocol number is usually -- defaultProtocol. If AF_INET6 is used, the -- IPv6Only socket option is set to 0 so that both IPv4 and IPv6 -- can be handled with one socket. socket :: Family -> SocketType -> ProtocolNumber -> IO Socket -- | Build a pair of connected socket objects using the given address -- family, socket type, and protocol number. Address family, socket type, -- and protocol number are as for the socket function above. -- Availability: Unix. socketPair :: Family -> SocketType -> ProtocolNumber -> IO (Socket, Socket) -- | Connect to a remote socket at address. connect :: Socket -> SockAddr -> IO () -- | Bind the socket to an address. The socket must not already be bound. -- The Family passed to bindSocket must be the same as -- that passed to socket. If the special port number -- aNY_PORT is passed then the system assigns the next available -- use port. bindSocket :: Socket -> SockAddr -> IO () -- | Listen for connections made to the socket. The second argument -- specifies the maximum number of queued connections and should be at -- least 1; the maximum value is system-dependent (usually 5). listen :: Socket -> Int -> IO () -- | Accept a connection. The socket must be bound to an address and -- listening for connections. The return value is a pair (conn, -- address) where conn is a new socket object usable to -- send and receive data on the connection, and address is the -- address bound to the socket on the other end of the connection. accept :: Socket -> IO (Socket, SockAddr) getPeerName :: Socket -> IO SockAddr getSocketName :: Socket -> IO SockAddr -- | Returns the processID, userID and groupID of the socket's peer. -- -- Only available on platforms that support SO_PEERCRED on domain -- sockets. getPeerCred :: Socket -> IO (CUInt, CUInt, CUInt) socketPort :: Socket -> IO PortNumber -- | Turns a Socket into an Handle. By default, the new handle is -- unbuffered. Use hSetBuffering to change the buffering. -- -- Note that since a Handle is automatically closed by a finalizer -- when it is no longer referenced, you should avoid doing any more -- operations on the Socket after calling socketToHandle. -- To close the Socket after socketToHandle, call -- hClose on the Handle. socketToHandle :: Socket -> IOMode -> IO Handle -- | 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. -- -- NOTE: blocking on Windows unless you compile with -threaded (see GHC -- ticket #1129) sendTo :: Socket -> String -> SockAddr -> IO Int -- | 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. sendBufTo :: Socket -> Ptr a -> Int -> SockAddr -> IO Int -- | Receive data from the socket. The socket need not be in a connected -- state. Returns (bytes, nbytes, address) where bytes -- is a String of length nbytes representing the data -- received and address is a SockAddr representing the -- address of the sending socket. -- -- NOTE: blocking on Windows unless you compile with -threaded (see GHC -- ticket #1129) recvFrom :: Socket -> Int -> IO (String, Int, SockAddr) -- | Receive data from the socket, writing it into buffer instead of -- creating a new string. The socket need not be in a connected state. -- Returns (nbytes, address) where nbytes is the number -- of bytes received and address is a SockAddr -- representing the address of the sending socket. -- -- NOTE: blocking on Windows unless you compile with -threaded (see GHC -- ticket #1129) recvBufFrom :: Socket -> Ptr a -> Int -> IO (Int, SockAddr) -- | 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 -> String -> IO Int -- | 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 String recvLen :: Socket -> Int -> IO (String, Int) inet_addr :: String -> IO HostAddress inet_ntoa :: HostAddress -> IO String -- | Shut down one or both halves of the connection, depending on the -- second argument to the function. If the second argument is -- ShutdownReceive, further receives are disallowed. If it is -- ShutdownSend, further sends are disallowed. If it is -- ShutdownBoth, further sends and receives are disallowed. shutdown :: Socket -> ShutdownCmd -> IO () -- | 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 () sIsConnected :: Socket -> IO Bool sIsBound :: Socket -> IO Bool sIsListening :: Socket -> IO Bool sIsReadable :: Socket -> IO Bool sIsWritable :: Socket -> IO Bool data SocketOption DummySocketOption__ :: SocketOption Debug :: SocketOption ReuseAddr :: SocketOption Type :: SocketOption SoError :: SocketOption DontRoute :: SocketOption Broadcast :: SocketOption SendBuffer :: SocketOption RecvBuffer :: SocketOption KeepAlive :: SocketOption OOBInline :: SocketOption TimeToLive :: SocketOption MaxSegment :: SocketOption NoDelay :: SocketOption Linger :: SocketOption RecvLowWater :: SocketOption SendLowWater :: SocketOption RecvTimeOut :: SocketOption SendTimeOut :: SocketOption IPv6Only :: SocketOption getSocketOption :: Socket -> SocketOption -> IO Int setSocketOption :: Socket -> SocketOption -> Int -> IO () sendFd :: Socket -> CInt -> IO () recvFd :: Socket -> IO CInt sendAncillary :: Socket -> Int -> Int -> Int -> Ptr a -> Int -> IO () recvAncillary :: Socket -> Int -> Int -> IO (Int, Int, Ptr a, Int) aNY_PORT :: PortNumber -- | The IPv4 wild card address. iNADDR_ANY :: HostAddress -- | The IPv6 wild card address. iN6ADDR_ANY :: HostAddress6 sOMAXCONN :: Int sOL_SOCKET :: Int sCM_RIGHTS :: Int maxListenQueue :: Int -- | On Windows operating systems, the networking subsystem has to be -- initialised using withSocketsDo before any networking -- operations can be used. eg. -- --
--   main = withSocketsDo $ do {...}
--   
-- -- Although this is only strictly necessary on Windows platforms, it is -- harmless on other platforms, so for portability it is good practice to -- use it all the time. withSocketsDo :: IO a -> IO a fdSocket :: Socket -> CInt mkSocket :: CInt -> Family -> SocketType -> ProtocolNumber -> SocketStatus -> IO Socket packFamily :: Family -> CInt unpackFamily :: CInt -> Family packSocketType :: SocketType -> CInt -- | 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 () instance Typeable SocketStatus instance Typeable SocketOption instance Typeable SocketType instance Typeable Socket instance Typeable ShutdownCmd instance Typeable AddrInfoFlag instance Typeable AddrInfo instance Typeable NameInfoFlag instance Eq SocketStatus instance Show SocketStatus instance Eq SocketType instance Ord SocketType instance Read SocketType instance Show SocketType 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 instance Storable PortNumber instance Integral PortNumber instance Real PortNumber instance Num PortNumber instance Enum PortNumber instance Show PortNumber instance Show Socket instance Eq Socket -- | 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 data to the socket. The socket must be in a connected state. -- Returns the number of bytes sent. Applications are responsible for -- ensuring that all data has been sent. -- -- Because a lazily generated ByteString may be arbitrarily long, -- this function caps the amount it will attempt to send at 4MB. This -- number is large (so it should not penalize performance on fast -- networks), but not outrageously so (to avoid demanding lazily computed -- data unnecessarily early). Before being sent, the lazy -- ByteString will be converted to a list of strict -- ByteStrings with toChunks; at most 1024 chunks will be -- sent. Unix only. send :: Socket -> ByteString -> IO Int64 -- | Send data to the socket. The socket must be in a connected state. This -- function continues to send data until either all data has been sent or -- an error occurs. If there is an error, an exception is raised, and -- there is no way to determine how much data was sent. Unix only. 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 () 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 () 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 -- | The Network interface is a "higher-level" interface to -- networking facilities, and it is recommended unless you need the -- lower-level interface in Network.Socket. module Network data Socket data PortID Service :: String -> PortID PortNumber :: PortNumber -> PortID UnixSocket :: String -> PortID -- | 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 data PortNumber -- | On Windows operating systems, the networking subsystem has to be -- initialised using withSocketsDo before any networking -- operations can be used. eg. -- --
--   main = withSocketsDo $ do {...}
--   
-- -- Although this is only strictly necessary on Windows platforms, it is -- harmless on other platforms, so for portability it is good practice to -- use it all the time. withSocketsDo :: IO a -> IO a -- | Creates the server side socket which has been bound to the specified -- port. -- -- NOTE: To avoid the "Address already in use" problems popped up several -- times on the GHC-Users mailing list we set the ReuseAddr socket -- option on the listening socket. If you don't want this behaviour, -- please use the lower level listen instead. -- -- If available, the IPv6Only socket option is set to 0 so that -- both IPv4 and IPv6 can be accepted with this socket. 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