1
0
mirror of https://github.com/golang/go synced 2024-11-19 05:24:42 -07:00
go/src/net/sys_cloexec.go
Tobias Klauser 3e00bd0ae4 internal/poll, net, syscall: use accept4 on solaris
Solaris supports accept4 since version 11.4, see
https://docs.oracle.com/cd/E88353_01/html/E37843/accept4-3c.html
Use it in internal/poll.accept like on other platforms.

Change-Id: I3d9830a85e93bbbed60486247c2f91abc646371f
Reviewed-on: https://go-review.googlesource.com/c/go/+/403394
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-05-03 14:38:32 +00:00

37 lines
962 B
Go

// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file implements sysSocket for platforms that do not provide a fast path
// for setting SetNonblock and CloseOnExec.
//go:build aix || darwin
package net
import (
"internal/poll"
"os"
"syscall"
)
// Wrapper around the socket system call that marks the returned file
// descriptor as nonblocking and close-on-exec.
func sysSocket(family, sotype, proto int) (int, error) {
// See ../syscall/exec_unix.go for description of ForkLock.
syscall.ForkLock.RLock()
s, err := socketFunc(family, sotype, proto)
if err == nil {
syscall.CloseOnExec(s)
}
syscall.ForkLock.RUnlock()
if err != nil {
return -1, os.NewSyscallError("socket", err)
}
if err = syscall.SetNonblock(s, true); err != nil {
poll.CloseFunc(s)
return -1, os.NewSyscallError("setnonblock", err)
}
return s, nil
}