libgo: update to go1.9
[official-gcc.git] / libgo / go / internal / poll / sys_cloexec.go
blob9ed35bdaf41e76eedfd995038cb70b9fcbf6141f
1 // Copyright 2013 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.
5 // This file implements sysSocket and accept for platforms that do not
6 // provide a fast path for setting SetNonblock and CloseOnExec.
8 // +build darwin nacl netbsd openbsd solaris
10 package poll
12 import (
13 "syscall"
16 // Wrapper around the accept system call that marks the returned file
17 // descriptor as nonblocking and close-on-exec.
18 func accept(s int) (int, syscall.Sockaddr, string, error) {
19 // See ../syscall/exec_unix.go for description of ForkLock.
20 // It is probably okay to hold the lock across syscall.Accept
21 // because we have put fd.sysfd into non-blocking mode.
22 // However, a call to the File method will put it back into
23 // blocking mode. We can't take that risk, so no use of ForkLock here.
24 ns, sa, err := AcceptFunc(s)
25 if err == nil {
26 syscall.CloseOnExec(ns)
28 if err != nil {
29 return -1, nil, "accept", err
31 if err = syscall.SetNonblock(ns, true); err != nil {
32 CloseFunc(ns)
33 return -1, nil, "setnonblock", err
35 return ns, sa, "", nil