Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Sources/SwiftNetwork/Protocols/ManyToManyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,15 @@ extension ManyToManyApplicationStreamProtocol where Flow: AutomaticUpperStreamPr
guard let flow = self.flow(for: flowID) else { throw NetworkError.posix(EINVAL) }
flow.serviceUpperReceiveQueue()
}
// Enqueue and delivery the stream data all in one shot
public func deliverInboundStreamData(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add the same for enqueueInboundDatagrams/deliverEnqueuedInboundDatagrams to keep them parallel

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that makes a lot of sense. Addressed in 62be3ec

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Can you also adopt it where we call enqueueInboundDatagrams?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good idea. Looks like I missed a place in HeterogeneousManyToManyProtocolHandler so I added it there too and adopted it. b62090c

flow flowID: MultiplexedFlowIdentifier,
streamData: consuming FrameArray
) throws(NetworkError) {
guard var flow = self.flow(for: flowID) else { throw NetworkError.posix(EINVAL) }
try flow.addToUpperReceiveQueue(streamData)
flow.serviceUpperReceiveQueue()
}
}

@_spi(ProtocolProvider)
Expand Down Expand Up @@ -1581,6 +1590,16 @@ extension ManyToManyApplicationDatagramProtocol where Flow: AutomaticUpperDatagr
guard let flow = self.flow(for: flowID) else { throw NetworkError.posix(EINVAL) }
flow.serviceUpperReceiveQueue()
}

// Enqueue and delivery the datagrams all in one shot
public func deliverInboundDatagrams(
flow flowID: MultiplexedFlowIdentifier,
datagrams: consuming FrameArray
) throws(NetworkError) {
guard var flow = self.flow(for: flowID) else { throw NetworkError.posix(EINVAL) }
try flow.addToUpperReceiveQueue(datagrams)
flow.serviceUpperReceiveQueue()
}
}

@available(Network 0.1.0, *)
Expand Down Expand Up @@ -1613,6 +1632,16 @@ extension HeterogeneousManyToManyProtocolHandler where SecondaryFlow: AutomaticU
guard let flow = self.secondaryFlow(for: flowID) else { throw NetworkError.posix(EINVAL) }
flow.serviceUpperReceiveQueue()
}

// Enqueue and delivery the datagrams all in one shot
public func deliverInboundDatagrams(
flow flowID: MultiplexedFlowIdentifier,
datagrams: consuming FrameArray
) throws(NetworkError) {
guard var flow = self.secondaryFlow(for: flowID) else { throw NetworkError.posix(EINVAL) }
try flow.addToUpperReceiveQueue(datagrams)
flow.serviceUpperReceiveQueue()
}
}

@_spi(ProtocolProvider)
Expand Down
9 changes: 3 additions & 6 deletions Sources/SwiftNetwork/QUIC/QUICConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2374,8 +2374,7 @@ public final class QUICConnection: ManyToManyApplicationStreamProtocol,
continue
}

try? enqueueInboundStreamData(flow: flowID, streamData: frameArray)
try? deliverEnqueuedInboundStreamData(flow: flowID)
try? deliverInboundStreamData(flow: flowID, streamData: frameArray)

// When the stream is already in `resetReceived` state,
// it should be closed when we receive STOP_SENDING, so we
Expand Down Expand Up @@ -4317,8 +4316,7 @@ public final class QUICConnection: ManyToManyApplicationStreamProtocol,
}
if let frameArray = stream.dequeueReassembledData(connection: self) {
do {
try enqueueInboundStreamData(flow: flowID, streamData: frameArray)
try deliverEnqueuedInboundStreamData(flow: flowID)
try deliverInboundStreamData(flow: flowID, streamData: frameArray)
sendFrames()
} catch {
log.error("Error sending frames on stream close: \(error)")
Expand Down Expand Up @@ -5564,8 +5562,7 @@ extension QUICConnection {

var frame = frame.frame
frame.metadataComplete = true
try? enqueueInboundDatagrams(flow: matchingFlowIdentifier, datagrams: .init(frame: frame))
try? deliverEnqueuedInboundDatagrams(flow: matchingFlowIdentifier)
try? deliverInboundDatagrams(flow: matchingFlowIdentifier, datagrams: .init(frame: frame))
return true
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftNetwork/QUIC/QUICStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ struct StreamListMembership: OptionSet {
// Also note that a flow identifier can exist in multiple lists at one time.
@available(Network 0.1.0, *)
struct QUICStreamList: ~Copyable {
private var list: [MultiplexedFlowIdentifier] = []
private var list = Deque<MultiplexedFlowIdentifier>()
private let name: StaticString
private let listType: StreamListMembership

Expand Down
3 changes: 1 addition & 2 deletions Tests/SwiftNetworkTests/TestMultiplexingProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ final class TestMultiplexingProtocol: ManyToManyApplicationDatagramProtocol, Man
return
}
accessReceivedDatagrams(path: path) { frames in
try? enqueueInboundDatagrams(flow: flow, datagrams: frames.drainArray())
try? deliverEnqueuedInboundDatagrams(flow: flow)
try? deliverInboundDatagrams(flow: flow, datagrams: frames.drainArray())
}
}

Expand Down
Loading