Source file
src/net/sock_cloexec_solaris.go
1
2
3
4
5
6
7
8
9
10
11 package net
12
13 import (
14 "internal/poll"
15 "internal/syscall/unix"
16 "os"
17 "syscall"
18 )
19
20
21
22 func sysSocket(family, sotype, proto int) (int, error) {
23
24 if unix.SupportSockNonblockCloexec() {
25 s, err := socketFunc(family, sotype|syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC, proto)
26 if err != nil {
27 return -1, os.NewSyscallError("socket", err)
28 }
29 return s, nil
30 }
31
32
33 syscall.ForkLock.RLock()
34 s, err := socketFunc(family, sotype, proto)
35 if err == nil {
36 syscall.CloseOnExec(s)
37 }
38 syscall.ForkLock.RUnlock()
39 if err != nil {
40 return -1, os.NewSyscallError("socket", err)
41 }
42 if err = syscall.SetNonblock(s, true); err != nil {
43 poll.CloseFunc(s)
44 return -1, os.NewSyscallError("setnonblock", err)
45 }
46 return s, nil
47 }
48
View as plain text