diff --git a/core/src/main/golang/tun/tun.go b/core/src/main/golang/tun/tun.go index 89167c9..bb54b64 100644 --- a/core/src/main/golang/tun/tun.go +++ b/core/src/main/golang/tun/tun.go @@ -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) +} \ No newline at end of file diff --git a/service/src/main/java/com/github/kr328/clash/service/TunService.kt b/service/src/main/java/com/github/kr328/clash/service/TunService.kt index 9e376a4..a0ef99b 100644 --- a/service/src/main/java/com/github/kr328/clash/service/TunService.kt +++ b/service/src/main/java/com/github/kr328/clash/service/TunService.kt @@ -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