Skip to content

Commit c3fbccc

Browse files
committed
exporting getAddrInfo only
1 parent 152aea0 commit c3fbccc

File tree

3 files changed

+44
-43
lines changed

3 files changed

+44
-43
lines changed

Network/Socket.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ module Network.Socket (
112112
withSocketsDo,
113113

114114
-- * Address information
115-
GetAddrInfo (..),
115+
getAddrInfo,
116116

117117
-- ** Types
118118
HostName,

Network/Socket/Info.hsc

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,47 @@ defaultHints = AddrInfo {
202202
}
203203

204204
class GetAddrInfo t where
205+
-----------------------------------------------------------------------------
206+
-- | Resolve a host or service name to one or more addresses.
207+
-- The 'AddrInfo' values that this function returns contain 'SockAddr'
208+
-- values that you can pass directly to 'connect' or
209+
-- 'bind'.
210+
--
211+
-- This function is protocol independent. It can return both IPv4 and
212+
-- IPv6 address information.
213+
--
214+
-- The 'AddrInfo' argument specifies the preferred query behaviour,
215+
-- socket options, or protocol. You can override these conveniently
216+
-- using Haskell's record update syntax on 'defaultHints', for example
217+
-- as follows:
218+
--
219+
-- >>> let hints = defaultHints { addrFlags = [AI_NUMERICHOST], addrSocketType = Stream }
220+
--
221+
-- You must provide a 'Just' value for at least one of the 'HostName'
222+
-- or 'ServiceName' arguments. 'HostName' can be either a numeric
223+
-- network address (dotted quad for IPv4, colon-separated hex for
224+
-- IPv6) or a hostname. In the latter case, its addresses will be
225+
-- looked up unless 'AI_NUMERICHOST' is specified as a hint. If you
226+
-- do not provide a 'HostName' value /and/ do not set 'AI_PASSIVE' as
227+
-- a hint, network addresses in the result will contain the address of
228+
-- the loopback interface.
229+
--
230+
-- If the query fails, this function throws an IO exception instead of
231+
-- returning an empty list. Otherwise, it returns a non-empty list
232+
-- of 'AddrInfo' values.
233+
--
234+
-- There are several reasons why a query might result in several
235+
-- values. For example, the queried-for host could be multihomed, or
236+
-- the service might be available via several protocols.
237+
--
238+
-- Note: the order of arguments is slightly different to that defined
239+
-- for @getaddrinfo@ in RFC 2553. The 'AddrInfo' parameter comes first
240+
-- to make partial application easier.
241+
--
242+
-- >>> import qualified Data.List.NonEmpty as NE
243+
-- >>> addr <- NE.head <$> getAddrInfo (Just hints) (Just "127.0.0.1") (Just "http")
244+
-- >>> addrAddress addr
245+
-- 127.0.0.1:80
205246
getAddrInfo
206247
:: Maybe AddrInfo -- ^ preferred socket type or protocol
207248
-> Maybe HostName -- ^ host name to look up
@@ -214,47 +255,6 @@ instance GetAddrInfo [] where
214255
instance GetAddrInfo NE.NonEmpty where
215256
getAddrInfo = getAddrInfoNE
216257

217-
-----------------------------------------------------------------------------
218-
-- | Resolve a host or service name to one or more addresses.
219-
-- The 'AddrInfo' values that this function returns contain 'SockAddr'
220-
-- values that you can pass directly to 'connect' or
221-
-- 'bind'.
222-
--
223-
-- This function is protocol independent. It can return both IPv4 and
224-
-- IPv6 address information.
225-
--
226-
-- The 'AddrInfo' argument specifies the preferred query behaviour,
227-
-- socket options, or protocol. You can override these conveniently
228-
-- using Haskell's record update syntax on 'defaultHints', for example
229-
-- as follows:
230-
--
231-
-- >>> let hints = defaultHints { addrFlags = [AI_NUMERICHOST], addrSocketType = Stream }
232-
--
233-
-- You must provide a 'Just' value for at least one of the 'HostName'
234-
-- or 'ServiceName' arguments. 'HostName' can be either a numeric
235-
-- network address (dotted quad for IPv4, colon-separated hex for
236-
-- IPv6) or a hostname. In the latter case, its addresses will be
237-
-- looked up unless 'AI_NUMERICHOST' is specified as a hint. If you
238-
-- do not provide a 'HostName' value /and/ do not set 'AI_PASSIVE' as
239-
-- a hint, network addresses in the result will contain the address of
240-
-- the loopback interface.
241-
--
242-
-- If the query fails, this function throws an IO exception instead of
243-
-- returning an empty list. Otherwise, it returns a non-empty list
244-
-- of 'AddrInfo' values.
245-
--
246-
-- There are several reasons why a query might result in several
247-
-- values. For example, the queried-for host could be multihomed, or
248-
-- the service might be available via several protocols.
249-
--
250-
-- Note: the order of arguments is slightly different to that defined
251-
-- for @getaddrinfo@ in RFC 2553. The 'AddrInfo' parameter comes first
252-
-- to make partial application easier.
253-
--
254-
-- >>> addr:_ <- getAddrInfo (Just hints) (Just "127.0.0.1") (Just "http")
255-
-- >>> addrAddress addr
256-
-- 127.0.0.1:80
257-
258258
getAddrInfoList
259259
:: Maybe AddrInfo -- ^ preferred socket type or protocol
260260
-> Maybe HostName -- ^ host name to look up

Network/Socket/Syscall.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ import Network.Socket.Types
6363
-- can be handled with one socket.
6464
--
6565
-- >>> import Network.Socket
66+
-- >>> import qualified Data.List.NonEmpty as NE
6667
-- >>> let hints = defaultHints { addrFlags = [AI_NUMERICHOST, AI_NUMERICSERV], addrSocketType = Stream }
67-
-- >>> addr:_ <- getAddrInfo (Just hints) (Just "127.0.0.1") (Just "5000")
68+
-- >>> addr <- NE.head <$> getAddrInfo (Just hints) (Just "127.0.0.1") (Just "5000")
6869
-- >>> sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr)
6970
-- >>> Network.Socket.bind sock (addrAddress addr)
7071
-- >>> getSocketName sock

0 commit comments

Comments
 (0)