]> Cypherpunks.ru repositories - gostls13.git/commitdiff
net, internal/poll, net/internal/socktest: use SOCK_{CLOEXEC,NONBLOCK} accept4/socket...
authorTobias Klauser <tklauser@distanz.ch>
Mon, 26 Feb 2018 14:58:05 +0000 (14:58 +0000)
committerTobias Klauser <tobias.klauser@gmail.com>
Mon, 26 Feb 2018 16:59:38 +0000 (16:59 +0000)
The SOCK_CLOEXEC and SOCK_NONBLOCK flags to the socket syscall and the
accept4 syscall are supported since OpenBSD 5.7.

Follows CL 40895 and CL 94295

Change-Id: Icaf35ace2ef5e73279a70d4f1a9fbf3be9371e6c
Reviewed-on: https://go-review.googlesource.com/97196
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
15 files changed:
src/internal/poll/hook_cloexec.go
src/internal/poll/sock_cloexec.go
src/internal/poll/sys_cloexec.go
src/net/internal/socktest/sys_cloexec.go
src/net/main_cloexec_test.go
src/net/sock_cloexec.go
src/net/sys_cloexec.go
src/syscall/syscall_openbsd.go
src/syscall/zerrors_openbsd_386.go
src/syscall/zerrors_openbsd_amd64.go
src/syscall/zsyscall_openbsd_386.go
src/syscall/zsyscall_openbsd_amd64.go
src/syscall/zsyscall_openbsd_arm.go
src/syscall/zsysnum_openbsd_386.go
src/syscall/zsysnum_openbsd_amd64.go

index 4b670b9d0ec8c1140bf75435352a7cdcc0b11ded..5c93bdaf6c96eaaeb5c14e036d2e0eb5b18f6a11 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build dragonfly freebsd linux netbsd
+// +build dragonfly freebsd linux netbsd openbsd
 
 package poll
 
index e46b4d3032373ae642eb81313dd80ba0958fe19e..691cb8e36fe6f84672aa5d0073ad59fa14d7a270 100644 (file)
@@ -5,7 +5,7 @@
 // This file implements sysSocket and accept for platforms that
 // provide a fast path for setting SetNonblock and CloseOnExec.
 
-// +build dragonfly freebsd linux netbsd
+// +build dragonfly freebsd linux netbsd openbsd
 
 package poll
 
index 4755dc3e5365e52a84129555e60a246759090431..3a25b13bb5a2272adf4255fc85dbd6d4921b0265 100644 (file)
@@ -5,7 +5,7 @@
 // This file implements sysSocket and accept for platforms that do not
 // provide a fast path for setting SetNonblock and CloseOnExec.
 
-// +build darwin nacl openbsd solaris
+// +build darwin nacl solaris
 
 package poll
 
index 3d70a4f026c76b4efe0a5dde69c57bfbc1155166..986d89471b07c55599f5831131bb834410b5206d 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build dragonfly freebsd linux netbsd
+// +build dragonfly freebsd linux netbsd openbsd
 
 package socktest
 
index c35c3b2673d3d5dad15d77e7b294dde5b01d4104..5398f9eae10fe8c25895ed4c1de0bdeeec34a1a7 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build dragonfly freebsd linux netbsd
+// +build dragonfly freebsd linux netbsd openbsd
 
 package net
 
index e224a5fb41f20b4a57c3523f511d2c403be61f08..0c883dc338fb0bdcab49a2e72e995432999150c8 100644 (file)
@@ -5,7 +5,7 @@
 // This file implements sysSocket and accept for platforms that
 // provide a fast path for setting SetNonblock and CloseOnExec.
 
-// +build dragonfly freebsd linux netbsd
+// +build dragonfly freebsd linux netbsd openbsd
 
 package net
 
index fe6b0cc764cf43ff6268abe375e5b2133edc40e0..7ab1407de92f22feba4930eb569d5c4e5542cec5 100644 (file)
@@ -5,7 +5,7 @@
 // This file implements sysSocket and accept for platforms that do not
 // provide a fast path for setting SetNonblock and CloseOnExec.
 
-// +build darwin nacl openbsd solaris
+// +build darwin nacl solaris
 
 package net
 
index d65e6a51fe8f53ac5a5254791aa54bcc5c63a605..1a9b7644a993dd1a50a9c8e67a8b87d555ca4e2b 100644 (file)
@@ -74,6 +74,25 @@ func Pipe(p []int) (err error) {
        return
 }
 
+//sys  accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error)
+func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) {
+       var rsa RawSockaddrAny
+       var len _Socklen = SizeofSockaddrAny
+       nfd, err = accept4(fd, &rsa, &len, flags)
+       if err != nil {
+               return
+       }
+       if len > SizeofSockaddrAny {
+               panic("RawSockaddrAny too small")
+       }
+       sa, err = anyToSockaddr(&rsa)
+       if err != nil {
+               Close(nfd)
+               nfd = 0
+       }
+       return
+}
+
 //sys getdents(fd int, buf []byte) (n int, err error)
 func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
        return getdents(fd, buf)
