File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ mod shared;
1414pub mod stream;
1515pub mod uvc;
1616
17- use nix:: errno:: Errno ;
17+ use nix:: { errno:: Errno , libc } ;
1818use pixel_format:: PixelFormat ;
1919use std:: {
2020 fmt,
@@ -86,11 +86,24 @@ impl Device {
8686 ///
8787 /// If the path does not refer to a V4L2 device node, an error will be returned.
8888 pub fn open < A : AsRef < Path > > ( path : A ) -> io:: Result < Self > {
89- Self :: open_impl ( path. as_ref ( ) )
89+ Self :: open_impl ( path. as_ref ( ) , true )
9090 }
9191
92- fn open_impl ( path : & Path ) -> io:: Result < Self > {
93- let file = OpenOptions :: new ( ) . read ( true ) . write ( true ) . open ( path) ?;
92+ /// Opens a V4L2 device file from the given path.
93+ ///
94+ /// If the path does not refer to a V4L2 device node, an error will be returned.
95+ pub fn open_non_blocking < A : AsRef < Path > > ( path : A ) -> io:: Result < Self > {
96+ Self :: open_impl ( path. as_ref ( ) , false )
97+ }
98+
99+ fn open_impl ( path : & Path , blocking : bool ) -> io:: Result < Self > {
100+ let mut open_options = OpenOptions :: new ( ) ;
101+ open_options. read ( true ) . write ( true ) ;
102+ if !blocking {
103+ open_options. custom_flags ( libc:: O_NONBLOCK ) ;
104+ }
105+ let file = open_options. open ( path) ?;
106+
94107 let mut this = Self {
95108 file,
96109 available_capabilities : CapabilityFlags :: empty ( ) ,
You can’t perform that action at this time.
0 commit comments