Debian Codegraph @

sync.go

raw symbols SCIP
1 package nioscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/
2
3 import (
4 "ioscip-go gomod github.com/golang/go/src go1.16 io/"
5 "syncscip-go gomod github.com/golang/go/src go1.16 sync/"
6 )
7
8 // PipeReader is the read half of the pipe.
9 type PipeReaderscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader# struct {
10 *bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#bufpipe.
11 }
12
13 // CloseWithError closes the reader; subsequent writes to the write half of the pipe will return the error err.
14 func (r *PipeReaderscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#) CloseWithErrorscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#CloseWithError().(err error) error {
15 if err == nil {
16 err = ioscip-go gomod github.com/golang/go/src go1.16 io/.ErrClosedPipescip-go gomod github.com/golang/go/src go1.16 io/ErrClosedPipe.
17 }
18 r.bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#bufpipe..lscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#l..Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().()
19 defer r.bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#bufpipe..lscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#l..Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().()
20 if r.bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#bufpipe..rerrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rerr. == nil {
21 r.bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#bufpipe..rerrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rerr. = err
22 r.bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#bufpipe..rwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rwait..Signalscip-go gomod github.com/golang/go/src go1.16 sync/Cond#Signal().()
23 r.bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#bufpipe..wwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#wwait..Signalscip-go gomod github.com/golang/go/src go1.16 sync/Cond#Signal().()
24 }
25 return nil
26 }
27
28 // Close closes the reader; subsequent writes to the write half of the pipe will return the error io.ErrClosedPipe.
29 func (r *PipeReaderscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#) Closescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#Close().() error {
30 return r.CloseWithErrorscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#CloseWithError().(nil)
31 }
32
33 // A PipeWriter is the write half of a pipe.
34 type PipeWriterscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter# struct {
35 *bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#bufpipe.
36 }
37
38 // CloseWithError closes the writer; once the buffer is empty subsequent reads from the read half of the pipe will return
39 // no bytes and the error err, or io.EOF if err is nil. CloseWithError always returns nil.
40 func (w *PipeWriterscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#) CloseWithErrorscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#CloseWithError().(err error) error {
41 if err == nil {
42 err = ioscip-go gomod github.com/golang/go/src go1.16 io/.EOFscip-go gomod github.com/golang/go/src go1.16 io/EOF.
43 }
44 w.bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#bufpipe..lscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#l..Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().()
45 defer w.bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#bufpipe..lscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#l..Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().()
46 if w.bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#bufpipe..werrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#werr. == nil {
47 w.bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#bufpipe..werrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#werr. = err
48 w.bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#bufpipe..rwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rwait..Signalscip-go gomod github.com/golang/go/src go1.16 sync/Cond#Signal().()
49 w.bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#bufpipe..wwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#wwait..Signalscip-go gomod github.com/golang/go/src go1.16 sync/Cond#Signal().()
50 }
51 return nil
52 }
53
54 // Close closes the writer; once the buffer is empty subsequent reads from the read half of the pipe will return
55 // no bytes and io.EOF after all the buffer has been read. CloseWithError always returns nil.
56 func (w *PipeWriterscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#) Closescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#Close().() error {
57 return w.CloseWithErrorscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#CloseWithError().(nil)
58 }
59
60 type bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe# struct {
61 rlscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rl. syncscip-go gomod github.com/golang/go/src go1.16 sync/.Mutexscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#
62 wlscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#wl. syncscip-go gomod github.com/golang/go/src go1.16 sync/.Mutexscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#
63 lscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#l. syncscip-go gomod github.com/golang/go/src go1.16 sync/.Mutexscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#
64 rwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rwait. syncscip-go gomod github.com/golang/go/src go1.16 sync/.Condscip-go gomod github.com/golang/go/src go1.16 sync/Cond#
65 wwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#wwait. syncscip-go gomod github.com/golang/go/src go1.16 sync/.Condscip-go gomod github.com/golang/go/src go1.16 sync/Cond#
66 bscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#b. Bufferscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Buffer#
67 rerrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rerr. error // if reader closed, error to give writes
68 werrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#werr. error // if writer closed, error to give reads
69 }
70
71 func newBufferedPipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/newBufferedPipe().(buf Bufferscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Buffer#) *bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe# {
72 s := &bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#{
73 bscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#b.: buf,
74 }
75 s.rwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rwait..Lscip-go gomod github.com/golang/go/src go1.16 sync/Cond#L. = &s.lscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#l.
76 s.wwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#wwait..Lscip-go gomod github.com/golang/go/src go1.16 sync/Cond#L. = &s.lscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#l.
77 return s
78 }
79
80 func emptyscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/empty().(buf Bufferscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Buffer#) bool {
81 return buf.Lenscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Buffer#Len.() == 0
82 }
83
84 func gapscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/gap().(buf Bufferscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Buffer#) int64 {
85 return buf.Capscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Buffer#Cap.() - buf.Lenscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Buffer#Len.()
86 }
87
88 func (r *PipeReaderscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#) Readscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#Read().(p []byte) (n int, err error) {
89 r.rlscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rl..Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().()
90 defer r.rlscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rl..Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().()
91
92 r.lscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#l..Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().()
93 defer r.wwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#wwait..Signalscip-go gomod github.com/golang/go/src go1.16 sync/Cond#Signal().()
94 defer r.lscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#l..Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().()
95
96 for emptyscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/empty().(r.bscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#b.) {
97 if r.rerrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rerr. != nil {
98 return 0, ioscip-go gomod github.com/golang/go/src go1.16 io/.ErrClosedPipescip-go gomod github.com/golang/go/src go1.16 io/ErrClosedPipe.
99 }
100
101 if r.werrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#werr. != nil {
102 return 0, r.werrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#werr.
103 }
104
105 r.wwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#wwait..Signalscip-go gomod github.com/golang/go/src go1.16 sync/Cond#Signal().()
106 r.rwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rwait..Waitscip-go gomod github.com/golang/go/src go1.16 sync/Cond#Wait().()
107 }
108
109 n, err = r.bscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#b..Readscip-go gomod github.com/golang/go/src go1.16 io/Reader#Read().(p)
110 if err == ioscip-go gomod github.com/golang/go/src go1.16 io/.EOFscip-go gomod github.com/golang/go/src go1.16 io/EOF. {
111 err = nil
112 }
113
114 return n, err
115 }
116
117 func (w *PipeWriterscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#) Writescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#Write().(p []byte) (int, error) {
118 var m int
119 var n, space int64
120 var err error
121 sliceLen := int64(len(p))
122
123 w.wlscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#wl..Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().()
124 defer w.wlscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#wl..Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().()
125
126 w.lscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#l..Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().()
127 defer w.rwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rwait..Signalscip-go gomod github.com/golang/go/src go1.16 sync/Cond#Signal().()
128 defer w.lscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#l..Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().()
129
130 if w.werrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#werr. != nil {
131 return 0, ioscip-go gomod github.com/golang/go/src go1.16 io/.ErrClosedPipescip-go gomod github.com/golang/go/src go1.16 io/ErrClosedPipe.
132 }
133
134 // while there is data to write
135 for writeLen := sliceLen; writeLen > 0 && err == nil; writeLen = sliceLen - n {
136
137 // wait for some buffer space to become available (while no errs)
138 for space = gapscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/gap().(w.bscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#b.); space == 0 && w.rerrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rerr. == nil && w.werrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#werr. == nil; space = gapscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/gap().(w.bscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#b.) {
139 w.rwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rwait..Signalscip-go gomod github.com/golang/go/src go1.16 sync/Cond#Signal().()
140 w.wwaitscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#wwait..Waitscip-go gomod github.com/golang/go/src go1.16 sync/Cond#Wait().()
141 }
142
143 if w.rerrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rerr. != nil {
144 err = w.rerrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#rerr.
145 break
146 }
147
148 if w.werrscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#werr. != nil {
149 err = ioscip-go gomod github.com/golang/go/src go1.16 io/.ErrClosedPipescip-go gomod github.com/golang/go/src go1.16 io/ErrClosedPipe.
150 break
151 }
152
153 // space > 0, and locked
154
155 var nn int64
156 if space < writeLen {
157 // => writeLen - space > 0
158 // => (sliceLen - n) - space > 0
159 // => sliceLen > n + space
160 // nn is safe to use for p[:nn]
161 nn = n + space
162 } else {
163 nn = sliceLen
164 }
165
166 m, err = w.bscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/bufpipe#b..Writescip-go gomod github.com/golang/go/src go1.16 io/Writer#Write().(p[n:nn])
167 n += int64(m)
168
169 // one of the following cases has occurred:
170 // 1. done writing -> writeLen == 0
171 // 2. ran out of buffer space -> gap(w.b) == 0
172 // 3. an error occurred err != nil
173 // all of these cases are handled at the top of this loop
174 }
175
176 return int(n), err
177 }