@@ -888,6 +888,39 @@ where
888
888
}
889
889
}
890
890
891
+ #[ cfg( unix) ]
892
+ #[ cfg_attr( docsrs, doc( cfg( unix) ) ) ]
893
+ // rustdoc-stripper-ignore-next
894
+ /// Adds a closure to be called by the main loop the returned `Source` is attached to whenever a
895
+ /// UNIX file descriptor reaches the given IO condition.
896
+ ///
897
+ /// `func` will be called repeatedly with `priority` while the file descriptor matches the given IO condition
898
+ /// until it returns `ControlFlow::Break`.
899
+ ///
900
+ /// The default main loop almost always is the main loop of the main thread.
901
+ /// Thus, the closure is called on the main thread.
902
+ #[ doc( alias = "g_unix_fd_add_full" ) ]
903
+ pub fn unix_fd_add_full < F > (
904
+ fd : RawFd ,
905
+ priority : Priority ,
906
+ condition : IOCondition ,
907
+ func : F ,
908
+ ) -> SourceId
909
+ where
910
+ F : FnMut ( RawFd , IOCondition ) -> ControlFlow + Send + ' static ,
911
+ {
912
+ unsafe {
913
+ from_glib ( ffi:: g_unix_fd_add_full (
914
+ priority. into_glib ( ) ,
915
+ fd,
916
+ condition. into_glib ( ) ,
917
+ Some ( trampoline_unix_fd :: < F > ) ,
918
+ into_raw_unix_fd ( func) ,
919
+ Some ( destroy_closure_unix_fd :: < F > ) ,
920
+ ) )
921
+ }
922
+ }
923
+
891
924
#[ cfg( unix) ]
892
925
#[ cfg_attr( docsrs, doc( cfg( unix) ) ) ]
893
926
// rustdoc-stripper-ignore-next
@@ -926,6 +959,49 @@ where
926
959
}
927
960
}
928
961
962
+ #[ cfg( unix) ]
963
+ #[ cfg_attr( docsrs, doc( cfg( unix) ) ) ]
964
+ // rustdoc-stripper-ignore-next
965
+ /// Adds a closure to be called by the main loop the returned `Source` is attached to whenever a
966
+ /// UNIX file descriptor reaches the given IO condition.
967
+ ///
968
+ /// `func` will be called repeatedly with `priority` while the file descriptor matches the given IO condition
969
+ /// until it returns `ControlFlow::Break`.
970
+ ///
971
+ /// The default main loop almost always is the main loop of the main thread.
972
+ /// Thus, the closure is called on the main thread.
973
+ ///
974
+ /// Different to `unix_fd_add()`, this does not require `func` to be
975
+ /// `Send` but can only be called from the thread that owns the main context.
976
+ ///
977
+ /// This function panics if called from a different thread than the one that
978
+ /// owns the main context.
979
+ #[ doc( alias = "g_unix_fd_add_full" ) ]
980
+ pub fn unix_fd_add_local_full < F > (
981
+ fd : RawFd ,
982
+ priority : Priority ,
983
+ condition : IOCondition ,
984
+ func : F ,
985
+ ) -> SourceId
986
+ where
987
+ F : FnMut ( RawFd , IOCondition ) -> ControlFlow + ' static ,
988
+ {
989
+ unsafe {
990
+ let context = MainContext :: default ( ) ;
991
+ let _acquire = context
992
+ . acquire ( )
993
+ . expect ( "default main context already acquired by another thread" ) ;
994
+ from_glib ( ffi:: g_unix_fd_add_full (
995
+ priority. into_glib ( ) ,
996
+ fd,
997
+ condition. into_glib ( ) ,
998
+ Some ( trampoline_unix_fd_local :: < F > ) ,
999
+ into_raw_unix_fd_local ( func) ,
1000
+ Some ( destroy_closure_unix_fd_local :: < F > ) ,
1001
+ ) )
1002
+ }
1003
+ }
1004
+
929
1005
// rustdoc-stripper-ignore-next
930
1006
/// The priority of sources
931
1007
#[ derive( Clone , Copy , Debug , Eq , PartialEq , Ord , PartialOrd ) ]
0 commit comments