@@ -35,6 +35,10 @@ const MAX_DATAGRAM_SIZE: usize = 1350;
35
35
36
36
const HTTP_REQ_STREAM_ID : u64 = 4 ;
37
37
38
+ struct TestData {
39
+ num_messages : u8 ,
40
+ }
41
+
38
42
fn main ( ) {
39
43
let mut buf = [ 0 ; 65535 ] ;
40
44
let mut out = [ 0 ; MAX_DATAGRAM_SIZE ] ;
@@ -96,8 +100,8 @@ fn main() {
96
100
config. set_initial_max_data ( 10_000_000 ) ;
97
101
config. set_initial_max_stream_data_bidi_local ( 1_000_000 ) ;
98
102
config. set_initial_max_stream_data_bidi_remote ( 1_000_000 ) ;
99
- config. set_initial_max_streams_bidi ( 100 ) ;
100
- config. set_initial_max_streams_uni ( 100 ) ;
103
+ config. set_initial_max_streams_bidi ( 10000 ) ;
104
+ config. set_initial_max_streams_uni ( 10000 ) ;
101
105
config. set_disable_active_migration ( true ) ;
102
106
103
107
// Generate a random source connection ID for the connection.
@@ -198,46 +202,64 @@ fn main() {
198
202
199
203
// Send an HTTP request as soon as the connection is established.
200
204
if conn. is_established ( ) && !req_sent {
201
- info ! ( "sending HTTP request for {}" , url. path( ) ) ;
202
-
203
- let req = format ! ( "GET {}\r \n " , url. path( ) ) ;
204
- conn. stream_send ( HTTP_REQ_STREAM_ID , req. as_bytes ( ) , true )
205
- . unwrap ( ) ;
205
+ println ! ( "Init data" ) ;
206
+ // init application data
207
+ match conn. stream_send ( 0 , b"" , false ) {
208
+ Ok ( _) => { } ,
209
+ Err ( quiche:: Error :: Done ) => { } ,
210
+ Err ( e) => {
211
+ error ! ( "{} stream send failed {:?}" , conn. trace_id( ) , e) ;
212
+ return ;
213
+ } ,
214
+ } ;
215
+ match conn. stream_init_application_data ( 0 , TestData { num_messages : 0 } ) {
216
+ Ok ( _) => { } ,
217
+ Err ( quiche:: Error :: Done ) => { } ,
218
+ Err ( e) => {
219
+ error ! ( "{} stream init failed {:?}" , conn. trace_id( ) , e) ;
220
+ return ;
221
+ } ,
222
+ } ;
206
223
207
224
req_sent = true ;
208
225
}
209
226
210
227
// Process all readable streams.
211
228
for s in conn. readable ( ) {
212
229
while let Ok ( ( read, fin) ) = conn. stream_recv ( s, & mut buf) {
213
- debug ! ( "received {} bytes" , read) ;
230
+ println ! ( "received {} bytes" , read) ;
214
231
215
232
let stream_buf = & buf[ ..read] ;
216
233
217
- debug ! (
234
+ println ! (
218
235
"stream {} has {} bytes (fin? {})" ,
219
236
s,
220
237
stream_buf. len( ) ,
221
238
fin
222
239
) ;
223
240
224
- print ! ( "{}" , unsafe {
241
+ println ! ( "{}" , unsafe {
225
242
std:: str :: from_utf8_unchecked( stream_buf)
226
243
} ) ;
227
244
228
- // The server reported that it has no more data to send, which
229
- // we got the full response. Close the connection.
230
- if s == HTTP_REQ_STREAM_ID && fin {
231
- info ! (
232
- "response received in {:?}, closing..." ,
233
- req_start. elapsed( )
234
- ) ;
235
-
236
- conn. close ( true , 0x00 , b"kthxbye" ) . unwrap ( ) ;
237
- }
238
245
}
239
246
}
240
247
248
+ for s in conn. writable ( ) {
249
+ println ! ( "Writing stream {}" , s) ;
250
+ let written = match conn. stream_send ( s, b"Hello!" , true ) {
251
+ Ok ( v) => v,
252
+
253
+ Err ( quiche:: Error :: Done ) => 0 ,
254
+
255
+ Err ( e) => {
256
+ error ! ( "{} stream send failed {:?}" , conn. trace_id( ) , e) ;
257
+ return ;
258
+ } ,
259
+ } ;
260
+ println ! ( "Written {} bytes" , written) ;
261
+ }
262
+
241
263
// Generate outgoing QUIC packets and send them on the UDP socket, until
242
264
// quiche reports that there are no more packets to be sent.
243
265
loop {
0 commit comments