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

Commitf970cfc

Browse files
fix: improve wake & sleep handling (#74)
1 parent3442516 commitf970cfc

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

‎Coder Desktop/VPN/PacketTunnelProvider.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
4848
options _:[String:NSObject]?, completionHandler:@escaping(Error?)->Void
4949
){
5050
logger.info("startTunnel called")
51+
guard manager==nilelse{
52+
logger.error("startTunnel called with non-nil Manager")
53+
// If the tunnel is already running, then we can just mark as connected.
54+
completionHandler(nil)
55+
return
56+
}
5157
start(completionHandler)
5258
}
5359

5460
// called by `startTunnel` and on `wake`
5561
func start(_ completionHandler:@escaping(Error?)->Void){
56-
guard manager==nilelse{
57-
logger.error("startTunnel called with non-nil Manager")
58-
completionHandler(makeNSError(suffix:"PTP", desc:"Already running"))
59-
return
60-
}
6162
guardlet proto= protocolConfigurationas?NETunnelProviderProtocol,
6263
let baseAccessURL= proto.serverAddress
6364
else{
@@ -123,9 +124,11 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
123124
logger.error("error stopping manager:\(error.description, privacy:.public)")
124125
}
125126
globalXPCListenerDelegate.vpnXPCInterface.manager=nil
127+
// Mark teardown as complete by setting manager to nil, and
128+
// calling the completion handler.
129+
self.manager=nil
126130
completionHandler()
127131
}
128-
self.manager=nil
129132
}
130133

131134
overridefunc handleAppMessage(_ messageData:Data, completionHandler:((Data?)->Void)?){
@@ -142,6 +145,13 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
142145
}
143146

144147
overridefunc wake(){
148+
// It's possible the tunnel is still starting up, if it is, wake should
149+
// be a no-op.
150+
guard !reassertingelse{return}
151+
guard manager==nilelse{
152+
logger.error("wake called with non-nil Manager")
153+
return
154+
}
145155
logger.debug("wake called")
146156
reasserting=true
147157
currentSettings=.init(tunnelRemoteAddress:"127.0.0.1")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp