|
8 | 8 |
|
9 | 9 | module Network.Mux.Bearer |
10 | 10 | ( Bearer (..) |
| 11 | + , MakeBearerCb |
11 | 12 | , MakeBearer (..) |
12 | 13 | , BearerTrace (..) |
13 | 14 | , makeSocketBearer |
@@ -36,35 +37,51 @@ import Network.Mux.Bearer.Pipe |
36 | 37 | import Network.Mux.Bearer.Queues |
37 | 38 | import Network.Mux.Bearer.Socket |
38 | 39 | import Network.Mux.Trace |
39 | | -import Network.Mux.Types hiding (sduSize) |
| 40 | +import Network.Mux.Types hiding (egressInterval) |
40 | 41 | #if defined(mingw32_HOST_OS) |
41 | 42 | import Network.Mux.Bearer.NamedPipe |
42 | 43 | #endif |
43 | 44 |
|
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 } |
55 | 67 |
|
56 | 68 | pureBearer :: Applicative m |
57 | 69 | => (DiffTime -> fd -> Maybe (ReadBuffer m) -> Bearer m) |
58 | 70 | -> DiffTime -> fd -> Maybe (ReadBuffer m) -> m (Bearer m) |
59 | 71 | pureBearer f = \sduTimeout rb fd -> pure (f sduTimeout rb fd) |
60 | 72 |
|
61 | 73 |
|
| 74 | +-- | `Socket` Bearer without egress interval. |
| 75 | +-- |
62 | 76 | makeSocketBearer :: MakeBearer IO Socket |
63 | 77 | makeSocketBearer = makeSocketBearer' 0 |
64 | 78 |
|
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 |
68 | 85 | where |
69 | 86 | size = SDUSize 12_288 |
70 | 87 | batch = 131_072 |
|
0 commit comments