forked from mdlayher/vsock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfd_linux_1.11.go
76 lines (61 loc) · 2.17 KB
/
fd_linux_1.11.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//+build go1.11,!go1.12,linux
package vsock
import (
"fmt"
"os"
"runtime"
"syscall"
"time"
"golang.org/x/sys/unix"
)
func (lfd *sysListenFD) accept4(flags int) (int, unix.Sockaddr, error) {
// In Go 1.11, accept on the raw file descriptor directly, because lfd.f
// may be attached to the runtime network poller, forcing this call to block
// even if Close is called.
return unix.Accept4(lfd.fd, flags)
}
func (lfd *sysListenFD) setNonblocking(name string) error {
// From now on, we must perform non-blocking I/O, so that our
// net.Listener.Accept method can be interrupted by closing the socket.
if err := unix.SetNonblock(lfd.fd, true); err != nil {
return err
}
// Transition from blocking mode to non-blocking mode.
lfd.f = os.NewFile(uintptr(lfd.fd), name)
return nil
}
func (*sysListenFD) setDeadline(_ time.Time) error {
// Listener deadlines won't work as expected in this version of Go, so
// return an early error.
return fmt.Errorf("vsock: listener deadlines not supported on %s", runtime.Version())
}
func (*sysConnFD) shutdown(_ int) error {
// Shutdown functionality is not available in this version on Go.
return fmt.Errorf("vsock: close conn read/write not supported on %s", runtime.Version())
}
func (*sysConnFD) syscallConn() (syscall.RawConn, error) {
// SyscallConn functionality is not available in this version on Go.
return nil, fmt.Errorf("vsock: syscall conn not supported on %s", runtime.Version())
}
func (cfd *sysConnFD) setNonblocking(name string) error {
// From now on, we must perform non-blocking I/O, so that our deadline
// methods work, and the connection can be interrupted by net.Conn.Close.
if err := unix.SetNonblock(cfd.fd, true); err != nil {
return err
}
// Transition from blocking mode to non-blocking mode.
cfd.f = os.NewFile(uintptr(cfd.fd), name)
return nil
}
func (cfd *sysConnFD) setDeadline(t time.Time, typ deadlineType) error {
switch typ {
case deadline:
return cfd.f.SetDeadline(t)
case readDeadline:
return cfd.f.SetReadDeadline(t)
case writeDeadline:
return cfd.f.SetWriteDeadline(t)
}
panicf("vsock: sysConnFD.SetDeadline method invoked with invalid deadline type constant: %d", typ)
return nil
}