Retro68/gcc/libgo/go/net/sys_cloexec.go

37 lines
982 B
Go
Raw Normal View History

2014-09-21 17:33:12 +00:00
// 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 and accept for platforms that do not
// provide a fast path for setting SetNonblock and CloseOnExec.
2019-06-02 15:48:37 +00:00
// +build aix darwin nacl solaris
2014-09-21 17:33:12 +00:00
package net
2017-04-10 11:32:00 +00:00
import (
2018-12-28 15:30:48 +00:00
"internal/poll"
2017-04-10 11:32:00 +00:00
"os"
"syscall"
)
2014-09-21 17:33:12 +00:00
// Wrapper around the socket system call that marks the returned file
// descriptor as nonblocking and close-on-exec.
2015-08-28 15:33:40 +00:00
func sysSocket(family, sotype, proto int) (int, error) {
2014-09-21 17:33:12 +00:00
// See ../syscall/exec_unix.go for description of ForkLock.
syscall.ForkLock.RLock()
2017-04-10 11:32:00 +00:00
s, err := socketFunc(family, sotype, proto)
2014-09-21 17:33:12 +00:00
if err == nil {
syscall.CloseOnExec(s)
}
syscall.ForkLock.RUnlock()
if err != nil {
2017-04-10 11:32:00 +00:00
return -1, os.NewSyscallError("socket", err)
2014-09-21 17:33:12 +00:00
}
if err = syscall.SetNonblock(s, true); err != nil {
2018-12-28 15:30:48 +00:00
poll.CloseFunc(s)
2017-04-10 11:32:00 +00:00
return -1, os.NewSyscallError("setnonblock", err)
2014-09-21 17:33:12 +00:00
}
return s, nil
}