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

Commit4d0b3da

Browse files
committed
improve tunnelhandle
1 parent844df27 commit4d0b3da

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

‎Coder Desktop/VPN/TunnelHandle.swift

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,12 @@ actor TunnelHandle {
1515

1616
init(dylibPath:URL)throws(TunnelHandleError){
1717
guardlet dylibHandle=dlopen(dylibPath.path, RTLD_NOW | RTLD_LOCAL)else{
18-
varerrStr="UNKNOWN"
19-
lete=dlerror()
20-
if e!=nil{
21-
errStr=String(cString: e!)
22-
}
23-
throw.dylib(errStr)
18+
throw.dylib(dlerror().flatMap{String(cString: $0)}??"UNKNOWN")
2419
}
2520
self.dylibHandle= dylibHandle
2621

2722
guardlet startSym=dlsym(dylibHandle, startSymbol)else{
28-
varerrStr="UNKNOWN"
29-
lete=dlerror()
30-
if e!=nil{
31-
errStr=String(cString: e!)
32-
}
33-
throw.symbol(startSymbol, errStr)
23+
throw.symbol(startSymbol,dlerror().flatMap{String(cString: $0)}??"UNKNOWN")
3424
}
3525
letopenTunnelFn=unsafeBitCast(startSym, to:OpenTunnel.self)
3626
tunnelReadPipe=Pipe()
@@ -42,21 +32,42 @@ actor TunnelHandle {
4232
}
4333
}
4434

45-
func close()throws{
46-
dlclose(dylibHandle)
35+
// This could be an isolated deinit in Swift 6.1
36+
func close()throws(TunnelHandleError){
37+
varerrs:[Error]=[]
38+
ifdlclose(dylibHandle)==0{
39+
errs.append(TunnelHandleError.dylib(dlerror().flatMap{String(cString: $0)}??"UNKNOWN"))
40+
}
41+
do{
42+
try writeHandle.close()
43+
}catch{
44+
errs.append(error)
45+
}
46+
do{
47+
try readHandle.close()
48+
}catch{
49+
errs.append(error)
50+
}
51+
if !errs.isEmpty{
52+
throw.close(errs)
53+
}
4754
}
4855
}
4956

5057
enumTunnelHandleError:Error{
5158
case dylib(String)
5259
case symbol(String,String)
5360
case openTunnel(OpenTunnelError)
61+
case pipe(anyError)
62+
case close([anyError])
5463

5564
vardescription:String{
5665
switchself{
66+
caselet.pipe(err):return"pipe error:\(err)"
5767
caselet.dylib(d):return d
5868
caselet.symbol(symbol, message):return"\(symbol):\(message)"
5969
caselet.openTunnel(error):return"OpenTunnel:\(error.message)"
70+
caselet.close(errs):return"close tunnel:\(errs.map(\.localizedDescription).joined(separator:","))"
6071
}
6172
}
6273
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp