Skip to content

Commit 84ed440

Browse files
committed
TASK-032-001: Extend ConnectionPolicy with multi-connection config
Add MaxHttp2ConnectionsPerHost (default 2), MaxHttp3ConnectionsPerHost (default 2), and SlotQueueSize (default 1, max 1) to ConnectionPolicy. HTTP/1.0 and HTTP/1.1 remain hard-coded to 1 connection per host. SlotQueueSize throws ArgumentOutOfRangeException if set outside [1..1] to preserve the Offering-based capacity signal for multi-slot routing.
1 parent 3d21cea commit 84ed440

3 files changed

Lines changed: 54 additions & 8 deletions

File tree

.maggus/features/feature_032.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ Two architectural improvements to TurboHttp's stream pipeline:
4141
**Parallel:** yes — can run alongside TASK-032-004
4242

4343
**Acceptance Criteria:**
44-
- [ ] `ConnectionPolicy` gains `MaxHttp2ConnectionsPerHost` (default `2`)
45-
- [ ] `ConnectionPolicy` gains `MaxHttp3ConnectionsPerHost` (default `2`)
46-
- [ ] `ConnectionPolicy` gains `SlotQueueSize` (default `1`) — per-slot Source.Queue buffer size; must not exceed `1` to ensure `Offering=true` propagates after at most one queued item
47-
- [ ] HTTP/1.0 and HTTP/1.1 are hard-coded to 1 connection per host (not configurable via these properties)
48-
- [ ] XML doc comments explain each property
49-
- [ ] Existing `ConnectionPolicy` tests still pass
50-
- [ ] Build succeeds with zero errors
44+
- [x] `ConnectionPolicy` gains `MaxHttp2ConnectionsPerHost` (default `2`)
45+
- [x] `ConnectionPolicy` gains `MaxHttp3ConnectionsPerHost` (default `2`)
46+
- [x] `ConnectionPolicy` gains `SlotQueueSize` (default `1`) — per-slot Source.Queue buffer size; must not exceed `1` to ensure `Offering=true` propagates after at most one queued item
47+
- [x] HTTP/1.0 and HTTP/1.1 are hard-coded to 1 connection per host (not configurable via these properties)
48+
- [x] XML doc comments explain each property
49+
- [x] Existing `ConnectionPolicy` tests still pass
50+
- [x] Build succeeds with zero errors
5151

5252
---
5353

src/TurboHttp/Protocol/RFC9112/ConnectionPolicy.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,50 @@ public sealed record ConnectionPolicy
2222
/// Default is true.
2323
/// </summary>
2424
public bool AllowHttp2Multiplexing { get; init; } = true;
25+
26+
/// <summary>
27+
/// Maximum number of parallel HTTP/2 connections opened per host.
28+
/// When a connection reaches its <c>MaxConcurrentStreams</c> limit, the pipeline
29+
/// backpressures and a new connection is opened — up to this limit.
30+
/// HTTP/1.0 and HTTP/1.1 always use exactly one connection per host regardless of this value.
31+
/// Default is 2.
32+
/// </summary>
33+
public int MaxHttp2ConnectionsPerHost { get; init; } = 2;
34+
35+
/// <summary>
36+
/// Maximum number of parallel HTTP/3 connections opened per host.
37+
/// When a connection reaches its stream limit, the pipeline backpressures
38+
/// and a new connection is opened — up to this limit.
39+
/// HTTP/1.0 and HTTP/1.1 always use exactly one connection per host regardless of this value.
40+
/// Default is 2.
41+
/// </summary>
42+
public int MaxHttp3ConnectionsPerHost { get; init; } = 2;
43+
44+
private int _slotQueueSize = 1;
45+
46+
/// <summary>
47+
/// Per-slot <c>Source.Queue</c> buffer size used by the multi-connection routing stage.
48+
/// Must be exactly <c>1</c>: a value greater than 1 would allow multiple requests to
49+
/// accumulate on a saturated connection slot without triggering the <c>Offering=true</c>
50+
/// backpressure signal, defeating the purpose of multi-connection routing.
51+
/// Default is 1.
52+
/// </summary>
53+
/// <exception cref="ArgumentOutOfRangeException">
54+
/// Thrown when the value is less than 1 or greater than 1.
55+
/// </exception>
56+
public int SlotQueueSize
57+
{
58+
get => _slotQueueSize;
59+
init
60+
{
61+
if (value < 1 || value > 1)
62+
{
63+
throw new ArgumentOutOfRangeException(
64+
nameof(SlotQueueSize),
65+
value,
66+
"SlotQueueSize must be exactly 1. A value greater than 1 defeats the Offering-based capacity signal used for multi-connection routing.");
67+
}
68+
_slotQueueSize = value;
69+
}
70+
}
2571
}

src/TurboHttp/Transport/IClientProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public ValueTask DisposeAsync()
9292
return ValueTask.CompletedTask;
9393
}
9494

95-
private Socket CreateSocket()
95+
private static Socket CreateSocket()
9696
{
9797
// On Linux, new Socket(AddressFamily.Unspecified, ...) throws SocketException
9898
// "Protocol not supported" because AF_UNSPEC + IPPROTO_TCP is invalid.

0 commit comments

Comments
 (0)