Skip to content

Commit

Permalink
Merge pull request #205 from ggreif/deprecation-notices
Browse files Browse the repository at this point in the history
add deprecation pragmas
  • Loading branch information
kazu-yamamoto authored Jul 19, 2016
2 parents d2215c2 + 7a50ce8 commit 77da9bc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 23 deletions.
8 changes: 4 additions & 4 deletions Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ listenOn (Service serv) = do
(\sock -> do
port <- getServicePortNumber serv
setSocketOption sock ReuseAddr 1
bindSocket sock (SockAddrInet port iNADDR_ANY)
bind sock (SockAddrInet port iNADDR_ANY)
listen sock maxListenQueue
return sock
)
Expand All @@ -208,7 +208,7 @@ listenOn (PortNumber port) = do
(sClose)
(\sock -> do
setSocketOption sock ReuseAddr 1
bindSocket sock (SockAddrInet port iNADDR_ANY)
bind sock (SockAddrInet port iNADDR_ANY)
listen sock maxListenQueue
return sock
)
Expand All @@ -221,7 +221,7 @@ listenOn (UnixSocket path) =
(sClose)
(\sock -> do
setSocketOption sock ReuseAddr 1
bindSocket sock (SockAddrUnix path)
bind sock (SockAddrUnix path)
listen sock maxListenQueue
return sock
)
Expand All @@ -248,7 +248,7 @@ listen' serv = do
(sClose)
(\sock -> do
setSocketOption sock ReuseAddr 1
bindSocket sock (addrAddress addr)
bind sock (addrAddress addr)
listen sock maxListenQueue
return sock
)
Expand Down
16 changes: 15 additions & 1 deletion Network/Socket.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ socket family stype protocol = do
E.catch (setSocketOption sock IPv6Only 0) $ (\(_ :: E.IOException) -> return ())
# else
when (family == AF_INET6 && (stype == Stream || stype == Datagram)) $
setSocketOption sock IPv6Only 0 `onException` sClose sock
setSocketOption sock IPv6Only 0 `onException` close sock
# endif
#endif
return sock
Expand Down Expand Up @@ -1599,32 +1599,46 @@ foreign import CALLCONV unsafe "getpeereid"
-- These aliases are deprecated and should not be used in new code.
-- They will be removed in some future version of the package.

