@@ -141,11 +141,11 @@ macro_rules! with {
141
141
( $ref: ident, $mut: ident, $type: ty, $http: ident, $expr: expr) => {
142
142
#[ inline( always) ]
143
143
#[ allow( dead_code) ]
144
- pub ( crate ) fn $mut<T >( key: usize , f: impl FnOnce ( & mut $type) -> T ) -> T {
144
+ pub ( crate ) fn $mut<T >( key: u32 , f: impl FnOnce ( & mut $type) -> T ) -> T {
145
145
SLAB . with( |slab| {
146
146
let mut borrow = slab. borrow_mut( ) ;
147
147
#[ allow( unused_mut) ] // TODO(mmastrac): compiler issue?
148
- let mut $http = match borrow. get_mut( key) {
148
+ let mut $http = match borrow. get_mut( key as usize ) {
149
149
Some ( http) => http,
150
150
None => panic!(
151
151
"Attemped to access invalid request {} ({} in total available)" ,
@@ -163,10 +163,10 @@ macro_rules! with {
163
163
164
164
#[ inline( always) ]
165
165
#[ allow( dead_code) ]
166
- pub ( crate ) fn $ref<T >( key: usize , f: impl FnOnce ( & $type) -> T ) -> T {
166
+ pub ( crate ) fn $ref<T >( key: u32 , f: impl FnOnce ( & $type) -> T ) -> T {
167
167
SLAB . with( |slab| {
168
168
let borrow = slab. borrow( ) ;
169
- let $http = borrow. get( key) . unwrap( ) ;
169
+ let $http = borrow. get( key as usize ) . unwrap( ) ;
170
170
#[ cfg( __zombie_http_tracking) ]
171
171
if !$http. alive {
172
172
panic!( "Attempted to access a dead HTTP object" )
@@ -211,7 +211,7 @@ with!(with_http, with_http_mut, HttpSlabRecord, http, http);
211
211
fn slab_insert (
212
212
request : Request ,
213
213
request_info : HttpConnectionProperties ,
214
- ) -> usize {
214
+ ) -> u32 {
215
215
SLAB . with ( |slab| {
216
216
let ( request_parts, request_body) = request. into_parts ( ) ;
217
217
slab. borrow_mut ( ) . insert ( HttpSlabRecord {
@@ -224,7 +224,7 @@ fn slab_insert(
224
224
#[ cfg( __zombie_http_tracking) ]
225
225
alive : true ,
226
226
} )
227
- } )
227
+ } ) as u32
228
228
}
229
229
230
230
#[ op]
@@ -233,7 +233,7 @@ pub fn op_upgrade_raw(_index: usize) {}
233
233
#[ op]
234
234
pub async fn op_upgrade (
235
235
state : Rc < RefCell < OpState > > ,
236
- index : usize ,
236
+ index : u32 ,
237
237
headers : Vec < ( ByteString , ByteString ) > ,
238
238
) -> Result < ( ResourceId , ZeroCopyBuf ) , AnyError > {
239
239
// Stage 1: set the respnse to 101 Switching Protocols and send it
@@ -273,8 +273,8 @@ pub async fn op_upgrade(
273
273
) )
274
274
}
275
275
276
- #[ op]
277
- pub fn op_set_promise_complete ( index : usize , status : u16 ) {
276
+ #[ op( fast ) ]
277
+ pub fn op_set_promise_complete ( index : u32 , status : u16 ) {
278
278
with_resp_mut ( index, |resp| {
279
279
// The Javascript code will never provide a status that is invalid here (see 23_response.js)
280
280
* resp. as_mut ( ) . unwrap ( ) . status_mut ( ) =
@@ -287,7 +287,7 @@ pub fn op_set_promise_complete(index: usize, status: u16) {
287
287
288
288
#[ op]
289
289
pub fn op_get_request_method_and_url (
290
- index : usize ,
290
+ index : u32 ,
291
291
) -> ( String , Option < String > , String , String , Option < u16 > ) {
292
292
// TODO(mmastrac): Passing method can be optimized
293
293
with_http ( index, |http| {
@@ -314,15 +314,15 @@ pub fn op_get_request_method_and_url(
314
314
}
315
315
316
316
#[ op]
317
- pub fn op_get_request_header ( index : usize , name : String ) -> Option < ByteString > {
317
+ pub fn op_get_request_header ( index : u32 , name : String ) -> Option < ByteString > {
318
318
with_req ( index, |req| {
319
319
let value = req. headers . get ( name) ;
320
320
value. map ( |value| value. as_bytes ( ) . into ( ) )
321
321
} )
322
322
}
323
323
324
324
#[ op]
325
- pub fn op_get_request_headers ( index : usize ) -> Vec < ( ByteString , ByteString ) > {
325
+ pub fn op_get_request_headers ( index : u32 ) -> Vec < ( ByteString , ByteString ) > {
326
326
with_req ( index, |req| {
327
327
let headers = & req. headers ;
328
328
let mut vec = Vec :: with_capacity ( headers. len ( ) ) ;
@@ -356,8 +356,8 @@ pub fn op_get_request_headers(index: usize) -> Vec<(ByteString, ByteString)> {
356
356
} )
357
357
}
358
358
359
- #[ op]
360
- pub fn op_read_request_body ( state : & mut OpState , index : usize ) -> ResourceId {
359
+ #[ op( fast ) ]
360
+ pub fn op_read_request_body ( state : & mut OpState , index : u32 ) -> ResourceId {
361
361
let incoming = with_req_body_mut ( index, |body| body. take ( ) . unwrap ( ) ) ;
362
362
let body_resource = Rc :: new ( HttpRequestBody :: new ( incoming) ) ;
363
363
let res = state. resource_table . add_rc ( body_resource. clone ( ) ) ;
@@ -367,24 +367,20 @@ pub fn op_read_request_body(state: &mut OpState, index: usize) -> ResourceId {
367
367
res
368
368
}
369
369
370
- #[ op]
371
- pub fn op_set_response_header (
372
- index : usize ,
373
- name : ByteString ,
374
- value : ByteString ,
375
- ) {
370
+ #[ op( fast) ]
371
+ pub fn op_set_response_header ( index : u32 , name : & str , value : & str ) {
376
372
with_resp_mut ( index, |resp| {
377
373
let resp_headers = resp. as_mut ( ) . unwrap ( ) . headers_mut ( ) ;
378
374
// These are valid latin-1 strings
379
- let name = HeaderName :: from_bytes ( & name) . unwrap ( ) ;
380
- let value = HeaderValue :: from_bytes ( & value) . unwrap ( ) ;
375
+ let name = HeaderName :: from_bytes ( name. as_bytes ( ) ) . unwrap ( ) ;
376
+ let value = HeaderValue :: from_bytes ( value. as_bytes ( ) ) . unwrap ( ) ;
381
377
resp_headers. append ( name, value) ;
382
378
} ) ;
383
379
}
384
380
385
381
#[ op]
386
382
pub fn op_set_response_headers (
387
- index : usize ,
383
+ index : u32 ,
388
384
headers : Vec < ( ByteString , ByteString ) > ,
389
385
) {
390
386
// TODO(mmastrac): Invalid headers should be handled?
@@ -400,10 +396,10 @@ pub fn op_set_response_headers(
400
396
} )
401
397
}
402
398
403
- #[ op]
399
+ #[ op( fast ) ]
404
400
pub fn op_set_response_body_resource (
405
401
state : & mut OpState ,
406
- index : usize ,
402
+ index : u32 ,
407
403
stream_rid : ResourceId ,
408
404
auto_close : bool ,
409
405
) -> Result < ( ) , AnyError > {
@@ -426,10 +422,10 @@ pub fn op_set_response_body_resource(
426
422
Ok ( ( ) )
427
423
}
428
424
429
- #[ op]
425
+ #[ op( fast ) ]
430
426
pub fn op_set_response_body_stream (
431
427
state : & mut OpState ,
432
- index : usize ,
428
+ index : u32 ,
433
429
) -> Result < ResourceId , AnyError > {
434
430
// TODO(mmastrac): what should this channel size be?
435
431
let ( tx, rx) = tokio:: sync:: mpsc:: channel ( 1 ) ;
@@ -445,8 +441,8 @@ pub fn op_set_response_body_stream(
445
441
Ok ( state. resource_table . add ( tx) )
446
442
}
447
443
448
- #[ op]
449
- pub fn op_set_response_body_text ( index : usize , text : String ) {
444
+ #[ op( fast ) ]
445
+ pub fn op_set_response_body_text ( index : u32 , text : String ) {
450
446
if !text. is_empty ( ) {
451
447
with_resp_mut ( index, move |response| {
452
448
response
@@ -458,23 +454,23 @@ pub fn op_set_response_body_text(index: usize, text: String) {
458
454
}
459
455
}
460
456
461
- #[ op]
462
- pub fn op_set_response_body_bytes ( index : usize , buffer : ZeroCopyBuf ) {
457
+ #[ op( fast ) ]
458
+ pub fn op_set_response_body_bytes ( index : u32 , buffer : & [ u8 ] ) {
463
459
if !buffer. is_empty ( ) {
464
460
with_resp_mut ( index, |response| {
465
461
response
466
462
. as_mut ( )
467
463
. unwrap ( )
468
464
. body_mut ( )
469
- . initialize ( ResponseBytesInner :: Bytes ( BufView :: from ( buffer) ) )
465
+ . initialize ( ResponseBytesInner :: Bytes ( BufView :: from ( buffer. to_vec ( ) ) ) )
470
466
} ) ;
471
467
} ;
472
468
}
473
469
474
470
#[ op]
475
471
pub async fn op_http_track (
476
472
state : Rc < RefCell < OpState > > ,
477
- index : usize ,
473
+ index : u32 ,
478
474
server_rid : ResourceId ,
479
475
) -> Result < ( ) , AnyError > {
480
476
let handle = with_resp ( index, |resp| {
@@ -496,12 +492,12 @@ pub async fn op_http_track(
496
492
}
497
493
498
494
#[ pin_project( PinnedDrop ) ]
499
- pub struct SlabFuture < F : Future < Output = ( ) > > ( usize , #[ pin] F ) ;
495
+ pub struct SlabFuture < F : Future < Output = ( ) > > ( u32 , #[ pin] F ) ;
500
496
501
497
pub fn new_slab_future (
502
498
request : Request ,
503
499
request_info : HttpConnectionProperties ,
504
- tx : tokio:: sync:: mpsc:: Sender < usize > ,
500
+ tx : tokio:: sync:: mpsc:: Sender < u32 > ,
505
501
) -> SlabFuture < impl Future < Output = ( ) > > {
506
502
let index = slab_insert ( request, request_info) ;
507
503
let rx = with_promise ( index, |promise| promise. clone ( ) ) ;
@@ -521,11 +517,11 @@ impl<F: Future<Output = ()>> PinnedDrop for SlabFuture<F> {
521
517
SLAB . with ( |slab| {
522
518
#[ cfg( __zombie_http_tracking) ]
523
519
{
524
- slab. borrow_mut ( ) . get_mut ( self . 0 ) . unwrap ( ) . alive = false ;
520
+ slab. borrow_mut ( ) . get_mut ( self . 0 as usize ) . unwrap ( ) . alive = false ;
525
521
}
526
522
#[ cfg( not( __zombie_http_tracking) ) ]
527
523
{
528
- slab. borrow_mut ( ) . remove ( self . 0 ) ;
524
+ slab. borrow_mut ( ) . remove ( self . 0 as usize ) ;
529
525
}
530
526
} ) ;
531
527
}
@@ -589,7 +585,7 @@ fn serve_https(
589
585
mut io : TlsStream ,
590
586
request_info : HttpConnectionProperties ,
591
587
cancel : RcRef < CancelHandle > ,
592
- tx : tokio:: sync:: mpsc:: Sender < usize > ,
588
+ tx : tokio:: sync:: mpsc:: Sender < u32 > ,
593
589
) -> JoinHandle < Result < ( ) , AnyError > > {
594
590
// TODO(mmastrac): This is faster if we can use tokio::spawn but then the send bounds get us
595
591
let svc = service_fn ( move |req : Request | {
@@ -614,7 +610,7 @@ fn serve_http(
614
610
io : impl HttpServeStream ,
615
611
request_info : HttpConnectionProperties ,
616
612
cancel : RcRef < CancelHandle > ,
617
- tx : tokio:: sync:: mpsc:: Sender < usize > ,
613
+ tx : tokio:: sync:: mpsc:: Sender < u32 > ,
618
614
) -> JoinHandle < Result < ( ) , AnyError > > {
619
615
// TODO(mmastrac): This is faster if we can use tokio::spawn but then the send bounds get us
620
616
let svc = service_fn ( move |req : Request | {
@@ -627,7 +623,7 @@ fn serve_http_on(
627
623
network_stream : NetworkStream ,
628
624
listen_properties : & HttpListenProperties ,
629
625
cancel : RcRef < CancelHandle > ,
630
- tx : tokio:: sync:: mpsc:: Sender < usize > ,
626
+ tx : tokio:: sync:: mpsc:: Sender < u32 > ,
631
627
) -> JoinHandle < Result < ( ) , AnyError > > {
632
628
// We always want some sort of peer address. If we can't get one, just make up one.
633
629
let peer_address = network_stream. peer_address ( ) . unwrap_or_else ( |_| {
@@ -659,7 +655,7 @@ fn serve_http_on(
659
655
struct HttpJoinHandle (
660
656
AsyncRefCell < Option < JoinHandle < Result < ( ) , AnyError > > > > ,
661
657
CancelHandle ,
662
- AsyncRefCell < tokio:: sync:: mpsc:: Receiver < usize > > ,
658
+ AsyncRefCell < tokio:: sync:: mpsc:: Receiver < u32 > > ,
663
659
) ;
664
660
665
661
impl HttpJoinHandle {
@@ -798,7 +794,7 @@ pub async fn op_http_wait(
798
794
799
795
// Do we have a request?
800
796
if let Some ( req) = next {
801
- return Ok ( req as u32 ) ;
797
+ return Ok ( req) ;
802
798
}
803
799
804
800
// No - we're shutting down
0 commit comments