@@ -71,6 +71,11 @@ impl<T: Read + Write> HttpConnection<T> {
71
71
/// Tries to read new bytes from the stream and automatically update the request.
72
72
/// Meant to be used only with non-blocking streams and an `EPOLL` structure.
73
73
/// Should be called whenever an `EPOLLIN` event is signaled.
74
+ ///
75
+ /// # Errors
76
+ /// `StreamError` is returned when an IO operation fails.
77
+ /// `ConnectionClosed` is returned when a client prematurely closes the connection.
78
+ /// `ParseError` is returned when a parsing operation fails.
74
79
pub fn try_read ( & mut self ) -> Result < ( ) , ConnectionError > {
75
80
// Read some bytes from the stream, which will be appended to what is already
76
81
// present in the buffer from a previous call of `try_read`. There are already
@@ -293,6 +298,12 @@ impl<T: Read + Write> HttpConnection<T> {
293
298
/// Tries to write the first available response to the provided stream.
294
299
/// Meant to be used only with non-blocking streams and an `EPOLL` structure.
295
300
/// Should be called whenever an `EPOLLOUT` event is signaled.
301
+ ///
302
+ /// # Errors
303
+ /// `StreamError` is returned when an IO operation fails.
304
+ /// `ConnectionClosed` is returned when trying to write on a closed connection.
305
+ /// `InvalidWrite` is returned when trying to write on a connection with an
306
+ /// empty outgoing buffer.
296
307
pub fn try_write ( & mut self ) -> Result < ( ) , ConnectionError > {
297
308
if self . response_buffer . is_none ( ) {
298
309
if let Some ( response) = self . response_queue . pop_front ( ) {
@@ -357,10 +368,16 @@ impl<T: Read + Write> HttpConnection<T> {
357
368
self . read_cursor = end_cursor - line_start_index;
358
369
}
359
370
360
- /// Returns the first parsed request in the queue.
371
+ /// Returns the first parsed request in the queue or `None` if the queue
372
+ /// is empty.
361
373
pub fn pop_parsed_request ( & mut self ) -> Option < Request > {
362
374
self . parsed_requests . pop_front ( )
363
375
}
376
+
377
+ /// Returns `true` if there are bytes waiting to be written into the stream.
378
+ pub fn pending_write ( & self ) -> bool {
379
+ self . response_buffer . is_some ( ) || !self . response_queue . is_empty ( )
380
+ }
364
381
}
365
382
366
383
#[ cfg( test) ]
0 commit comments