{-# DEPRECATED bindSocket "use 'bind'" #-}

-- | Deprecated alias for 'bind'.
bindSocket :: Socket -- Unconnected Socket
-> SockAddr -- Address to Bind to
-> IO ()
bindSocket = bind

{-# DEPRECATED sClose "use 'close'" #-}

-- | Deprecated alias for 'close'.
sClose :: Socket -> IO ()
sClose = close

{-# DEPRECATED sIsConnected "use 'isConnected'" #-}

-- | Deprecated alias for 'isConnected'.
sIsConnected :: Socket -> IO Bool
sIsConnected = isConnected

{-# DEPRECATED sIsBound "use 'isBound'" #-}

-- | Deprecated alias for 'isBound'.
sIsBound :: Socket -> IO Bool
sIsBound = isBound

{-# DEPRECATED sIsListening "use 'isListening'" #-}

-- | Deprecated alias for 'isListening'.
sIsListening :: Socket -> IO Bool
sIsListening = isListening

{-# DEPRECATED sIsReadable "use 'isReadable'" #-}

-- | Deprecated alias for 'isReadable'.
sIsReadable :: Socket -> IO Bool
sIsReadable = isReadable

{-# DEPRECATED sIsWritable "use 'isWritable'" #-}

-- | Deprecated alias for 'isWritable'.
sIsWritable :: Socket -> IO Bool
sIsWritable = isWritable
8 changes: 4 additions & 4 deletions Network/Socket/ByteString.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ withIOVec cs f =
-- > Nothing (Just "3000")
-- > let serveraddr = head addrinfos
-- > sock <- socket (addrFamily serveraddr) Stream defaultProtocol
-- > bindSocket sock (addrAddress serveraddr)
-- > bind sock (addrAddress serveraddr)
-- > listen sock 1
-- > (conn, _) <- accept sock
-- > talk conn
-- > sClose conn
-- > sClose sock
-- > close conn
-- > close sock
-- >
-- > where
-- > talk :: Socket -> IO ()
Expand All @@ -314,6 +314,6 @@ withIOVec cs f =
-- > connect sock (addrAddress serveraddr)
-- > sendAll sock $ C.pack "Hello, world!"
-- > msg <- recv sock 1024
-- > sClose sock
-- > close sock
-- > putStr "Received "
-- > C.putStrLn msg
2 changes: 1 addition & 1 deletion examples/EchoClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ main = withSocketsDo $
connect sock (addrAddress serveraddr)
sendAll sock $ C.pack "Hello, world!"
msg <- recv sock 1024
sClose sock
close sock
putStr "Received "
C.putStrLn msg
6 changes: 3 additions & 3 deletions examples/EchoServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ main = withSocketsDo $
Nothing (Just "3000")
let serveraddr = head addrinfos
sock <- socket (addrFamily serveraddr) Stream defaultProtocol
bindSocket sock (addrAddress serveraddr)
bind sock (addrAddress serveraddr)
listen sock 1
(conn, _) <- accept sock
talk conn
sClose conn
sClose sock
close conn
close sock

where
talk :: Socket -> IO ()
Expand Down
20 changes: 10 additions & 10 deletions tests/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ testUserTimeout = do
getSocketOption sock UserTimeout >>= (@=?) 1000
setSocketOption sock UserTimeout 2000
getSocketOption sock UserTimeout >>= (@=?) 2000
sClose sock
close sock

{-
testGetPeerCred:: Assertion
Expand All @@ -153,14 +153,14 @@ testGetPeerCred =
serverSetup = do
sock <- socket AF_UNIX Stream defaultProtocol
bindSocket sock $ SockAddrUnix addr
bind sock $ SockAddrUnix addr
listen sock 1
return sock
server sock = do
(clientSock, _) <- accept sock
_ <- serverAct clientSock
sClose clientSock
close clientSock
addr = "/tmp/testAddr1"
clientAct sock = withSocketsDo $ do
Expand All @@ -183,14 +183,14 @@ testGetPeerEid =
serverSetup = do
sock <- socket AF_UNIX Stream defaultProtocol
bindSocket sock $ SockAddrUnix addr
bind sock $ SockAddrUnix addr
listen sock 1
return sock
server sock = do
(clientSock, _) <- accept sock
_ <- serverAct clientSock
sClose clientSock
close clientSock
addr = "/tmp/testAddr2"
clientAct sock = withSocketsDo $ do
Expand Down Expand Up @@ -294,7 +294,7 @@ tcpTest clientAct serverAct = do
sock <- socket AF_INET Stream defaultProtocol
setSocketOption sock ReuseAddr 1
addr <- inet_addr serverAddr
bindSocket sock (SockAddrInet aNY_PORT addr)
bind sock (SockAddrInet aNY_PORT addr)
listen sock 1
serverPort <- socketPort sock
putMVar portVar serverPort
Expand All @@ -303,7 +303,7 @@ tcpTest clientAct serverAct = do
server sock = do
(clientSock, _) <- accept sock
_ <- serverAct clientSock
sClose clientSock
close clientSock

-- | Create an unconnected 'Socket' for sending UDP and receiving
-- datagrams and then run 'clientAct' and 'serverAct'.
Expand All @@ -322,7 +322,7 @@ udpTest clientAct serverAct = do
sock <- socket AF_INET Datagram defaultProtocol
setSocketOption sock ReuseAddr 1
addr <- inet_addr serverAddr
bindSocket sock (SockAddrInet aNY_PORT addr)
bind sock (SockAddrInet aNY_PORT addr)
serverPort <- socketPort sock
putMVar portVar serverPort
return sock
Expand All @@ -338,7 +338,7 @@ test clientSetup clientAct serverSetup serverAct = do
client tid barrier
where
server barrier = do
E.bracket serverSetup sClose $ \sock -> do
E.bracket serverSetup close $ \sock -> do
serverReady
_ <- serverAct sock
putMVar barrier ()
Expand All @@ -349,7 +349,7 @@ test clientSetup clientAct serverSetup serverAct = do
client tid barrier = do
takeMVar barrier
-- Transfer exceptions to the main thread.
bracketWithReraise tid clientSetup sClose $ \res -> do
bracketWithReraise tid clientSetup close $ \res -> do
_ <- clientAct res
takeMVar barrier

Expand Down

0 comments on commit 77da9bc

Please sign in to comment.