7
7
#![ allow( clippy:: future_not_send) ]
8
8
9
9
use std:: {
10
- borrow:: Cow ,
11
10
cell:: RefCell ,
12
- cmp:: min,
13
11
fmt:: { self , Display } ,
14
12
fs, io,
15
13
net:: { SocketAddr , ToSocketAddrs } ,
@@ -30,11 +28,10 @@ use neqo_crypto::{
30
28
constants:: { TLS_AES_128_GCM_SHA256 , TLS_AES_256_GCM_SHA384 , TLS_CHACHA20_POLY1305_SHA256 } ,
31
29
init_db, AntiReplay , Cipher ,
32
30
} ;
33
- use neqo_http3:: { Http3OrWebTransportStream , StreamId } ;
34
- use neqo_transport:: { server:: ConnectionRef , Output , RandomConnectionIdGenerator , Version } ;
31
+ use neqo_transport:: { Output , RandomConnectionIdGenerator , Version } ;
35
32
use tokio:: time:: Sleep ;
36
33
37
- use crate :: { SharedArgs , STREAM_IO_BUFFER_SIZE } ;
34
+ use crate :: SharedArgs ;
38
35
39
36
const ANTI_REPLAY_WINDOW : Duration = Duration :: from_secs ( 10 ) ;
40
37
@@ -409,89 +406,3 @@ pub async fn server(mut args: Args) -> Res<()> {
409
406
. run ( )
410
407
. await
411
408
}
412
-
413
- #[ derive( Debug ) ]
414
- struct ResponseData {
415
- data : Cow < ' static , [ u8 ] > ,
416
- offset : usize ,
417
- remaining : usize ,
418
- }
419
-
420
- impl From < & [ u8 ] > for ResponseData {
421
- fn from ( data : & [ u8 ] ) -> Self {
422
- Self :: from ( data. to_vec ( ) )
423
- }
424
- }
425
-
426
- impl From < Vec < u8 > > for ResponseData {
427
- fn from ( data : Vec < u8 > ) -> Self {
428
- let remaining = data. len ( ) ;
429
- Self {
430
- data : Cow :: Owned ( data) ,
431
- offset : 0 ,
432
- remaining,
433
- }
434
- }
435
- }
436
-
437
- impl From < & str > for ResponseData {
438
- fn from ( data : & str ) -> Self {
439
- Self :: from ( data. as_bytes ( ) )
440
- }
441
- }
442
-
443
- impl ResponseData {
444
- const fn zeroes ( total : usize ) -> Self {
445
- const MESSAGE : & [ u8 ] = & [ 0 ; STREAM_IO_BUFFER_SIZE ] ;
446
- Self {
447
- data : Cow :: Borrowed ( MESSAGE ) ,
448
- offset : 0 ,
449
- remaining : total,
450
- }
451
- }
452
-
453
- fn slice ( & self ) -> & [ u8 ] {
454
- let end = min ( self . data . len ( ) , self . offset + self . remaining ) ;
455
- & self . data [ self . offset ..end]
456
- }
457
-
458
- fn send_h3 ( & mut self , stream : & Http3OrWebTransportStream ) {
459
- while self . remaining > 0 {
460
- match stream. send_data ( self . slice ( ) ) {
461
- Ok ( 0 ) => {
462
- return ;
463
- }
464
- Ok ( sent) => {
465
- self . remaining -= sent;
466
- self . offset = ( self . offset + sent) % self . data . len ( ) ;
467
- }
468
- Err ( e) => {
469
- qwarn ! ( "Error writing to stream {}: {:?}" , stream, e) ;
470
- return ;
471
- }
472
- }
473
- }
474
- }
475
-
476
- fn send_h09 ( & mut self , stream_id : StreamId , conn : & ConnectionRef ) {
477
- while self . remaining > 0 {
478
- match conn
479
- . borrow_mut ( )
480
- . stream_send ( stream_id, self . slice ( ) )
481
- . unwrap ( )
482
- {
483
- 0 => {
484
- return ;
485
- }
486
- sent => {
487
- self . remaining -= sent;
488
- self . offset = ( self . offset + sent) % self . data . len ( ) ;
489
- }
490
- }
491
- }
492
- }
493
-
494
- const fn done ( & self ) -> bool {
495
- self . remaining == 0
496
- }
497
- }
0 commit comments