@@ -184,9 +184,13 @@ impl<E> PollEvented<E> {
184
184
match self . readiness . load ( Ordering :: SeqCst ) & bits {
185
185
0 => {
186
186
if mask. is_writable ( ) {
187
- self . need_write ( ) ;
187
+ if self . need_write ( ) . is_err ( ) {
188
+ return Async :: Ready ( mask)
189
+ }
188
190
} else {
189
- self . need_read ( ) ;
191
+ if self . need_read ( ) . is_err ( ) {
192
+ return Async :: Ready ( mask)
193
+ }
190
194
}
191
195
Async :: NotReady
192
196
}
@@ -213,14 +217,22 @@ impl<E> PollEvented<E> {
213
217
/// previously indicated that the object is readable. That is, this function
214
218
/// must always be paired with calls to `poll_read` previously.
215
219
///
220
+ /// # Errors
221
+ ///
222
+ /// This function will return an error if the `Core` that this `PollEvented`
223
+ /// is associated with has gone away (been destroyed). The error means that
224
+ /// the ambient futures task could not be scheduled to receive a
225
+ /// notification and typically means that the error should be propagated
226
+ /// outwards.
227
+ ///
216
228
/// # Panics
217
229
///
218
230
/// This function will panic if called outside the context of a future's
219
231
/// task.
220
- pub fn need_read ( & self ) {
232
+ pub fn need_read ( & self ) -> io :: Result < ( ) > {
221
233
let bits = super :: ready2usize ( super :: read_ready ( ) ) ;
222
234
self . readiness . fetch_and ( !bits, Ordering :: SeqCst ) ;
223
- self . token . schedule_read ( ) ;
235
+ self . token . schedule_read ( )
224
236
}
225
237
226
238
/// Indicates to this source of events that the corresponding I/O object is
@@ -239,14 +251,22 @@ impl<E> PollEvented<E> {
239
251
/// previously indicated that the object is writable. That is, this function
240
252
/// must always be paired with calls to `poll_write` previously.
241
253
///
254
+ /// # Errors
255
+ ///
256
+ /// This function will return an error if the `Core` that this `PollEvented`
257
+ /// is associated with has gone away (been destroyed). The error means that
258
+ /// the ambient futures task could not be scheduled to receive a
259
+ /// notification and typically means that the error should be propagated
260
+ /// outwards.
261
+ ///
242
262
/// # Panics
243
263
///
244
264
/// This function will panic if called outside the context of a future's
245
265
/// task.
246
- pub fn need_write ( & self ) {
266
+ pub fn need_write ( & self ) -> io :: Result < ( ) > {
247
267
let bits = super :: ready2usize ( Ready :: writable ( ) ) ;
248
268
self . readiness . fetch_and ( !bits, Ordering :: SeqCst ) ;
249
- self . token . schedule_write ( ) ;
269
+ self . token . schedule_write ( )
250
270
}
251
271
252
272
/// Returns a reference to the event loop handle that this readiness stream
@@ -275,7 +295,7 @@ impl<E: Read> Read for PollEvented<E> {
275
295
}
276
296
let r = self . get_mut ( ) . read ( buf) ;
277
297
if is_wouldblock ( & r) {
278
- self . need_read ( ) ;
298
+ self . need_read ( ) ? ;
279
299
}
280
300
return r
281
301
}
@@ -288,7 +308,7 @@ impl<E: Write> Write for PollEvented<E> {
288
308
}
289
309
let r = self . get_mut ( ) . write ( buf) ;
290
310
if is_wouldblock ( & r) {
291
- self . need_write ( ) ;
311
+ self . need_write ( ) ? ;
292
312
}
293
313
return r
294
314
}
@@ -299,7 +319,7 @@ impl<E: Write> Write for PollEvented<E> {
299
319
}
300
320
let r = self . get_mut ( ) . flush ( ) ;
301
321
if is_wouldblock ( & r) {
302
- self . need_write ( ) ;
322
+ self . need_write ( ) ? ;
303
323
}
304
324
return r
305
325
}
@@ -323,7 +343,7 @@ impl<'a, E> Read for &'a PollEvented<E>
323
343
}
324
344
let r = self . get_ref ( ) . read ( buf) ;
325
345
if is_wouldblock ( & r) {
326
- self . need_read ( ) ;
346
+ self . need_read ( ) ? ;
327
347
}
328
348
return r
329
349
}
@@ -338,7 +358,7 @@ impl<'a, E> Write for &'a PollEvented<E>
338
358
}
339
359
let r = self . get_ref ( ) . write ( buf) ;
340
360
if is_wouldblock ( & r) {
341
- self . need_write ( ) ;
361
+ self . need_write ( ) ? ;
342
362
}
343
363
return r
344
364
}
@@ -349,7 +369,7 @@ impl<'a, E> Write for &'a PollEvented<E>
349
369
}
350
370
let r = self . get_ref ( ) . flush ( ) ;
351
371
if is_wouldblock ( & r) {
352
- self . need_write ( ) ;
372
+ self . need_write ( ) ? ;
353
373
}
354
374
return r
355
375
}
0 commit comments