@@ -253,10 +253,6 @@ impl smoltcp::phy::TxToken for TxToken<'_> {
253
253
// Thus, we bypass the Drop implementation that would do that prematurely and let the call to poll in the next
254
254
// call to this function return the capacity.
255
255
let mut token = ManuallyDrop :: new ( self ) ;
256
- // We need to poll to get the queue to remove elements from the table and make space for
257
- // what we are about to add
258
- * token. send_capacity += token. send_vqs . poll ( ) * u32:: from ( BUFF_PER_PACKET ) ;
259
-
260
256
assert ! ( len <= usize :: try_from( token. send_vqs. buf_size) . unwrap( ) ) ;
261
257
let mut packet = Vec :: with_capacity_in ( len, DeviceAlloc ) ;
262
258
let result = unsafe {
@@ -428,9 +424,10 @@ impl smoltcp::phy::Device for VirtioNetDriver {
428
424
& mut self ,
429
425
_timestamp : smoltcp:: time:: Instant ,
430
426
) -> Option < ( Self :: RxToken < ' _ > , Self :: TxToken < ' _ > ) > {
431
- if self . inner . recv_vqs . has_packet ( )
432
- && self . inner . send_capacity >= u32:: from ( BUFF_PER_PACKET )
433
- {
427
+ if self . inner . recv_vqs . has_packet ( ) && {
428
+ self . free_up_send_capacity ( ) ;
429
+ self . inner . send_capacity >= u32:: from ( BUFF_PER_PACKET )
430
+ } {
434
431
self . inner . send_capacity -= u32:: from ( BUFF_PER_PACKET ) ;
435
432
Some ( (
436
433
RxToken {
@@ -449,6 +446,7 @@ impl smoltcp::phy::Device for VirtioNetDriver {
449
446
}
450
447
451
448
fn transmit ( & mut self , _timestamp : smoltcp:: time:: Instant ) -> Option < Self :: TxToken < ' _ > > {
449
+ self . free_up_send_capacity ( ) ;
452
450
if self . inner . send_capacity >= u32:: from ( BUFF_PER_PACKET ) {
453
451
self . inner . send_capacity -= u32:: from ( BUFF_PER_PACKET ) ;
454
452
Some ( TxToken {
@@ -609,6 +607,11 @@ impl VirtioNetDriver<Init> {
609
607
610
608
Some ( ( ip_header_len, csum_offset) )
611
609
}
610
+
611
+ fn free_up_send_capacity ( & mut self ) {
612
+ // We need to poll to get the queue to remove elements from the table and open up capacity if possible.
613
+ self . inner . send_capacity += self . inner . send_vqs . poll ( ) * u32:: from ( BUFF_PER_PACKET ) ;
614
+ }
612
615
}
613
616
614
617
impl VirtioNetDriver < Uninit > {
0 commit comments