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
4 changes: 4 additions & 0 deletions Sources/SwiftScaffolding/Client/ScaffoldingClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public final class ScaffoldingClient {

let localPort: UInt16 = try ConnectionUtil.getPort(serverPort)
try easyTier.addPortForward(bind: "127.0.0.1:\(localPort)", destination: "\(serverIp):\(serverPort)")
try await Task.sleep(nanoseconds: 3_000_000_000)
try await joinRoom(port: localPort, checkServer: checkServer)
return
}
Expand Down Expand Up @@ -137,6 +138,9 @@ public final class ScaffoldingClient {
}
} catch ConnectionError.timeout {
Logger.error("Timeout occurred while sending c:player_ping request")
if room.members.isEmpty {
throw ConnectionError.timeout
}
do {
try await sendRequest("c:ping", timeout: 1)
} catch ConnectionError.timeout {
Expand Down
11 changes: 10 additions & 1 deletion Sources/SwiftScaffolding/Server/ScaffoldingServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public final class ScaffoldingServer {

if let machineId = machineIdMap[identifier] {
self.room.members.removeAll(where: { $0.machineId == machineId })
self.machineIdMap.removeValue(forKey: identifier)
}

self.connectionTasks[identifier]?.cancel()
Expand Down Expand Up @@ -198,7 +199,15 @@ public final class ScaffoldingServer {
}

try handler.handleRequest(from: connection, type: type, requestBody: .init(data: bodyData), responseBuffer: responseBuffer)
connection.send(content: responseBuffer.data, completion: .idempotent)
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
connection.send(content: responseBuffer.data, completion: .contentProcessed { error in
if let error {
continuation.resume(throwing: error)
} else {
continuation.resume(returning: ())
}
})
}
}
}
}