add increase max connection & clean up code

This commit is contained in:
Kr328 committed 2020-06-12 00:38:21 +08:00
1 parent e1f4fef157
commit f4af98f54a
2 files changed
+22 -1

No files matched your search

+22
View File
@@ -55,6 +55,8 @@ func StartTunDevice(fd, mtu int, gateway, mirror, dnsAddress string, onStop func
file := os.NewFile(uintptr(fd), "/dev/tun")
_ = syscall.SetNonblock(fd, true)
increaseMaxConnection()
adapter = tun2socket.NewTun2Socket(file, mtu, gatewayIP, mirrorIP.To4())
adapter.SetLogger(&ClashLogger{})
@@ -133,3 +135,23 @@ func StopTunDevice() {
log.Infoln("Android tun stopped")
}
}
func increaseMaxConnection() {
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
return
}
if limit.Max == limit.Cur {
return
}
limit.Cur = limit.Max
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
return
}
log.Infoln("Increase max connection to %d", limit.Cur)
}
@@ -19,7 +19,6 @@ class TunService : VpnService(), CoroutineScope by MainScope() {
private const val PRIVATE_VLAN4_CLIENT = "172.31.255.253"
private const val PRIVATE_VLAN4_MIRROR = "172.31.255.254"
private const val PRIVATE_VLAN_DNS = "198.18.0.1"
private const val VLAN_ANY = "0.0.0.0/0"
}
private val service = this