...
Source file
src/net/sock_cloexec.go
Documentation: net
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 switch err {
26 case nil:
27 return s, nil
28 default:
29 return -1, os.NewSyscallError("socket", err)
30 case syscall.EPROTONOSUPPORT, syscall.EINVAL:
31 }
32
33
34 syscall.ForkLock.RLock()
35 s, err = socketFunc(family, sotype, proto)
36 if err == nil {
37 syscall.CloseOnExec(s)
38 }
39 syscall.ForkLock.RUnlock()
40 if err != nil {
41 return -1, os.NewSyscallError("socket", err)
42 }
43 if err = syscall.SetNonblock(s, true); err != nil {
44 poll.CloseFunc(s)
45 return -1, os.NewSyscallError("setnonblock", err)
46 }
47 return s, nil
48 }
49
View as plain text