1
- use std:: { cell:: RefCell , os :: unix :: prelude :: AsRawFd , ptr, sync:: Mutex , time:: Instant } ;
1
+ use std:: { cell:: RefCell , ptr, sync:: Mutex , time:: Instant } ;
2
2
3
3
#[ cfg( target_os = "macos" ) ]
4
4
use copypasta:: osx_clipboard:: OSXClipboardContext ;
@@ -11,10 +11,9 @@ use copypasta::{
11
11
x11_clipboard:: { Clipboard , X11ClipboardContext } ,
12
12
} ;
13
13
14
- use futures:: future:: FutureExt ;
15
14
use libc:: { c_void, fd_set, pselect, sigset_t, timespec} ;
16
15
use once_cell:: sync:: Lazy ;
17
- use tokio:: { io :: unix :: AsyncFd , io :: Interest , runtime:: Runtime , time:: Duration } ;
16
+ use tokio:: { runtime:: Runtime , time:: Duration } ;
18
17
#[ cfg( all( feature = "wayland" , not( any( target_os = "macos" , windows) ) ) ) ]
19
18
use winit:: platform:: unix:: EventLoopWindowTargetExtUnix ;
20
19
use winit:: {
@@ -26,14 +25,14 @@ use winit::{
26
25
window:: WindowId ,
27
26
} ;
28
27
29
- use crate :: future:: batch_select;
30
-
31
28
use surfman:: Connection ;
32
29
use surfman:: SurfaceType ;
33
30
use webrender_surfman:: WebrenderSurfman ;
34
31
35
32
use lisp_types:: bindings:: { inhibit_window_system, thread_select} ;
36
33
34
+ use crate :: select:: tokio_select_fds;
35
+
37
36
pub type GUIEvent = Event < ' static , i32 > ;
38
37
39
38
#[ allow( dead_code) ]
@@ -177,7 +176,7 @@ pub static TOKIO_RUNTIME: Lazy<Mutex<Runtime>> =
177
176
178
177
pub static EVENT_BUFFER : Lazy < Mutex < Vec < GUIEvent > > > = Lazy :: new ( || Mutex :: new ( Vec :: new ( ) ) ) ;
179
178
180
- struct FdSet ( * mut fd_set ) ;
179
+ pub struct FdSet ( pub * mut fd_set ) ;
181
180
182
181
unsafe impl Send for FdSet { }
183
182
unsafe impl Sync for FdSet { }
@@ -190,7 +189,7 @@ impl FdSet {
190
189
}
191
190
}
192
191
193
- struct Timespec ( * mut timespec ) ;
192
+ pub struct Timespec ( pub * mut timespec ) ;
194
193
195
194
unsafe impl Send for Timespec { }
196
195
unsafe impl Sync for Timespec { }
@@ -293,87 +292,9 @@ pub extern "C" fn wr_select(
293
292
} ;
294
293
} ) ;
295
294
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 ( ( ) ) ;
377
298
378
- nfds as i32
299
+ return nfds_result . into_inner ( ) ;
379
300
}
0 commit comments