[server] Fix running on Android (tcplisten had issues determining max TCP backlog).

This commit is contained in:
Ciprian Dorin Craciun 2022-09-02 12:57:16 +03:00
parent a3f433ad2d
commit 1dd2586c39
2 changed files with 44 additions and 6 deletions

View file

@ -0,0 +1,39 @@
package server
import "runtime"
import "net"
import "github.com/valyala/tcplisten"
import "github.com/valyala/fasthttp/reuseport"
func listenTcp (_endpoint string) (net.Listener, error) {
if runtime.GOOS == "android" {
var _config = & tcplisten.Config {
ReusePort : true,
DeferAccept : true,
FastOpen : true,
Backlog : 1024,
}
return _config.NewListener ("tcp4", _endpoint)
}
// FIXME: Perhaps always use `tcplisten`...
return reuseport.Listen ("tcp4", _endpoint)
}
func listenUdp (_endpoint string) (net.PacketConn, error) {
return net.ListenPacket ("udp4", _endpoint)
}

View file

@ -29,7 +29,6 @@ import "unsafe"
import "github.com/colinmarc/cdb" import "github.com/colinmarc/cdb"
import "github.com/valyala/fasthttp" import "github.com/valyala/fasthttp"
import "github.com/valyala/fasthttp/reuseport"
import "github.com/lucas-clemente/quic-go" import "github.com/lucas-clemente/quic-go"
import "github.com/lucas-clemente/quic-go/http3" import "github.com/lucas-clemente/quic-go/http3"
@ -1780,7 +1779,7 @@ func main_0 () (error) {
var _httpPlain1Listener net.Listener var _httpPlain1Listener net.Listener
if _bindPlain1 != "" { if _bindPlain1 != "" {
if _listener_0, _error := reuseport.Listen ("tcp4", _bindPlain1); _error == nil { if _listener_0, _error := listenTcp (_bindPlain1); _error == nil {
_httpPlain1Listener = _listener_0 _httpPlain1Listener = _listener_0
} else { } else {
AbortError (_error, "[d5f51e9f] [bind-0a.] failed creating TCP listener!") AbortError (_error, "[d5f51e9f] [bind-0a.] failed creating TCP listener!")
@ -1789,7 +1788,7 @@ func main_0 () (error) {
var _httpPlain2Listener net.Listener var _httpPlain2Listener net.Listener
if _bindPlain2 != "" { if _bindPlain2 != "" {
if _listener_0, _error := reuseport.Listen ("tcp4", _bindPlain2); _error == nil { if _listener_0, _error := listenTcp (_bindPlain2); _error == nil {
_httpPlain2Listener = _listener_0 _httpPlain2Listener = _listener_0
} else { } else {
AbortError (_error, "[546075c2] [bind-0b.] failed creating TCP listener!") AbortError (_error, "[546075c2] [bind-0b.] failed creating TCP listener!")
@ -1798,7 +1797,7 @@ func main_0 () (error) {
var _httpTls1Listener net.Listener var _httpTls1Listener net.Listener
if _bindTls1 != "" { if _bindTls1 != "" {
if _listener_0, _error := reuseport.Listen ("tcp4", _bindTls1); _error == nil { if _listener_0, _error := listenTcp (_bindTls1); _error == nil {
_httpTls1Listener = _listener_0 _httpTls1Listener = _listener_0
} else { } else {
AbortError (_error, "[e35cc693] [bind-1..] failed creating TCP listener!") AbortError (_error, "[e35cc693] [bind-1..] failed creating TCP listener!")
@ -1807,7 +1806,7 @@ func main_0 () (error) {
var _httpTls2Listener net.Listener var _httpTls2Listener net.Listener
if _bindTls2 != "" { if _bindTls2 != "" {
if _listener_0, _error := reuseport.Listen ("tcp4", _bindTls2); _error == nil { if _listener_0, _error := listenTcp (_bindTls2); _error == nil {
_httpTls2Listener = _listener_0 _httpTls2Listener = _listener_0
} else { } else {
AbortError (_error, "[63567445] [bind-2..] failed creating TCP listener!") AbortError (_error, "[63567445] [bind-2..] failed creating TCP listener!")
@ -1816,7 +1815,7 @@ func main_0 () (error) {
var _httpQuicListener net.PacketConn var _httpQuicListener net.PacketConn
if _bindQuic != "" { if _bindQuic != "" {
if _listener_0, _error := net.ListenPacket ("udp4", _bindQuic); _error == nil { if _listener_0, _error := listenUdp (_bindQuic); _error == nil {
_httpQuicListener = _listener_0 _httpQuicListener = _listener_0
} else { } else {
AbortError (_error, "[3b1bfc15] [bind-3..] failed creating UDP listener!") AbortError (_error, "[3b1bfc15] [bind-3..] failed creating UDP listener!")