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