github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/internal/poll/sys_cloexec.go (about) 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. 4 5 // This file implements accept for platforms that do not provide a fast path for 6 // setting SetNonblock and CloseOnExec. 7 8 //go:build aix || darwin || (js && wasm) || (solaris && !illumos) 9 // +build aix darwin js,wasm solaris,!illumos 10 11 package poll 12 13 import ( 14 "syscall" 15 ) 16 17 // Wrapper around the accept system call that marks the returned file 18 // descriptor as nonblocking and close-on-exec. 19 func accept(s int) (int, syscall.Sockaddr, string, error) { 20 // See ../syscall/exec_unix.go for description of ForkLock. 21 // It is probably okay to hold the lock across syscall.Accept 22 // because we have put fd.sysfd into non-blocking mode. 23 // However, a call to the File method will put it back into 24 // blocking mode. We can't take that risk, so no use of ForkLock here. 25 ns, sa, err := AcceptFunc(s) 26 if err == nil { 27 syscall.CloseOnExec(ns) 28 } 29 if err != nil { 30 return -1, nil, "accept", err 31 } 32 if err = syscall.SetNonblock(ns, true); err != nil { 33 CloseFunc(ns) 34 return -1, nil, "setnonblock", err 35 } 36 return ns, sa, "", nil 37 }