@@ -85,6 +85,10 @@ impl Socket {
85
85
}
86
86
}
87
87
88
+ pub trait SocketLookup {
89
+ fn get ( & mut self , addr : SocketAddr ) -> & mut Socket ;
90
+ }
91
+
88
92
/// Loops around `process` while it returns `Output::Datagram`. While looping,
89
93
/// batch together returned datagrams with the same length, destination and TOS
90
94
/// byte into GSO-sized chunks and send them when the batch is full. If we
@@ -95,8 +99,8 @@ impl Socket {
95
99
/// introduces a lot of unnecessary memory copies. It would be better to extend
96
100
/// this with something like https://github.com/mozilla/neqo/pull/2138, where
97
101
/// the stack directly writes into the GSO buffer.
98
- pub async fn process_send < ' a > (
99
- mut socket : impl FnMut ( SocketAddr ) -> & ' a mut Socket ,
102
+ pub async fn process_send (
103
+ mut socket_lookup : impl SocketLookup ,
100
104
mut process : impl FnMut ( ) -> Output ,
101
105
timeout : & mut Option < Pin < Box < Sleep > > > ,
102
106
) -> Result < ( ) , io:: Error > {
@@ -111,7 +115,7 @@ pub async fn process_send<'a>(
111
115
if ( send || exit) && !batch_data. is_empty ( ) {
112
116
let meta = batch_meta. clone ( ) . unwrap ( ) ;
113
117
// Send all collected datagrams as GSO-sized chunks.
114
- let socket = socket ( meta. source ( ) ) ;
118
+ let socket = socket_lookup . get ( meta. source ( ) ) ;
115
119
for gso_chunk in batch_data. chunks ( socket. max_gso_segments ( ) * meta. len ( ) ) {
116
120
// Optimistically attempt sending datagram. In case the OS
117
121
// buffer is full, wait till socket is writable then try again.
0 commit comments