Skip to content
Merged
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
14 changes: 12 additions & 2 deletions Sources/SwiftNetwork/EndpointFlow/EndpointFlowExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,18 @@ extension EndpointFlow {

switch transport {
case .tcp(let options):
guard let reference = TCPProtocol().newProtocolInstance(context: context) else {
throw NetworkError.posix(EINVAL)
// In bridged (test-harness) mode drive a raw TCP instance directly;
// otherwise use a real kernel socket. The flow wiring is identical.
let reference: ProtocolInstanceReference
if case .custom(let linkOptions) = stack.link,
linkOptions.identifier == BridgeDatagramProtocol.identifier

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A little unusual to be using the BridgeDatagramProtocol for TCP

{
guard let bridged = TCPProtocol().newProtocolInstance(context: context) else {
throw NetworkError.posix(EINVAL)
}
reference = bridged
} else {
reference = SocketStreamProtocol.instance(context: context)
}
options.setProtocolInstance(reference)
let linkage = OutboundStreamLinkage(reference: reference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,13 @@ class EndpointFlowProtocol<LinkageType: InboundDataLinkage>: ProtocolInstanceCon

func handleInboundDataAvailableEvent(_ from: ProtocolInstanceReference) {
log.debug("Received inbound data available event")
// Clear the slot before invoking: the completion may synchronously
// re-arm the waiter (when receiveStreamData returns nil because the
// requested minimum spans more than one segment). Clearing afterwards
// would clobber that re-registration and drop later notifications.
if let inboundDataAvailableCompletion = self.completions.inboundDataAvailable {
inboundDataAvailableCompletion(true)
self.completions.inboundDataAvailable = nil
inboundDataAvailableCompletion(true)
}
}

Expand Down
Loading
Loading