Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package net | 5 package net |
6 | 6 |
7 import ( | 7 import ( |
8 "errors" | 8 "errors" |
9 "io" | 9 "io" |
10 "os" | 10 "os" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 mode int32 | 86 mode int32 |
87 errno int32 | 87 errno int32 |
88 qty uint32 | 88 qty uint32 |
89 | 89 |
90 errnoc chan error | 90 errnoc chan error |
91 fd *netFD | 91 fd *netFD |
92 } | 92 } |
93 | 93 |
94 func (o *anOp) Init(fd *netFD, mode int32) { | 94 func (o *anOp) Init(fd *netFD, mode int32) { |
95 o.fd = fd | 95 o.fd = fd |
96 » var i int | 96 » o.mode = mode |
97 » if mode == 'r' { | |
98 » » i = 0 | |
99 » } else { | |
100 » » i = 1 | |
101 » } | |
102 » if fd.errnoc[i] == nil { | |
103 » » fd.errnoc[i] = make(chan error) | |
104 » } | |
105 » o.errnoc = fd.errnoc[i] | |
106 o.runtimeCtx = fd.pd.runtimeCtx | 97 o.runtimeCtx = fd.pd.runtimeCtx |
107 » o.mode = mode | 98 » if !canCancelIO { |
99 » » var i int | |
100 » » if mode == 'r' { | |
101 » » » i = 0 | |
102 » » } else { | |
103 » » » i = 1 | |
104 » » } | |
105 » » if fd.errnoc[i] == nil { | |
106 » » » fd.errnoc[i] = make(chan error) | |
107 » » } | |
108 » » o.errnoc = fd.errnoc[i] | |
109 » } | |
108 } | 110 } |
109 | 111 |
110 func (o *anOp) Op() *anOp { | 112 func (o *anOp) Op() *anOp { |
111 return o | 113 return o |
112 } | 114 } |
113 | 115 |
114 // bufOp is used by IO operations that read / write | 116 // bufOp is used by IO operations that read / write |
115 // data from / to client buffer. | 117 // data from / to client buffer. |
116 type bufOp struct { | 118 type bufOp struct { |
117 anOp | 119 anOp |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 err := syscall.CancelIoEx(syscall.Handle(o.Op().fd.sysfd), &o.o) | 207 err := syscall.CancelIoEx(syscall.Handle(o.Op().fd.sysfd), &o.o) |
206 // Assuming ERROR_NOT_FOUND is returned, if IO is completed. | 208 // Assuming ERROR_NOT_FOUND is returned, if IO is completed. |
207 if err != nil && err != syscall.ERROR_NOT_FOUND { | 209 if err != nil && err != syscall.ERROR_NOT_FOUND { |
208 // TODO(brainman): maybe do something else, but panic. | 210 // TODO(brainman): maybe do something else, but panic. |
209 panic(err) | 211 panic(err) |
210 } | 212 } |
211 } else { | 213 } else { |
212 s.canchan <- oi | 214 s.canchan <- oi |
213 <-o.errnoc | 215 <-o.errnoc |
214 } | 216 } |
215 » // Wait for cancelation to complete. | 217 » // Wait for cancellation to complete. |
216 o.fd.pd.WaitCanceled(int(o.mode)) | 218 o.fd.pd.WaitCanceled(int(o.mode)) |
217 if o.errno != 0 { | 219 if o.errno != 0 { |
218 err = syscall.Errno(o.errno) | 220 err = syscall.Errno(o.errno) |
219 if err == syscall.ERROR_OPERATION_ABORTED { // IO Canceled | 221 if err == syscall.ERROR_OPERATION_ABORTED { // IO Canceled |
220 err = netpollErr | 222 err = netpollErr |
221 } | 223 } |
222 return 0, &OpError{oi.Name(), o.fd.net, o.fd.laddr, err} | 224 return 0, &OpError{oi.Name(), o.fd.net, o.fd.laddr, err} |
223 } | 225 } |
226 // We issued cancellation request. But, it seems, IO operation succeeded | |
227 // before cancellation request run. We need to treat IO operation as | |
228 // succeeded (the bytes are actually sent/recv from network). | |
224 return int(o.qty), nil | 229 return int(o.qty), nil |
dvyukov
2013/06/04 09:47:34
add a comment explaining that we've issued the can
brainman
2013/06/06 05:37:56
Done.
| |
225 } | 230 } |
226 | 231 |
227 // Start helper goroutines. | 232 // Start helper goroutines. |
228 var iosrv *ioSrv | 233 var iosrv *ioSrv |
229 var onceStartServer sync.Once | 234 var onceStartServer sync.Once |
230 | 235 |
231 func startServer() { | 236 func startServer() { |
232 iosrv = new(ioSrv) | 237 iosrv = new(ioSrv) |
233 if !canCancelIO { | 238 if !canCancelIO { |
234 // Only CancelIo API is available. Lets start special goroutine | 239 // Only CancelIo API is available. Lets start special goroutine |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 | 618 |
614 var errNoSupport = errors.New("address family not supported") | 619 var errNoSupport = errors.New("address family not supported") |
615 | 620 |
616 func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S ockaddr, err error) { | 621 func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S ockaddr, err error) { |
617 return 0, 0, 0, nil, errNoSupport | 622 return 0, 0, 0, nil, errNoSupport |
618 } | 623 } |
619 | 624 |
620 func (fd *netFD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oob n int, err error) { | 625 func (fd *netFD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oob n int, err error) { |
621 return 0, 0, errNoSupport | 626 return 0, 0, errNoSupport |
622 } | 627 } |
LEFT | RIGHT |