Skip to content

Commit bc14f3b

Browse files
committed
subscription: configure sockets
Use `Ouroboros.Network.Socket.configureSocket` to configure outbound sockets.
1 parent 9a4e67f commit bc14f3b

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

ouroboros-network-framework/src/Ouroboros/Network/Subscription/Client.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ clientSubscriptionWorker snocket
5858
nmsConnectionTable
5959
nmsPeerStates
6060
snocket
61+
mempty
6162
WorkerCallbacks
6263
{ wcSocketStateChangeTx = socketStateChangeTx
6364
, wcCompleteApplicationTx = completeApplicationTx cspErrorPolicies

ouroboros-network-framework/src/Ouroboros/Network/Subscription/Ip.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ subscriptionWorker snocket
203203
nmsConnectionTable
204204
nmsPeerStates
205205
snocket
206+
((. Just) <$> configureSocket)
206207
WorkerCallbacks
207208
{ wcSocketStateChangeTx = socketStateChangeTx
208209
, wcCompleteApplicationTx = completeApplicationTx errorPolicies

ouroboros-network-framework/src/Ouroboros/Network/Subscription/Worker.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ safeConnect :: ( MonadThrow m
152152
, MonadMask m
153153
)
154154
=> Snocket m sock addr
155+
-> (sock -> addr -> m ()) -- ^ configure the socket
155156
-> addr
156157
-- ^ remote addr
157158
-> addr
@@ -167,7 +168,7 @@ safeConnect :: ( MonadThrow m
167168
-- masked; it receives: unmask function, allocated socket and
168169
-- connection error.
169170
-> m t
170-
safeConnect sn remoteAddr localAddr malloc mclean k =
171+
safeConnect sn configureSock remoteAddr localAddr malloc mclean k =
171172
bracket
172173
(do sock <- Snocket.open sn (Snocket.addrFamily sn remoteAddr)
173174
malloc
@@ -176,6 +177,7 @@ safeConnect sn remoteAddr localAddr malloc mclean k =
176177
(\sock -> Snocket.close sn sock >> mclean)
177178
(\sock -> mask $ \unmask -> do
178179
res <- try $ do
180+
configureSock sock localAddr
179181
let doBind = case Snocket.addrFamily sn localAddr of
180182
Snocket.SocketFamily fam -> fam /= AF_UNIX
181183
_ -> False -- Bind is a nop for Named Pipes anyway
@@ -224,6 +226,7 @@ subscriptionLoop
224226
-> ThreadsVar m
225227

226228
-> Snocket m sock addr
229+
-> (sock -> addr -> m ())
227230

228231
-> WorkerCallbacks m s addr a x
229232
-> WorkerParams m localAddrs addr
@@ -232,7 +235,7 @@ subscriptionLoop
232235
-- ^ application
233236
-> m Void
234237
subscriptionLoop
235-
tr tbl resQ sVar threadsVar snocket
238+
tr tbl resQ sVar threadsVar snocket configureSock
236239
WorkerCallbacks { wcSocketStateChangeTx = socketStateChangeTx
237240
, wcCompleteApplicationTx = completeApplicationTx
238241
}
@@ -344,6 +347,7 @@ subscriptionLoop
344347
-- this bracket.
345348
safeConnect
346349
snocket
350+
configureSock
347351
remoteAddr
348352
localAddr
349353
(do
@@ -558,18 +562,19 @@ worker
558562
-> StateVar IO s
559563

560564
-> Snocket IO sock addr
565+
-> (sock -> addr -> IO ())
561566

562567
-> WorkerCallbacks IO s addr a x
563568
-> WorkerParams IO localAddrs addr
564569

565570
-> (sock -> IO a)
566571
-- ^ application
567572
-> IO x
568-
worker tr errTrace tbl sVar snocket workerCallbacks@WorkerCallbacks {wcCompleteApplicationTx, wcMainTx } workerParams k = do
573+
worker tr errTrace tbl sVar snocket configureSock workerCallbacks@WorkerCallbacks {wcCompleteApplicationTx, wcMainTx } workerParams k = do
569574
resQ <- newResultQ
570575
threadsVar <- newTVarIO Set.empty
571576
withAsync
572-
(subscriptionLoop tr tbl resQ sVar threadsVar snocket
577+
(subscriptionLoop tr tbl resQ sVar threadsVar snocket configureSock
573578
workerCallbacks workerParams k) $ \_ ->
574579
mainLoop errTrace resQ threadsVar sVar wcCompleteApplicationTx wcMainTx
575580
`finally` killThreads threadsVar

ouroboros-network-framework/test/Test/Ouroboros/Network/Subscription.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Control.Monad.Class.MonadTime
2222
import Control.Monad.Class.MonadTimer
2323
import Control.Monad.IOSim (runSimStrictShutdown)
2424
import Control.Tracer
25+
import qualified Data.ByteString.Char8 as BSC
2526
import qualified Data.ByteString.Lazy as BL
2627
import Data.Functor (void)
2728
import qualified Data.IP as IP
@@ -120,8 +121,8 @@ tests =
120121
-- the above tests takes about 10 minutes to run due to delays in
121122
-- realtime.
122123
, testProperty "Resolve Subscribe (IO)" prop_sub_io
123-
, testProperty "Send Recive with Dns worker (IO)" prop_send_recv
124-
, testProperty "Send Recieve with IP worker, Initiator and responder (IO)"
124+
, testProperty "Send Receive with Dns worker (IO)" prop_send_recv
125+
, testProperty "Send Receive with IP worker, Initiator and responder (IO)"
125126
prop_send_recv_init_and_rsp
126127
-- , testProperty "subscription demo" _demo
127128
]
@@ -917,7 +918,7 @@ instance (Show a) => Show (WithThreadAndTime a) where
917918
printf "%s: %s: %s" (show wtatOccuredAt) (show wtatWithinThread) (show wtatEvent)
918919

919920
_verboseTracer :: Show a => Tracer IO a
920-
_verboseTracer = threadAndTimeTracer $ showTracing stdoutTracer
921+
_verboseTracer = threadAndTimeTracer $ Tracer (BSC.putStrLn . BSC.pack . show)
921922

922923
threadAndTimeTracer :: Tracer IO (WithThreadAndTime a) -> Tracer IO a
923924
threadAndTimeTracer tr = Tracer $ \s -> do

ouroboros-network/test/Test/PeerState.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ prop_subscriptionWorker
359359
tbl
360360
peerStatesVar
361361
(mkSnocket sockType localAddr remoteAddr)
362+
mempty
362363
WorkerCallbacks {
363364
wcSocketStateChangeTx = \ss s -> do
364365
s' <- socketStateChangeTx ss s

0 commit comments

Comments
 (0)