1
2
3
4
5
6
7 package poll
8
9 import (
10 "io"
11 "syscall"
12 )
13
14
15
16 func (fd *FD) eofError(n int, err error) error {
17 if n == 0 && err == nil && fd.ZeroReadIsEOF {
18 return io.EOF
19 }
20 return err
21 }
22
23
24 func (fd *FD) Shutdown(how int) error {
25 if err := fd.incref(); err != nil {
26 return err
27 }
28 defer fd.decref()
29 return syscall.Shutdown(fd.Sysfd, how)
30 }
31
32
33 func (fd *FD) Fchown(uid, gid int) error {
34 if err := fd.incref(); err != nil {
35 return err
36 }
37 defer fd.decref()
38 return ignoringEINTR(func() error {
39 return syscall.Fchown(fd.Sysfd, uid, gid)
40 })
41 }
42
43
44 func (fd *FD) Ftruncate(size int64) error {
45 if err := fd.incref(); err != nil {
46 return err
47 }
48 defer fd.decref()
49 return ignoringEINTR(func() error {
50 return syscall.Ftruncate(fd.Sysfd, size)
51 })
52 }
53
54
55
56 func (fd *FD) RawControl(f func(uintptr)) error {
57 if err := fd.incref(); err != nil {
58 return err
59 }
60 defer fd.decref()
61 f(uintptr(fd.Sysfd))
62 return nil
63 }
64
65
66
67
68
69
70
71
72 func ignoringEINTR(fn func() error) error {
73 for {
74 err := fn()
75 if err != syscall.EINTR {
76 return err
77 }
78 }
79 }
80
View as plain text