Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ClashForAndroid
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
ClashForAndroid
Commits
634c2589
There was an error fetching the commit references. Please try again later.
Commit
634c2589
authored
3 years ago
by
kr328
Browse files
Options
Downloads
Patches
Plain Diff
Fix: should close all endpoint on exit
parent
42f5331a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/src/main/golang/tun/tun.go
+17
-13
17 additions, 13 deletions
core/src/main/golang/tun/tun.go
with
17 additions
and
13 deletions
core/src/main/golang/tun/tun.go
+
17
−
13
View file @
634c2589
...
...
@@ -9,13 +9,18 @@ import (
)
type
context
struct
{
stack
tun2socket
.
Stack
device
*
os
.
File
stack
tun2socket
.
Stack
}
var
lock
sync
.
Mutex
var
tun
*
context
func
(
ctx
*
context
)
close
()
{
_
=
ctx
.
stack
.
Close
()
_
=
ctx
.
device
.
Close
()
}
func
Start
(
fd
,
mtu
int
,
dns
string
)
error
{
lock
.
Lock
()
defer
lock
.
Unlock
()
...
...
@@ -33,11 +38,15 @@ func Start(fd, mtu int, dns string) error {
return
err
}
ctx
:=
&
context
{
device
:
device
,
stack
:
stack
,
}
go
func
()
{
// device -> lwip
defer
device
.
Close
()
defer
stack
.
Close
()
defer
ctx
.
close
()
buf
:=
make
([]
byte
,
mtu
)
...
...
@@ -54,8 +63,7 @@ func Start(fd, mtu int, dns string) error {
go
func
()
{
// lwip -> device
defer
device
.
Close
()
defer
stack
.
Close
()
defer
ctx
.
close
()
buf
:=
make
([]
byte
,
mtu
)
...
...
@@ -72,7 +80,7 @@ func Start(fd, mtu int, dns string) error {
go
func
()
{
// lwip tcp
defer
stack
.
TCP
()
.
C
lose
()
defer
ctx
.
c
lose
()
for
{
conn
,
err
:=
stack
.
TCP
()
.
Accept
()
...
...
@@ -96,7 +104,7 @@ func Start(fd, mtu int, dns string) error {
go
func
()
{
// lwip udp
defer
stack
.
UDP
()
.
C
lose
()
defer
ctx
.
c
lose
()
for
{
buf
:=
allocUDP
(
mtu
)
...
...
@@ -123,10 +131,7 @@ func Start(fd, mtu int, dns string) error {
}
}()
tun
=
&
context
{
stack
:
stack
,
device
:
device
,
}
tun
=
ctx
return
nil
}
...
...
@@ -140,8 +145,7 @@ func Stop() {
func
stopLocked
()
{
if
tun
!=
nil
{
tun
.
device
.
Close
()
tun
.
stack
.
Close
()
tun
.
close
()
}
tun
=
nil
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment