Skip to content

Commit 2594fc9

Browse files
committed
Add support for network-3.0 API
1 parent 5b76f23 commit 2594fc9

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Drop redundant dependency on `HUnit`
55
- Add more explicit `SafeHaskell` annotations to modules; all modules
66
except for `System.Debian` are now explicitly either `Safe` or `Trustworthy`
7+
- Add support for `network-3.0` and `network-3.1`
78

89
## 1.4.1.0
910

MissingH.cabal

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ extra-source-files:
4545
winbuild.bat
4646
wintest.bat
4747

48+
flag network--GE-3_0_0
49+
description: [network](http://hackage.haskell.org/package/network) ≥ 3.0.0
50+
default: True
51+
manual: False
52+
4853
source-repository head
4954
type: git
5055
location: https://github.com/hvr/missingh.git
@@ -122,7 +127,6 @@ library
122127
, filepath >= 1.3.0.0 && < 1.5
123128
, hslogger >= 1.3.0.0 && < 1.4
124129
, mtl >= 1.1.1.0 && < 2.3
125-
, network >= 2.6.3.1 && < 2.9
126130
, old-locale == 1.0.*
127131
, old-time == 1.1.*
128132
, parsec == 3.1.* && (< 3.1.12 || >= 3.1.13)
@@ -131,6 +135,12 @@ library
131135
, regex-compat >= 0.95.1 && < 0.96
132136
, time >= 1.4 && < 1.10
133137

138+
if flag(network--GE-3_0_0)
139+
build-depends: network-bsd >= 2.8.1 && <2.9,
140+
network >= 3.0 && <3.2
141+
else
142+
build-depends: network >= 2.6.3.1 && <2.9
143+
134144
If !os(windows)
135145
Build-Depends: unix >= 2.5.1.0 && < 2.8
136146

src/Network/SocketServer.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ simpleTCPOptions :: Int -- ^ Port Number
7878
-> InetServerOptions
7979
simpleTCPOptions p = InetServerOptions {listenQueueSize = 5,
8080
portNumber = (fromIntegral p),
81-
interface = iNADDR_ANY,
81+
interface = 0,
8282
reuse = False,
8383
family = AF_INET,
8484
sockType = Stream,
@@ -98,7 +98,7 @@ setupSocketServer opts =
9898
setSocketOption s ReuseAddr (case (reuse opts) of
9999
True -> 1
100100
False -> 0)
101-
bindSocket s (SockAddrInet (portNumber opts)
101+
bind s (SockAddrInet (portNumber opts)
102102
(interface opts))
103103
listen s (listenQueueSize opts)
104104
return $ SocketServer {optionsSS = opts, sockSS = s}
@@ -107,7 +107,7 @@ setupSocketServer opts =
107107
handlers, if any. -}
108108
closeSocketServer :: SocketServer -> IO ()
109109
closeSocketServer ss =
110-
sClose (sockSS ss)
110+
close (sockSS ss)
111111

112112
{- | Handle one incoming request from the given 'SocketServer'. -}
113113
handleOne :: SocketServer -> HandlerT -> IO ()

src/Network/Utils.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ module Network.Utils (niceSocketsDo, connectTCP, connectTCPAddr,
2626
listenTCPAddr, showSockAddr)
2727
where
2828

29-
import Network
3029
import Network.BSD
3130
import Network.Socket
3231
import System.IO
@@ -72,14 +71,14 @@ listenTCPAddr :: SockAddr -> Int -> IO Socket
7271
listenTCPAddr addr queuelen = do
7372
proto <- getProtocolNumber "tcp"
7473
s <- socket AF_INET Stream proto
75-
bindSocket s addr
74+
bind s addr
7675
listen s queuelen
7776
return s
7877

7978
showSockAddr :: SockAddr -> IO String
8079
#if !(defined(mingw32_HOST_OS) || defined(mingw32_TARGET_OS) || defined(__MINGW32__))
8180
showSockAddr (SockAddrUnix x) = return $ "UNIX socket at " ++ x
8281
#endif
83-
showSockAddr (SockAddrInet port host) =
84-
do h <- inet_ntoa host
82+
showSockAddr sa@(SockAddrInet port host) =
83+
do (Just h,_) <- getNameInfo [NI_NUMERICHOST] True False sa
8584
return $ "IPv4 host " ++ h ++ ", port " ++ (show port)

0 commit comments

Comments
 (0)