Making getAddrInfo polymorphic#587
Conversation
endgame
left a comment
There was a problem hiding this comment.
Would it be worth putting a {-# DEPRECATED #-} on getAddrInfo, and laying out a migration plan of:
- Remove
getAddrInfo - Re-add
getAddrInfo = getAddrInfoNE, deprecategetAddrInfoNE - Remove
getAddrInfoNE?
|
It is a nice idea to put |
|
It would be worth making Roughly, getAddrInfo
:: (??? t)
=> Maybe AddrInfo
-> Maybe HostName
-> Maybe ServiceName
-> IO (t AddrInfo)
``` |
|
Some thoughts, which might conflict with each other:
|
Network/Socket/Info.hsc
Outdated
| -> IO (NE.NonEmpty AddrInfo) | ||
| getAddrInfoNE hints node service = | ||
| -- getAddrInfo never returns an empty list. | ||
| NE.fromList <$> getAddrInfo hints node service |
There was a problem hiding this comment.
Since getAddrInfoList also does a non-empty check and throws an IO error if the list is empty, you could make getAddrInfoNE the "real" function and implement getAddrInfoList by fmapping toList over the result of getAddrInfoNE?
d97f57d to
795cebb
Compare
I cannot find a way to deprecate instance from the GHC documentation. |
OK. Done. |
|
How about not allocating the head tuple when constucting the |
| getAddrInfo | ||
| class GetAddrInfo t where | ||
| ----------------------------------------------------------------------------- | ||
| -- | Resolve a host or service name to one or more addresses. |
There was a problem hiding this comment.
I rendered the haddocks, and it doesn't give the reader a way to see what instances of GetAddrInfo exist. I think we should document them here.
Alternatively, we could use the IsList class? But I think that will be more confusing and should only be for -XOverloadedLists support.
There was a problem hiding this comment.
It seems to me that IsList is confusing.
1411634 improves the doc.
|
IsList example: Applicative and Semigroup example: Which type signature would be better? |
I think |
|
@endgame I like the current implementation. |
|
Is this ready for merging? |
endgame
left a comment
There was a problem hiding this comment.
Some final thoughts, most small. I reworded the haddock too.
| -- >>> addr <- NE.head <$> getAddrInfo (Just hints) (Just "127.0.0.1") (Just "http") | ||
| -- >>> addrAddress addr | ||
| -- 127.0.0.1:80 | ||
| getAddrInfo |
There was a problem hiding this comment.
A @since line might also be useful for future readers, to know when a NonEmpty is available.
Co-authored-by: endgame <[email protected]>
Co-authored-by: endgame <[email protected]>
endgame
left a comment
There was a problem hiding this comment.
Seems good. One final nit (my fault, sorry) and a thought for future work. Thank you for this.
| | ptr_ai == nullPtr = return [] | ||
| -- POSIX requires that getaddrinfo(3) returns at least one addrinfo. | ||
| -- See: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html | ||
| | ptr_ai == nullPtr = ioError $ mkIOError NoSuchThing "getaddrinfo must return at least one addrinfo" Nothing Nothing |
There was a problem hiding this comment.
Might be nice to capture errno in the IO error, but that's out of scope for this PR.
There was a problem hiding this comment.
The error reporting of network is historically poor.
We should implement a mechanism to maintain error numbers in the future.
Co-authored-by: endgame <[email protected]>
|
Merged. |
haskell#587 removed the call to c_freeaddrinfo in getAddrInfoNE. This restores it and in addition makes the function async exception safe.
haskell#587 removed the call to `c_freeaddrinfo` in `getaddrinfo`. This restores it and in addition makes the function async exception safe.
haskell#587 removed the call to `c_freeaddrinfo` in `getaddrinfo`. This restores it and in addition makes the function async exception safe.
haskell#587 removed the call to `c_freeaddrinfo` in `getaddrinfo`. This restores it and in addition makes the function async exception safe.
## Version 3.2.7.0 * Using nested `bracket` for `gracefulClose`. [#591](haskell/network#590) * Fix memory leak in getaddrinfo and make it async exception safe. [#591](haskell/network#591) * Make call to c_free async exception safe. [#592](haskell/network#592) ## Version 3.2.6.0 * fixing the Show instance of IPv4-mapped IPv6 address on little endian machines ## Version 3.2.5.0 * `gracefulClose` based on STM racing and `timeout`. [#587](haskell/network#587) ## Version 3.2.4.0 * New API: setSockOptValue. [#588](haskell/network#588) ## Version 3.2.3.0 * Making getAddrInfo polymorphic [#587](haskell/network#587) ## Version 3.2.2.0 * New API: waitReadSocketSTM, waitAndCancelReadSocketSTM, waitWriteSocketSTM, waitAndCancelWriteSocketSTM [#586](haskell/network#586) * Checking the length of ASCII string allowing trailing 0. [#585](haskell/network#585) ## Version 3.2.1.0 * Trying to release with the latest autoreconf. Packing "network" in the local directory instead of CI. * Remove includes from .cabal-file [#583](haskell/network#583) * making gracefulClose more graceful [#580](haskell/network#580) * Update config.guess, config.sub to their latest versions [#579](haskell/network#579)
The recent GHCs warn partial pattern matchings and partial functions.
So, let's provide
getAddrInfoNE:Since GHC 9.8 or later warn partial functions, I begin to think to provide:
getAddrInfoNE :: Maybe AddrInfo -> Maybe HostName -> Maybe ServiceName -> IO (NonEmpty AddrInfo)@khibino Would you review this PR?