Skip to content

Commit

Permalink
Adds a function to show the defaultHints without reading their undefi…
Browse files Browse the repository at this point in the history
…ned fields (#291)
  • Loading branch information
MaxGabriel authored and eborden committed Jan 2, 2018
1 parent 3e779b2 commit e15dab1
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Network/Socket/Info.hsc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE RecordWildCards #-}

#include "HsNet.h"
##include "HsNetDef.h"
Expand Down Expand Up @@ -214,6 +215,26 @@ defaultHints = AddrInfo {
addrCanonName = undefined
}

-- | Shows the fields of 'defaultHints', without inspecting the by-default undefined fields 'addrAddress' and 'addrCanonName'.
showDefaultHints :: AddrInfo -> String
showDefaultHints AddrInfo{..} = concat
[ "AddrInfo {"
, "addrFlags = "
, show addrFlags
, ", addrFamily = "
, show addrFamily
, ", addrSocketType = "
, show addrSocketType
, ", addrProtocol = "
, show addrProtocol
, ", addrAddress = "
, "<assumed to be undefined>"
, ", addrCanonName = "
, "<assumed to be undefined>"
, "}"
]


-----------------------------------------------------------------------------
-- | Resolve a host or service name to one or more addresses.
-- The 'AddrInfo' values that this function returns contain 'SockAddr'
Expand Down Expand Up @@ -274,7 +295,7 @@ getAddrInfo hints node service = withSocketsDo $
_ -> do err <- gai_strerror ret
let message = concat
[ "Network.Socket.getAddrInfo (called with preferred socket type/protocol: "
, show hints
, maybe (show hints) showDefaultHints hints
, ", host name: "
, show node
, ", service name: "
Expand Down

0 comments on commit e15dab1

Please sign in to comment.