@@ -24,11 +24,14 @@ module Streamly.Internal.Network.Inet.TCP
2424 -- * TCP Servers
2525 -- ** Unfolds
2626 acceptOnAddr
27+ , acceptOnAddrWith
2728 , acceptOnPort
29+ , acceptOnPortWith
2830 , acceptOnPortLocal
2931
3032 -- ** Streams
3133 , connectionsOnAddr
34+ , connectionsOnAddrWith
3235 , connectionsOnPort
3336 , connectionsOnLocalHost
3437
@@ -131,16 +134,12 @@ import qualified Streamly.Internal.Network.Socket as ISK
131134-- Accept (unfolds)
132135-------------------------------------------------------------------------------
133136
134−-- | Unfold a tuple @(ipAddr, port)@ into a stream of connected TCP sockets.
135−-- @ipAddr@ is the local IP address and @port@ is the local port on which
136−-- connections are accepted.
137−--
138−-- @since 0.7.0
139−{-# INLINE acceptOnAddr #-}
140−acceptOnAddr
137+{-# INLINE acceptOnAddrWith #-}
138+acceptOnAddrWith
141139 :: MonadIO m
142− => Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Socket
143−acceptOnAddr = UF.lmap f accept
140+ => [(SocketOption, Int)]
141+ -> Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Socket
142+acceptOnAddrWith opts = UF.lmap f accept
144143 where
145144 f (addr, port) =
146145 (maxListenQueue
@@ -148,11 +147,28 @@ acceptOnAddr = UF.lmap f accept
148147 { sockFamily = AF_INET
149148 , sockType = Stream
150149 , sockProto = defaultProtocol -- TCP
151− , sockOpts = [(NoDelay,1), (ReuseAddr,1)]
150+ , sockOpts = opts
152151 }
153152 , SockAddrInet port (tupleToHostAddress addr)
154153 )
155154
155+-- | Unfold a tuple @(ipAddr, port)@ into a stream of connected TCP sockets.
156+-- @ipAddr@ is the local IP address and @port@ is the local port on which
157+-- connections are accepted.
158+--
159+-- @since 0.7.0
160+{-# INLINE acceptOnAddr #-}
161+acceptOnAddr
162+ :: MonadIO m
163+ => Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Socket
164+acceptOnAddr = acceptOnAddrWith []
165+
166+{-# INLINE acceptOnPortWith #-}
167+acceptOnPortWith :: MonadIO m
168+ => [(SocketOption, Int)]
169+ -> Unfold m PortNumber Socket
170+acceptOnPortWith opts = UF.supplyFirst (acceptOnAddrWith opts) (0,0,0,0)
171+
156172-- | Like 'acceptOnAddr' but binds on the IPv4 address @0.0.0.0@ i.e. on all
157173-- IPv4 addresses/interfaces of the machine and listens for TCP connections on
158174-- the specified port.
@@ -179,6 +195,22 @@ acceptOnPortLocal = UF.supplyFirst acceptOnAddr (127,0,0,1)
179195-- Accept (streams)
180196-------------------------------------------------------------------------------
181197
198+{-# INLINE connectionsOnAddrWith #-}
199+connectionsOnAddrWith
200+ :: MonadAsync m
201+ => [(SocketOption, Int)]
202+ -> (Word8, Word8, Word8, Word8)
203+ -> PortNumber
204+ -> SerialT m Socket
205+connectionsOnAddrWith opts addr port =
206+ connections maxListenQueue SockSpec
207+ { sockFamily = AF_INET
208+ , sockType = Stream
209+ , sockProto = defaultProtocol
210+ , sockOpts = opts
211+ }
212+ (SockAddrInet port (tupleToHostAddress addr))
213+
182214-- | Like 'connections' but binds on the specified IPv4 address of the machine
183215-- and listens for TCP connections on the specified port.
184216--
@@ -189,14 +221,7 @@ connectionsOnAddr
189221 => (Word8, Word8, Word8, Word8)
190222 -> PortNumber
191223 -> SerialT m Socket
192−connectionsOnAddr addr port =
193− connections maxListenQueue SockSpec
194− { sockFamily = AF_INET
195− , sockType = Stream
196− , sockProto = defaultProtocol
197− , sockOpts = [(NoDelay,1), (ReuseAddr,1)]
198− }
199− (SockAddrInet port (tupleToHostAddress addr))
224+connectionsOnAddr = connectionsOnAddrWith []
200225
201226-- | Like 'connections' but binds on the IPv4 address @0.0.0.0@ i.e. on all
202227-- IPv4 addresses/interfaces of the machine and listens for TCP connections on