File tree 1 file changed +8
-2
lines changed
network-mux/src/Network/Mux
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ module Network.Mux.Ingress
12
12
) where
13
13
14
14
import Data.Array
15
- import Data.ByteString.Builder.Internal (lazyByteStringThreshold )
15
+ import Data.ByteString.Builder.Internal (lazyByteStringInsert , lazyByteStringThreshold )
16
16
import Data.ByteString.Lazy qualified as BL
17
17
import Data.List (nub )
18
18
@@ -119,7 +119,13 @@ demuxer ptcls bearer =
119
119
(len, buf) <- readTVar q
120
120
let len' = len + BL. length (msBlob sdu)
121
121
if len' <= fromIntegral qMax
122
- then writeTVar q $ (len', buf <> (lazyByteStringThreshold 64 $ msBlob sdu))
122
+ then do
123
+ let buf' = if len == 0
124
+ then -- Don't copy the payload if the queue was empty
125
+ lazyByteStringInsert $ msBlob sdu
126
+ else -- Copy payloads smaller than 128 bytes
127
+ buf <> (lazyByteStringThreshold 128 $ msBlob sdu)
128
+ writeTVar q $ (len', buf')
123
129
else throwSTM $ IngressQueueOverRun (msNum sdu) (msDir sdu)
124
130
125
131
lookupMiniProtocol :: MiniProtocolDispatch m
You can’t perform that action at this time.
0 commit comments