@@ -76,46 +76,44 @@ fn main() {
7676 }
7777 }
7878
79- {
80- let socket = iface. get_socket :: < TcpSocket > ( tcp_handle) ;
79+ let socket = iface. get_socket :: < TcpSocket > ( tcp_handle) ;
8180
82- state = match state {
83- State :: Connect if !socket. is_active ( ) => {
84- debug ! ( "connecting" ) ;
85- let local_port = 49152 + rand:: random :: < u16 > ( ) % 16384 ;
86- socket
87- . connect ( ( address, url. port ( ) . unwrap_or ( 80 ) ) , local_port)
88- . unwrap ( ) ;
89- State :: Request
90- }
91- State :: Request if socket. may_send ( ) => {
92- debug ! ( "sending request" ) ;
93- let http_get = "GET " . to_owned ( ) + url. path ( ) + " HTTP/1.1\r \n " ;
94- socket. send_slice ( http_get. as_ref ( ) ) . expect ( "cannot send" ) ;
95- let http_host = "Host: " . to_owned ( ) + url. host_str ( ) . unwrap ( ) + "\r \n " ;
96- socket. send_slice ( http_host. as_ref ( ) ) . expect ( "cannot send" ) ;
97- socket
98- . send_slice ( b"Connection: close\r \n " )
99- . expect ( "cannot send" ) ;
100- socket. send_slice ( b"\r \n " ) . expect ( "cannot send" ) ;
101- State :: Response
102- }
103- State :: Response if socket. can_recv ( ) => {
104- socket
105- . recv ( |data| {
106- println ! ( "{}" , str :: from_utf8( data) . unwrap_or( "(invalid utf8)" ) ) ;
107- ( data. len ( ) , ( ) )
108- } )
109- . unwrap ( ) ;
110- State :: Response
111- }
112- State :: Response if !socket. may_recv ( ) => {
113- debug ! ( "received complete response" ) ;
114- break ;
115- }
116- _ => state,
81+ state = match state {
82+ State :: Connect if !socket. is_active ( ) => {
83+ debug ! ( "connecting" ) ;
84+ let local_port = 49152 + rand:: random :: < u16 > ( ) % 16384 ;
85+ socket
86+ . connect ( ( address, url. port ( ) . unwrap_or ( 80 ) ) , local_port)
87+ . unwrap ( ) ;
88+ State :: Request
11789 }
118- }
90+ State :: Request if socket. may_send ( ) => {
91+ debug ! ( "sending request" ) ;
92+ let http_get = "GET " . to_owned ( ) + url. path ( ) + " HTTP/1.1\r \n " ;
93+ socket. send_slice ( http_get. as_ref ( ) ) . expect ( "cannot send" ) ;
94+ let http_host = "Host: " . to_owned ( ) + url. host_str ( ) . unwrap ( ) + "\r \n " ;
95+ socket. send_slice ( http_host. as_ref ( ) ) . expect ( "cannot send" ) ;
96+ socket
97+ . send_slice ( b"Connection: close\r \n " )
98+ . expect ( "cannot send" ) ;
99+ socket. send_slice ( b"\r \n " ) . expect ( "cannot send" ) ;
100+ State :: Response
101+ }
102+ State :: Response if socket. can_recv ( ) => {
103+ socket
104+ . recv ( |data| {
105+ println ! ( "{}" , str :: from_utf8( data) . unwrap_or( "(invalid utf8)" ) ) ;
106+ ( data. len ( ) , ( ) )
107+ } )
108+ . unwrap ( ) ;
109+ State :: Response
110+ }
111+ State :: Response if !socket. may_recv ( ) => {
112+ debug ! ( "received complete response" ) ;
113+ break ;
114+ }
115+ _ => state,
116+ } ;
119117
120118 phy_wait ( fd, iface. poll_delay ( timestamp) ) . expect ( "wait error" ) ;
121119 }
0 commit comments