1- use std:: { cell:: RefCell , os :: unix :: prelude :: AsRawFd , ptr, sync:: Mutex , time:: Instant } ;
1+ use std:: { cell:: RefCell , ptr, sync:: Mutex , time:: Instant } ;
22
33#[ cfg( target_os = "macos" ) ]
44use copypasta:: osx_clipboard:: OSXClipboardContext ;
@@ -11,10 +11,9 @@ use copypasta::{
1111 x11_clipboard:: { Clipboard , X11ClipboardContext } ,
1212} ;
1313
14- use futures:: future:: FutureExt ;
1514use libc:: { c_void, fd_set, pselect, sigset_t, timespec} ;
1615use once_cell:: sync:: Lazy ;
17- use tokio:: { io :: unix :: AsyncFd , io :: Interest , runtime:: Runtime , time:: Duration } ;
16+ use tokio:: { runtime:: Runtime , time:: Duration } ;
1817#[ cfg( all( feature = "wayland" , not( any( target_os = "macos" , windows) ) ) ) ]
1918use winit:: platform:: unix:: EventLoopWindowTargetExtUnix ;
2019use winit:: {
@@ -26,14 +25,14 @@ use winit::{
2625 window:: WindowId ,
2726} ;
2827
29- use crate :: future:: batch_select;
30-
3128use surfman:: Connection ;
3229use surfman:: SurfaceType ;
3330use webrender_surfman:: WebrenderSurfman ;
3431
3532use lisp_types:: bindings:: { inhibit_window_system, thread_select} ;
3633
34+ use crate :: select:: tokio_select_fds;
35+
3736pub type GUIEvent = Event < ' static , i32 > ;
3837
3938#[ allow( dead_code) ]
@@ -177,7 +176,7 @@ pub static TOKIO_RUNTIME: Lazy<Mutex<Runtime>> =
177176
178177pub static EVENT_BUFFER : Lazy < Mutex < Vec < GUIEvent > > > = Lazy :: new ( || Mutex :: new ( Vec :: new ( ) ) ) ;
179178
180- struct FdSet ( * mut fd_set ) ;
179+ pub struct FdSet ( pub * mut fd_set ) ;
181180
182181unsafe impl Send for FdSet { }
183182unsafe impl Sync for FdSet { }
@@ -190,7 +189,7 @@ impl FdSet {
190189 }
191190}
192191
193- struct Timespec ( * mut timespec ) ;
192+ pub struct Timespec ( pub * mut timespec ) ;
194193
195194unsafe impl Send for Timespec { }
196195unsafe impl Sync for Timespec { }
@@ -293,87 +292,9 @@ pub extern "C" fn wr_select(
293292 } ;
294293 } ) ;
295294
296- return nfds_result. into_inner ( ) ;
297- }
298-
299- fn fd_set_to_async_fds ( nfds : i32 , fds : & FdSet , interest : Interest ) -> Vec < AsyncFd < i32 > > {
300- if fds. 0 == ptr:: null_mut ( ) {
301- return Vec :: new ( ) ;
302- }
303-
304- let mut async_fds = Vec :: new ( ) ;
305-
306- for fd in 0 ..nfds {
307- unsafe {
308- if libc:: FD_ISSET ( fd, fds. 0 ) {
309- let async_fd_result = AsyncFd :: with_interest ( fd, interest) ;
310- if async_fd_result. is_err ( ) {
311- println ! ( "AsyncFd err: {:?}" , async_fd_result. unwrap_err( ) ) ;
312- continue ;
313- }
314-
315- async_fds. push ( async_fd_result. unwrap ( ) )
316- }
317- }
318- }
319-
320- async_fds
321- }
322-
323- fn async_fds_to_fd_set ( fds : Vec < i32 > , fd_set : & FdSet ) {
324- if fd_set. 0 == ptr:: null_mut ( ) {
325- return ;
326- }
327-
328- unsafe { libc:: FD_ZERO ( fd_set. 0 ) }
329-
330- for f in fds {
331- unsafe { libc:: FD_SET ( f, fd_set. 0 ) }
332- }
333- }
334-
335- async fn tokio_select_fds (
336- nfds : i32 ,
337- readfds : & FdSet ,
338- writefds : & FdSet ,
339- _timeout : & Timespec ,
340- ) -> i32 {
341- let read_fds = fd_set_to_async_fds ( nfds, readfds, Interest :: READABLE ) ;
342- let write_fds = fd_set_to_async_fds ( nfds, writefds, Interest :: WRITABLE ) ;
343-
344- let mut fd_futures = Vec :: new ( ) ;
345-
346- for f in read_fds. iter ( ) {
347- fd_futures. push ( f. readable ( ) . boxed ( ) )
348- }
349-
350- for f in write_fds. iter ( ) {
351- fd_futures. push ( f. writable ( ) . boxed ( ) )
352- }
353-
354- let read_fds_count = read_fds. len ( ) ;
355-
356- let readliness = batch_select ( fd_futures) . await ;
357-
358- let mut readable_result = Vec :: new ( ) ;
359- let mut writable_result = Vec :: new ( ) ;
360-
361- for ( result, index) in readliness {
362- if result. is_err ( ) {
363- continue ;
364- }
365-
366- if index < read_fds_count {
367- readable_result. push ( read_fds[ index] . as_raw_fd ( ) )
368- } else {
369- writable_result. push ( write_fds[ index - read_fds_count] . as_raw_fd ( ) )
370- }
371- }
372-
373- let nfds = readable_result. len ( ) + writable_result. len ( ) ;
374-
375- async_fds_to_fd_set ( readable_result, readfds) ;
376- async_fds_to_fd_set ( writable_result, writefds) ;
295+ // stop tokio select
296+ #[ cfg( target_os = "macos" ) ]
297+ let _ = select_stop_sender. send ( ( ) ) ;
377298
378- nfds as i32
299+ return nfds_result . into_inner ( ) ;
379300}
0 commit comments