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