Source file src/syscall/syscall_linux_accept.go

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // We require Linux kernel version 2.6.32. The accept4 system call was
     6  // added in version 2.6.28, so in general we can use accept4.
     7  // Unfortunately, for ARM only, accept4 was added in version 2.6.36.
     8  // Handle that case here, by using a copy of the Accept function that
     9  // we used in Go 1.17.
    10  
    11  //go:build linux && arm
    12  
    13  package syscall
    14  
    15  //sys	accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
    16  
    17  func Accept(fd int) (nfd int, sa Sockaddr, err error) {
    18  	var rsa RawSockaddrAny
    19  	var len _Socklen = SizeofSockaddrAny
    20  	// Try accept4 first for Android and newer kernels.
    21  	nfd, err = accept4(fd, &rsa, &len, 0)
    22  	if err == ENOSYS {
    23  		nfd, err = accept(fd, &rsa, &len)
    24  	}
    25  	if err != nil {
    26  		return
    27  	}
    28  	sa, err = anyToSockaddr(&rsa)
    29  	if err != nil {
    30  		Close(nfd)
    31  		nfd = 0
    32  	}
    33  	return
    34  }
    35  

View as plain text