@@ -5,7 +5,7 @@ use std::time::Instant;
5
5
6
6
use futures:: { Poll , Async , AsyncSink , Stream , Sink , StartSend } ;
7
7
use futures:: task:: Task ;
8
- use tokio :: io :: Io ;
8
+ use tokio_io :: { AsyncRead , AsyncWrite } ;
9
9
use tokio_proto:: streaming:: pipeline:: { Frame , Transport } ;
10
10
11
11
use header:: { ContentLength , TransferEncoding } ;
@@ -16,7 +16,7 @@ use version::HttpVersion;
16
16
17
17
18
18
/// This handles a connection, which will have been established over an
19
- /// `Io ` (like a socket), and will likely include multiple
19
+ /// `AsyncRead + AsyncWrite ` (like a socket), and will likely include multiple
20
20
/// `Transaction`s over HTTP.
21
21
///
22
22
/// The connection will determine when a message begins and ends as well as
@@ -29,7 +29,7 @@ pub struct Conn<I, B, T, K = KA> {
29
29
}
30
30
31
31
impl < I , B , T , K > Conn < I , B , T , K >
32
- where I : Io ,
32
+ where I : AsyncRead + AsyncWrite ,
33
33
B : AsRef < [ u8 ] > ,
34
34
T : Http1Transaction ,
35
35
K : KeepAlive
@@ -155,7 +155,7 @@ where I: Io,
155
155
}
156
156
157
157
fn maybe_park_read ( & mut self ) {
158
- if self . io . poll_read ( ) . is_ready ( ) {
158
+ if ! self . io . is_read_blocked ( ) {
159
159
// the Io object is ready to read, which means it will never alert
160
160
// us that it is ready until we drain it. However, we're currently
161
161
// finished reading, so we need to park the task to be able to
@@ -350,7 +350,7 @@ where I: Io,
350
350
}
351
351
352
352
impl < I , B , T , K > Stream for Conn < I , B , T , K >
353
- where I : Io ,
353
+ where I : AsyncRead + AsyncWrite ,
354
354
B : AsRef < [ u8 ] > ,
355
355
T : Http1Transaction ,
356
356
K : KeepAlive ,
@@ -385,7 +385,7 @@ where I: Io,
385
385
}
386
386
387
387
impl < I , B , T , K > Sink for Conn < I , B , T , K >
388
- where I : Io ,
388
+ where I : AsyncRead + AsyncWrite ,
389
389
B : AsRef < [ u8 ] > ,
390
390
T : Http1Transaction ,
391
391
K : KeepAlive ,
@@ -450,10 +450,15 @@ where I: Io,
450
450
trace ! ( "Conn::flush = {:?}" , ret) ;
451
451
ret
452
452
}
453
+
454
+ fn close( & mut self ) -> Poll <( ) , Self :: SinkError > {
455
+ try_ready ! ( self . poll_complete( ) ) ;
456
+ self . io . io_mut ( ) . shutdown ( )
457
+ }
453
458
}
454
459
455
460
impl < I , B , T , K > Transport for Conn < I , B , T , K >
456
- where I : Io + ' static ,
461
+ where I : AsyncRead + AsyncWrite + ' static ,
457
462
B : AsRef < [ u8 ] > + ' static ,
458
463
T : Http1Transaction + ' static ,
459
464
K : KeepAlive + ' static ,
@@ -665,6 +670,7 @@ impl<'a, T: fmt::Debug + 'a, B: AsRef<[u8]> + 'a> fmt::Debug for DebugFrame<'a,
665
670
#[ cfg( test) ]
666
671
mod tests {
667
672
use futures:: { Async , Future , Stream , Sink } ;
673
+ use futures:: future;
668
674
use tokio_proto:: streaming:: pipeline:: Frame ;
669
675
670
676
use http:: { self , MessageHead , ServerTransaction } ;
@@ -705,7 +711,7 @@ mod tests {
705
711
706
712
#[ test]
707
713
fn test_conn_parse_partial( ) {
708
- let _: Result < ( ) , ( ) > = :: futures :: lazy( || {
714
+ let _: Result < ( ) , ( ) > = future :: lazy( || {
709
715
let good_message = b"GET / HTTP/1.1\r \n Host: foo.bar\r \n \r \n " . to_vec ( ) ;
710
716
let io = AsyncIo :: new_buf ( good_message, 10 ) ;
711
717
let mut conn = Conn :: < _ , http:: Chunk , ServerTransaction > :: new ( io, Default :: default ( ) ) ;
@@ -772,7 +778,7 @@ mod tests {
772
778
773
779
#[ test]
774
780
fn test_conn_body_write_length ( ) {
775
- let _: Result < ( ) , ( ) > = :: futures :: lazy ( || {
781
+ let _: Result < ( ) , ( ) > = future :: lazy ( || {
776
782
let io = AsyncIo :: new_buf ( vec ! [ ] , 0 ) ;
777
783
let mut conn = Conn :: < _ , http:: Chunk , ServerTransaction > :: new ( io, Default :: default ( ) ) ;
778
784
let max = :: http:: io:: MAX_BUFFER_SIZE + 4096 ;
@@ -800,7 +806,7 @@ mod tests {
800
806
801
807
#[ test]
802
808
fn test_conn_body_write_chunked ( ) {
803
- let _: Result < ( ) , ( ) > = :: futures :: lazy ( || {
809
+ let _: Result < ( ) , ( ) > = future :: lazy ( || {
804
810
let io = AsyncIo :: new_buf ( vec ! [ ] , 4096 ) ;
805
811
let mut conn = Conn :: < _ , http:: Chunk , ServerTransaction > :: new ( io, Default :: default ( ) ) ;
806
812
conn. state . writing = Writing :: Body ( Encoder :: chunked ( ) , None ) ;
@@ -813,7 +819,7 @@ mod tests {
813
819
814
820
#[ test]
815
821
fn test_conn_body_flush ( ) {
816
- let _: Result < ( ) , ( ) > = :: futures :: lazy ( || {
822
+ let _: Result < ( ) , ( ) > = future :: lazy ( || {
817
823
let io = AsyncIo :: new_buf ( vec ! [ ] , 1024 * 1024 * 5 ) ;
818
824
let mut conn = Conn :: < _ , http:: Chunk , ServerTransaction > :: new ( io, Default :: default ( ) ) ;
819
825
conn. state . writing = Writing :: Body ( Encoder :: length ( 1024 * 1024 ) , None ) ;
@@ -829,7 +835,7 @@ mod tests {
829
835
#[ test]
830
836
fn test_conn_parking ( ) {
831
837
use std:: sync:: Arc ;
832
- use futures:: task :: Unpark ;
838
+ use futures:: executor :: Unpark ;
833
839
834
840
struct Car {
835
841
permit : bool ,
@@ -847,7 +853,7 @@ mod tests {
847
853
}
848
854
849
855
// test that once writing is done, unparks
850
- let f = :: futures :: lazy ( || {
856
+ let f = future :: lazy ( || {
851
857
let io = AsyncIo :: new_buf ( vec ! [ ] , 4096 ) ;
852
858
let mut conn = Conn :: < _ , http:: Chunk , ServerTransaction > :: new ( io, Default :: default ( ) ) ;
853
859
conn. state . reading = Reading :: KeepAlive ;
@@ -861,7 +867,7 @@ mod tests {
861
867
862
868
863
869
// test that flushing when not waiting on read doesn't unpark
864
- let f = :: futures :: lazy ( || {
870
+ let f = future :: lazy ( || {
865
871
let io = AsyncIo :: new_buf ( vec ! [ ] , 4096 ) ;
866
872
let mut conn = Conn :: < _ , http:: Chunk , ServerTransaction > :: new ( io, Default :: default ( ) ) ;
867
873
conn. state . writing = Writing :: KeepAlive ;
@@ -872,7 +878,7 @@ mod tests {
872
878
873
879
874
880
// test that flushing and writing isn't done doesn't unpark
875
- let f = :: futures :: lazy ( || {
881
+ let f = future :: lazy ( || {
876
882
let io = AsyncIo :: new_buf ( vec ! [ ] , 4096 ) ;
877
883
let mut conn = Conn :: < _ , http:: Chunk , ServerTransaction > :: new ( io, Default :: default ( ) ) ;
878
884
conn. state . reading = Reading :: KeepAlive ;
0 commit comments