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
61 changes: 42 additions & 19 deletions Sources/SwiftNetwork/EndpointFlow/EndpointFlowExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,49 @@ extension EndpointFlow {

switch transport {
case .tcp(let options):
guard let reference = TCPProtocol().newProtocolInstance(context: context) else {
throw NetworkError.posix(EINVAL)
if case .custom(let linkOptions) = stack.link,
linkOptions.identifier == BridgeDatagramProtocol.identifier
{
guard let reference = TCPProtocol().newProtocolInstance(context: context) else {
throw NetworkError.posix(EINVAL)
}
options.setProtocolInstance(reference)
let linkage = OutboundStreamLinkage(reference: reference)
let flow = try StreamEndpointFlowProtocol(
identifier: String(self.identifier),
local: effectiveLocalEndpoint,
remote: effectiveRemoteEndpoint,
parameters: self.parameters,
path: path,
context: context,
lowerStreamProtocol: linkage
)
self.flowProtocol = .stream(flow)
options.setLogID(
prefix: "C",
parent: String(self.identifier),
protocolLogIDNumber: Int(self.identifier)
)
} else {
let socketReference = SocketStreamProtocol.instance(context: context)
options.setProtocolInstance(socketReference)
let linkage = OutboundStreamLinkage(reference: socketReference)
let flow = try StreamEndpointFlowProtocol(
identifier: String(self.identifier),
local: effectiveLocalEndpoint,
remote: effectiveRemoteEndpoint,
parameters: self.parameters,
path: path,
context: context,
lowerStreamProtocol: linkage
)
self.flowProtocol = .stream(flow)
options.setLogID(
prefix: "C",
parent: String(self.identifier),
protocolLogIDNumber: Int(self.identifier)
)
}
options.setProtocolInstance(reference)
let linkage = OutboundStreamLinkage(reference: reference)
let flow = try StreamEndpointFlowProtocol(
identifier: String(self.identifier),
local: effectiveLocalEndpoint,
remote: effectiveRemoteEndpoint,
parameters: self.parameters,
path: path,
context: context,
lowerStreamProtocol: linkage
)
self.flowProtocol = .stream(flow)
options.setLogID(
prefix: "C",
parent: String(self.identifier),
protocolLogIDNumber: Int(self.identifier)
)
case .udp(let options):
if case .custom(let linkOptions) = stack.link,
linkOptions.identifier == BridgeDatagramProtocol.identifier
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