@@ -235,7 +235,8 @@ fn wake_socket_waker_by_ref(orig_ptr: *const ()) {
235
235
// fully write, but we only need to provide a write_event() once. Otherwise, the sending thread
236
236
// may have already gone away due to a socket close, in which case there's nothing to wake up
237
237
// anyway.
238
- let _ = unsafe { ( * descriptor) . write_avail . clone ( ) } . try_send ( ( ) ) ;
238
+ let mut us = unsafe { ( * descriptor) . conn . lock ( ) } . unwrap ( ) ;
239
+ let _ = us. write_avail . try_send ( ( ) ) ;
239
240
}
240
241
fn drop_socket_waker ( orig_ptr : * const ( ) ) {
241
242
let _orig_box = unsafe { Box :: from_raw ( orig_ptr as * mut SocketDescriptor ) } ;
@@ -249,19 +250,12 @@ fn descriptor_to_waker(descriptor: *const SocketDescriptor) -> task::RawWaker {
249
250
250
251
pub struct SocketDescriptor {
251
252
conn : Arc < Mutex < Connection > > ,
252
- // Ideally we'd just lock conn and push to the write_avail there, but sadly tokio calls our
253
- // waker irrespective of available space on the first poll_write call, which would result in a
254
- // deadlock, so instead we keep a copy in each SocketDescriptor.
255
- write_avail : mpsc:: Sender < ( ) > ,
256
253
id : u64 ,
257
254
}
258
255
impl SocketDescriptor {
259
256
fn new ( conn : Arc < Mutex < Connection > > ) -> Self {
260
- let ( id, write_avail) = {
261
- let us = conn. lock ( ) . unwrap ( ) ;
262
- ( us. id , us. write_avail . clone ( ) )
263
- } ;
264
- Self { conn, write_avail, id }
257
+ let id = conn. lock ( ) . unwrap ( ) . id ;
258
+ Self { conn, id }
265
259
}
266
260
}
267
261
impl peer_handler:: SocketDescriptor for SocketDescriptor {
@@ -329,7 +323,6 @@ impl Clone for SocketDescriptor {
329
323
fn clone ( & self ) -> Self {
330
324
Self {
331
325
conn : Arc :: clone ( & self . conn ) ,
332
- write_avail : self . write_avail . clone ( ) ,
333
326
id : self . id ,
334
327
}
335
328
}
0 commit comments