@@ -202,6 +202,47 @@ defaultHints = AddrInfo {
202
202
}
203
203
204
204
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
205
246
getAddrInfo
206
247
:: Maybe AddrInfo -- ^ preferred socket type or protocol
207
248
-> Maybe HostName -- ^ host name to look up
@@ -214,47 +255,6 @@ instance GetAddrInfo [] where
214
255
instance GetAddrInfo NE. NonEmpty where
215
256
getAddrInfo = getAddrInfoNE
216
257
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
-
258
258
getAddrInfoList
259
259
:: Maybe AddrInfo -- ^ preferred socket type or protocol
260
260
-> Maybe HostName -- ^ host name to look up
0 commit comments