Skip to content

Commit 113d308

Browse files
authored
Merge pull request #5182 from IntersectMBO/coot/network-mux-haddocks
Improved network-mux haddocks
2 parents 90b2c4b + 853011b commit 113d308

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

network-mux/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### Non-breaking changes
88

9+
* Exposed `MakeBearerCb` to expose its haddocks.
10+
911
## 0.9.0.0 -- 2025-06-28
1012

1113
### Breaking changes

network-mux/src/Network/Mux/Bearer.hs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
module Network.Mux.Bearer
1010
( Bearer (..)
11+
, MakeBearerCb
1112
, MakeBearer (..)
1213
, BearerTrace (..)
1314
, makeSocketBearer
@@ -36,35 +37,51 @@ import Network.Mux.Bearer.Pipe
3637
import Network.Mux.Bearer.Queues
3738
import Network.Mux.Bearer.Socket
3839
import Network.Mux.Trace
39-
import Network.Mux.Types hiding (sduSize)
40+
import Network.Mux.Types hiding (egressInterval)
4041
#if defined(mingw32_HOST_OS)
4142
import Network.Mux.Bearer.NamedPipe
4243
#endif
4344

44-
newtype MakeBearer m fd = MakeBearer {
45-
getBearer
46-
:: DiffTime
47-
-- timeout for reading an SDU segment, if negative no
48-
-- timeout is applied.
49-
-> fd
50-
-- file descriptor
51-
-> Maybe (ReadBuffer m)
52-
-- Optional Readbuffer
53-
-> m (Bearer m)
54-
}
45+
-- | Callback which constructs a bearer, see `MakeBearer`.
46+
--
47+
type MakeBearerCb m fd =
48+
DiffTime
49+
-- ^ Timeout for reading an SDU segment, if negative no timeout is
50+
-- applied. The timeout is not applied to the first SDU segment received
51+
-- from the network, which allows a mini-protocol to have longer
52+
-- timeouts than the one given here (or even have no timeout).
53+
--
54+
-- NOTE: a mini-protocol timeouts (which are not responsibility of
55+
-- `network-mux` library) might include the time waiting for the response,
56+
-- receiving all bytes, and the time required to parse the message.
57+
-> fd
58+
-- ^ file descriptor
59+
-> Maybe (ReadBuffer m)
60+
-- ^ optional `ReadBuffer`
61+
-> m (Bearer m)
62+
63+
64+
-- | Construct a bearer using a `MakeBearerCb`.
65+
--
66+
newtype MakeBearer m fd = MakeBearer { getBearer :: MakeBearerCb m fd }
5567

5668
pureBearer :: Applicative m
5769
=> (DiffTime -> fd -> Maybe (ReadBuffer m) -> Bearer m)
5870
-> DiffTime -> fd -> Maybe (ReadBuffer m) -> m (Bearer m)
5971
pureBearer f = \sduTimeout rb fd -> pure (f sduTimeout rb fd)
6072

6173

74+
-- | `Socket` Bearer without egress interval.
75+
--
6276
makeSocketBearer :: MakeBearer IO Socket
6377
makeSocketBearer = makeSocketBearer' 0
6478

65-
makeSocketBearer' :: DiffTime -> MakeBearer IO Socket
66-
makeSocketBearer' pt = MakeBearer $ \sduTimeout fd rb ->
67-
return $ socketAsBearer size batch rb sduTimeout pt fd
79+
makeSocketBearer'
80+
:: DiffTime
81+
-- ^ egress interval
82+
-> MakeBearer IO Socket
83+
makeSocketBearer' egressInterval = MakeBearer $ pureBearer $ \sduTimeout fd rb ->
84+
socketAsBearer size batch rb sduTimeout egressInterval fd
6885
where
6986
size = SDUSize 12_288
7087
batch = 131_072

network-mux/src/Network/Mux/Bearer/Socket.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ socketAsBearer
5555
-> DiffTime -- ^ egress poll interval
5656
-> Socket.Socket
5757
-> Bearer IO
58-
socketAsBearer sduSize batchSize readBuffer_m sduTimeout pollInterval sd =
58+
socketAsBearer sduSize batchSize readBuffer_m sduTimeout egressInterval sd =
5959
Mx.Bearer {
6060
Mx.read = readSocket,
6161
Mx.write = writeSocket,
6262
Mx.writeMany = writeSocketMany,
6363
Mx.sduSize = sduSize,
6464
Mx.batchSize = batchSize,
6565
Mx.name = "socket-bearer",
66-
Mx.egressInterval = pollInterval
66+
Mx.egressInterval
6767
}
6868
where
6969
readSocket :: Tracer IO BearerTrace -> Mx.TimeoutFn IO -> IO (Mx.SDU, Time)

0 commit comments

Comments
 (0)