on master help sign in
rename listen to accept
3888780Harendra Kumar
src/Streamly/Internal/Network/Inet/TCP.hs+2−2
@@ -103,7 +103,7 @@ import Prelude hiding (read)
103import Streamly (MonadAsync)
103import Streamly (MonadAsync)
104import Streamly.Internal.Data.Fold.Types (Fold(..))
104import Streamly.Internal.Data.Fold.Types (Fold(..))
105import Streamly.Internal.Data.Unfold.Types (Unfold(..))
105import Streamly.Internal.Data.Unfold.Types (Unfold(..))
106−import Streamly.Internal.Network.Socket (SockSpec(..), listen, connections)
106+import Streamly.Internal.Network.Socket (SockSpec(..), accept, connections)
107import Streamly.Streams.Serial (SerialT)
107import Streamly.Streams.Serial (SerialT)
108import Streamly.Internal.Memory.Array.Types (Array(..), defaultChunkSize, writeNUnsafe)
108import Streamly.Internal.Memory.Array.Types (Array(..), defaultChunkSize, writeNUnsafe)
109import Streamly.Streams.StreamK.Type (IsStream)
109import Streamly.Streams.StreamK.Type (IsStream)
@@ -130,7 +130,7 @@ import qualified Streamly.Internal.Network.Socket as ISK
130acceptOnAddr
130acceptOnAddr
131 :: MonadIO m
131 :: MonadIO m
132 => Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Socket
132 => Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Socket
133−acceptOnAddr = UF.lmap f listen
133+acceptOnAddr = UF.lmap f accept
134 where
134 where
135 f (addr, port) =
135 f (addr, port) =
136 (maxListenQueue
136 (maxListenQueue
src/Streamly/Internal/Network/Socket.hs+16−17
@@ -23,8 +23,8 @@ module Streamly.Internal.Network.Socket
23 , useSocketM
23 , useSocketM
24 , useSocket
24 , useSocket
25
25
26− -- * Listen for incoming connections
26+ -- * Accept connections
27− , listen
27+ , accept
28 , connections
28 , connections
29
29
30 -- * Read from connection
30 -- * Read from connection
@@ -73,10 +73,9 @@ import Foreign.Storable (Storable(..))
73import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
73import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
74import Network.Socket (sendBuf, recvBuf)
74import Network.Socket (sendBuf, recvBuf)
75import Network.Socket
75import Network.Socket
76− (Socket, PortNumber, SocketOption(..), Family(..), SockAddr(..),
76+ (Socket, SocketOption(..), Family(..), SockAddr(..),
77− ProtocolNumber,
78− withSocketsDo, SocketType(..), socket, accept, bind,
77+ ProtocolNumber, withSocketsDo, SocketType(..), socket, bind,
79− defaultProtocol, setSocketOption, maxListenQueue, tupleToHostAddress)
78+ setSocketOption)
80#if MIN_VERSION_network(3,1,0)
79#if MIN_VERSION_network(3,1,0)
81import Network.Socket (withFdSocket)
80import Network.Socket (withFdSocket)
82#else
81#else
@@ -124,7 +123,7 @@ useSocket :: (IsStream t, MonadCatch m, MonadIO m)
124useSocket sk f = S.finally (liftIO $ Net.close sk) (f sk)
123useSocket sk f = S.finally (liftIO $ Net.close sk) (f sk)
125
124
126-------------------------------------------------------------------------------
125-------------------------------------------------------------------------------
127−-- Listen (Unfolds)
126+-- Accept (Unfolds)
128-------------------------------------------------------------------------------
127-------------------------------------------------------------------------------
129
128
130-- XXX Protocol specific socket options should be separated from socket level
129-- XXX Protocol specific socket options should be separated from socket level
@@ -158,20 +157,20 @@ listenTuples = Unfold step inject
158 return listener
157 return listener
159
158
160 step listener = do
159 step listener = do
161− r <- liftIO $ accept listener
160+ r <- liftIO $ Net.accept listener
162 -- XXX error handling
161 -- XXX error handling
163 return $ D.Yield r listener
162 return $ D.Yield r listener
164
163
165-- | Unfold a three tuple @(listenQLen, spec, addr)@ into a stream of connected
164-- | Unfold a three tuple @(listenQLen, spec, addr)@ into a stream of connected
165+-- protocol sockets corresponding to incoming connections. @listenQLen@ is the
166−-- protocol sockets. @listenQLen@ is the maximum number of pending connections
166+-- maximum number of pending connections in the backlog. @spec@ is the socket
167−-- in the backlog. @spec@ is the socket protocol and options specification and
167+-- protocol and options specification and @addr@ is the protocol address where
168−-- @addr@ is the protocol address where the server listens for incoming
168+-- the server listens for incoming connections.
169−-- connections.
170--
169--
171-- @since 0.7.0
170-- @since 0.7.0
172−{-# INLINE listen #-}
171+{-# INLINE accept #-}
173−listen :: MonadIO m => Unfold m (Int, SockSpec, SockAddr) Socket
172+accept :: MonadIO m => Unfold m (Int, SockSpec, SockAddr) Socket
174−listen = UF.map fst listenTuples
173+accept = UF.map fst listenTuples
175
174
176-------------------------------------------------------------------------------
175-------------------------------------------------------------------------------
177-- Listen (Streams)
176-- Listen (Streams)
@@ -184,12 +183,12 @@ recvConnectionTuplesWith tcpListenQ spec addr = S.unfoldrM step Nothing
184 where
183 where
185 step Nothing = do
184 step Nothing = do
186 listener <- liftIO $ initListener tcpListenQ spec addr
185 listener <- liftIO $ initListener tcpListenQ spec addr
187− r <- liftIO $ accept listener
186+ r <- liftIO $ Net.accept listener
188 -- XXX error handling
187 -- XXX error handling
189 return $ Just (r, Just listener)
188 return $ Just (r, Just listener)
190
189
191 step (Just listener) = do
190 step (Just listener) = do
192− r <- liftIO $ accept listener
191+ r <- liftIO $ Net.accept listener
193 -- XXX error handling
192 -- XXX error handling
194 return $ Just (r, Just listener)
193 return $ Just (r, Just listener)
195
194
src/Streamly/Network/Socket.hs+1−1
@@ -35,7 +35,7 @@ module Streamly.Network.Socket
35 SockSpec(..)
35 SockSpec(..)
36
36
37 -- * Accept Connections
37 -- * Accept Connections
38− , listen
38+ , accept
39
39
40 -- * Read from connection
40 -- * Read from connection
41 , read
41 , read