index 540d310e9f0b2f970a4439e297a4f6448ee5af93..5a7cdf2b65a3ecb65b65597f6beac5cb9ec229cb 100644 (file)
@@ -1177,7 +1177,9 @@ const (
        SIOCSSPPPPARAMS                   = 0x80206993
        SIOCSVH                           = 0xc02069f5
        SIOCSVNETID                       = 0x802069a6
+       SOCK_CLOEXEC                      = 0x8000
        SOCK_DGRAM                        = 0x2
+       SOCK_NONBLOCK                     = 0x4000
        SOCK_RAW                          = 0x3
        SOCK_RDM                          = 0x4
        SOCK_SEQPACKET                    = 0x5
index ae5b8c955a93d889b9ae03e4ca21b93ec48bcfe0..11fc1e3a16523f05ff74be0c0240715917c1ce43 100644 (file)
@@ -1176,7 +1176,9 @@ const (
        SIOCSSPPPPARAMS                   = 0x80206993
        SIOCSVH                           = 0xc02069f5
        SIOCSVNETID                       = 0x802069a6
+       SOCK_CLOEXEC                      = 0x8000
        SOCK_DGRAM                        = 0x2
+       SOCK_NONBLOCK                     = 0x4000
        SOCK_RAW                          = 0x3
        SOCK_RDM                          = 0x4
        SOCK_SEQPACKET                    = 0x5
index 3a46b94fa2fa14ea0b7bfed1e9520b08c81779bb..2e619472d977388b33971799f1fedc8b38ac26ad 100644 (file)
@@ -271,6 +271,17 @@ func pipe(p *[2]_C_int) (err error) {
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
+func accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) {
+       r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
+       nfd = int(r0)
+       if e1 != 0 {
+               err = errnoErr(e1)
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
 func getdents(fd int, buf []byte) (n int, err error) {
        var _p0 unsafe.Pointer
        if len(buf) > 0 {
index 6bca25140b7b1456acd264ca833a129d2329ca40..b749b88d90b79c3c892a8fa670826f36b438c655 100644 (file)
@@ -271,6 +271,17 @@ func pipe(p *[2]_C_int) (err error) {
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
+func accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) {
+       r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
+       nfd = int(r0)
+       if e1 != 0 {
+               err = errnoErr(e1)
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
 func getdents(fd int, buf []byte) (n int, err error) {
        var _p0 unsafe.Pointer
        if len(buf) > 0 {
index 4ce317c1b009152e1310e6a9e6ac33833365c116..69f4823e16265c57edd2589cffafd669b77e8e5c 100644 (file)
@@ -271,6 +271,17 @@ func pipe(p *[2]_C_int) (err error) {
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
+func accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) {
+       r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
+       nfd = int(r0)
+       if e1 != 0 {
+               err = errnoErr(e1)
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
 func getdents(fd int, buf []byte) (n int, err error) {
        var _p0 unsafe.Pointer
        if len(buf) > 0 {
index c172534aebb579bc561750f00c8604c59a058dc9..f9331fc57bae42c0366e99c38b0b2ef778063f91 100644 (file)
@@ -94,6 +94,7 @@ const (
        SYS_DUP2           = 90  // { int sys_dup2(int from, int to); }
        SYS_NANOSLEEP      = 91  // { int sys_nanosleep(const struct timespec *rqtp, \
        SYS_FCNTL          = 92  // { int sys_fcntl(int fd, int cmd, ... void *arg); }
+       SYS_ACCEPT4        = 93  // { int sys_accept4(int s, struct sockaddr *name, \
        SYS___THRSLEEP     = 94  // { int sys___thrsleep(const volatile void *ident, \
        SYS_FSYNC          = 95  // { int sys_fsync(int fd); }
        SYS_SETPRIORITY    = 96  // { int sys_setpriority(int which, id_t who, int prio); }
index 356c18737516d546deaaf397c5498cbd55932e34..3ebb1c4e8262b9d6bd68c28725294bccb2a343d0 100644 (file)
@@ -94,6 +94,7 @@ const (
        SYS_DUP2           = 90  // { int sys_dup2(int from, int to); }
        SYS_NANOSLEEP      = 91  // { int sys_nanosleep(const struct timespec *rqtp, \
        SYS_FCNTL          = 92  // { int sys_fcntl(int fd, int cmd, ... void *arg); }
+       SYS_ACCEPT4        = 93  // { int sys_accept4(int s, struct sockaddr *name, \
        SYS___THRSLEEP     = 94  // { int sys___thrsleep(const volatile void *ident, \
        SYS_FSYNC          = 95  // { int sys_fsync(int fd); }
        SYS_SETPRIORITY    = 96  // { int sys_setpriority(int which, id_t who, int prio); }