Skip to content

Commit d19ff85

Browse files
committed
unix: on linux use accept4 in Accept, fall back to accept
Android seems to block the accept syscall in newer versions. Use accept4 instead on kernel versions that support it (Linux 2.6.28 and newer) and fall back to accept on ENOSYS. Updates golang/go#45767 Change-Id: If557eaaaa0b69112bbe66ed820fbb382afb53b04 Reviewed-on: https://go-review.googlesource.com/c/sys/+/313690 Trust: Tobias Klauser <[email protected]> Run-TryBot: Tobias Klauser <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 413ae7e commit d19ff85

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

unix/syscall_linux.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,11 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
11511151
func Accept(fd int) (nfd int, sa Sockaddr, err error) {
11521152
var rsa RawSockaddrAny
11531153
var len _Socklen = SizeofSockaddrAny
1154-
nfd, err = accept(fd, &rsa, &len)
1154+
// Try accept4 first for Android, then try accept for kernel older than 2.6.28
1155+
nfd, err = accept4(fd, &rsa, &len, 0)
1156+
if err == ENOSYS {
1157+
nfd, err = accept(fd, &rsa, &len)
1158+
}
11551159
if err != nil {
11561160
return
11571161
}

0 commit comments

Comments
 (0)