Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: upgrade Proto code to Swift 6#14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
spikecurtis merged 1 commit intomainfromspike/proto-swift-6
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
8 changes: 4 additions & 4 deletionsCoder Desktop/Coder Desktop.xcodeproj/project.pbxproj
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -660,7 +660,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.coder.Coder-Desktop";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION =5.0;
SWIFT_VERSION =6.0;
};
name = Debug;
};
Expand DownExpand Up@@ -690,7 +690,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.coder.Coder-Desktop";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION =5.0;
SWIFT_VERSION =6.0;
};
name = Release;
};
Expand DownExpand Up@@ -835,7 +835,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.coder.Coder-Desktop.ProtoTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION =5.0;
SWIFT_VERSION =6.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Coder Desktop.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Coder Desktop";
};
name = Debug;
Expand All@@ -853,7 +853,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.coder.Coder-Desktop.ProtoTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION =5.0;
SWIFT_VERSION =6.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Coder Desktop.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Coder Desktop";
};
name = Release;
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,6 +54,15 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "961678FB2CFF100D00B2B6DF"
BuildableName = "Coder Desktop.app"
BlueprintName = "Coder Desktop"
ReferencedContainer = "container:Coder Desktop.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
4 changes: 2 additions & 2 deletionsCoder Desktop/Proto/Receiver.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ actor Receiver<RecvMsg: Message> {
dispatch.read(offset: 0, length: 4, queue: queue) { done, data, error in
guard error == 0 else {
let errStrPtr = strerror(error)
let errStr = String(validatingUTF8: errStrPtr!)!
let errStr = String(validatingCString: errStrPtr!)!
continuation.resume(throwing: ReceiveError.readError(errStr))
return
}
Expand All@@ -42,7 +42,7 @@ actor Receiver<RecvMsg: Message> {
dispatch.read(offset: 0, length: Int(length), queue: queue) { done, data, error in
guard error == 0 else {
let errStrPtr = strerror(error)
let errStr = String(validatingUTF8: errStrPtr!)!
let errStr = String(validatingCString: errStrPtr!)!
continuation.resume(throwing: ReceiveError.readError(errStr))
return
}
Expand Down
22 changes: 11 additions & 11 deletionsCoder Desktop/Proto/Speaker.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -133,20 +133,20 @@ class Speaker<SendMsg: RPCMessage & Message, RecvMsg: RPCMessage & Message> {
/// Send a unary RPC message and handle the response
func unaryRPC(_ req: SendMsg) async throws -> RecvMsg {
return try await withCheckedThrowingContinuation { continuation in
Task {
let msgID = awaitself.secretary.record(continuation: continuation)
Task { [sender, secretary, logger] in
let msgID = await secretary.record(continuation: continuation)
var req = req
req.rpc = Vpn_RPC()
req.rpc.msgID = msgID
do {
self.logger.debug("sending RPC with msgID: \(msgID)")
try awaitself.sender.send(req)
logger.debug("sending RPC with msgID: \(msgID)")
try await sender.send(req)
} catch {
self.logger.warning("failed to send RPC with msgID: \(msgID): \(error)")
awaitself.secretary.erase(id: req.rpc.msgID)
logger.warning("failed to send RPC with msgID: \(msgID): \(error)")
await secretary.erase(id: req.rpc.msgID)
continuation.resume(throwing: error)
}
self.logger.debug("sent RPC with msgID: \(msgID)")
logger.debug("sent RPC with msgID: \(msgID)")
}
}
}
Expand All@@ -169,7 +169,7 @@ class Speaker<SendMsg: RPCMessage & Message, RecvMsg: RPCMessage & Message> {
}

/// A class that performs the initial VPN protocol handshake and version negotiation.
class Handshaker {
class Handshaker: @unchecked Sendable {
private let writeFD: FileHandle
private let dispatch: DispatchIO
private var theirData: Data = .init()
Expand DownExpand Up@@ -219,7 +219,7 @@ class Handshaker {
private func handleRead(_: Bool, _ data: DispatchData?, _ error: Int32) {
guard error == 0 else {
let errStrPtr = strerror(error)
let errStr = String(validatingUTF8: errStrPtr!)!
let errStr = String(validatingCString: errStrPtr!)!
continuation?.resume(throwing: HandshakeError.readError(errStr))
return
}
Expand DownExpand Up@@ -277,7 +277,7 @@ enum HandshakeError: Error {
case unsupportedVersion([ProtoVersion])
}

struct RPCRequest<SendMsg: RPCMessage & Message, RecvMsg: RPCMessage> {
struct RPCRequest<SendMsg: RPCMessage & Message, RecvMsg: RPCMessage & Sendable>: Sendable {
let msg: RecvMsg
private let sender: Sender<SendMsg>

Expand All@@ -302,7 +302,7 @@ enum RPCError: Error {
}

/// An actor to record outgoing RPCs and route their replies to the original sender
actor RPCSecretary<RecvMsg: RPCMessage> {
actor RPCSecretary<RecvMsg: RPCMessage & Sendable> {
private var continuations: [UInt64: CheckedContinuation<RecvMsg, Error>] = [:]
private var nextMsgID: UInt64 = 1

Expand Down
63 changes: 41 additions & 22 deletionsCoder Desktop/ProtoTests/SpeakerTests.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,20 +4,45 @@ import Testing

/// A concrete, test class for the abstract Speaker, which overrides the handlers to send things to
/// continuations we set in the test.
classTestTunnel:Speaker<Vpn_TunnelMessage,Vpn_ManagerMessage>{
varmsgHandler:CheckedContinuation<Vpn_ManagerMessage,Error>?
classTestTunnel:Speaker<Vpn_TunnelMessage,Vpn_ManagerMessage>,@uncheckedSendable{
privatevarmsgHandler:CheckedContinuation<Vpn_ManagerMessage,Error>?
overridefunc handleMessage(_ msg:Vpn_ManagerMessage){
msgHandler?.resume(returning: msg)
}

varrpcHandler:CheckedContinuation<RPCRequest<Vpn_TunnelMessage,Vpn_ManagerMessage>,Error>?
/// Runs the given closure asynchronously and returns the next non-RPC message received.
func expectMessage(with closure:
@escaping@Sendable()async->Void)asyncthrows->Vpn_ManagerMessage
{
returntryawaitwithCheckedThrowingContinuation{ continuationin
msgHandler= continuation
Task{
awaitclosure()
}
}
}

privatevarrpcHandler:CheckedContinuation<RPCRequest<Vpn_TunnelMessage,Vpn_ManagerMessage>,Error>?
overridefunc handleRPC(_ req:RPCRequest<Vpn_TunnelMessage,Vpn_ManagerMessage>){
rpcHandler?.resume(returning: req)
}

/// Runs the given closure asynchronously and return the next non-RPC message received
func expectRPC(with closure:
@escaping@Sendable()async->Void)asyncthrows->
RPCRequest<Vpn_TunnelMessage,Vpn_ManagerMessage>
{
returntryawaitwithCheckedThrowingContinuation{ continuationin
rpcHandler= continuation
Task{
awaitclosure()
}
}
}
}

@Suite(.timeLimit(.minutes(1)))
struct SpeakerTests{
struct SpeakerTests:Sendable{
letpipeMT=Pipe()
letpipeTM=Pipe()
letuut:TestTunnel
Expand DownExpand Up@@ -56,14 +81,11 @@ struct SpeakerTests {
@Testfunc handleSingleMessage()asyncthrows{
asyncletreadDone:()=try uut.readLoop()

letgot=tryawaitwithCheckedThrowingContinuation{ continuationin
uut.msgHandler= continuation
Task{
vars=Vpn_ManagerMessage()
s.start=Vpn_StartRequest()
await #expect(throws:Never.self){
tryawait sender.send(s)
}
letgot=tryawait uut.expectMessage{
vars=Vpn_ManagerMessage()
s.start=Vpn_StartRequest()
await #expect(throws:Never.self){
tryawait sender.send(s)
}
}
#expect(got.msg==.start(Vpn_StartRequest()))
Expand All@@ -74,16 +96,13 @@ struct SpeakerTests {
@Testfunc handleRPC()asyncthrows{
asyncletreadDone:()=try uut.readLoop()

letgot=tryawaitwithCheckedThrowingContinuation{ continuationin
uut.rpcHandler= continuation
Task{
vars=Vpn_ManagerMessage()
s.start=Vpn_StartRequest()
s.rpc=Vpn_RPC()
s.rpc.msgID=33
await #expect(throws:Never.self){
tryawait sender.send(s)
}
letgot=tryawait uut.expectRPC{
vars=Vpn_ManagerMessage()
s.start=Vpn_StartRequest()
s.rpc=Vpn_RPC()
s.rpc.msgID=33
await #expect(throws:Never.self){
tryawait sender.send(s)
}
}
#expect(got.msg.msg==.start(Vpn_StartRequest()))
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp