Skip to content

Commit 7abbdc9

Browse files
Call smb2_get_fd before each call to libc::poll
Just in case smb2 context somehow gets closed from underneath us.
1 parent e8e6190 commit 7abbdc9

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

libsmb2-rs/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,14 +404,19 @@ impl Smb {
404404
let cb_data_ptr = Box::into_raw(cb_data);
405405
smb2_notify_change_filehandle_async(ctx, fh, notify_flags.bits(), filter.bits(), 1, Some(smb_notify_change_callback), cb_data_ptr.cast::<c_void>());
406406

407-
let pfd = Box::new(libc::pollfd{
408-
fd: smb2_get_fd(ctx),
409-
events: 0,
410-
revents: 0,
411-
});
412-
let pfd_ptr = Box::into_raw(pfd);
413407
loop {
414-
(*pfd_ptr).events = smb2_which_events(ctx) as libc::c_short;
408+
let fd = smb2_get_fd(ctx);
409+
if fd < 0 {
410+
println!("Smb notify_change_async - bad fd returned from smb2_get_fd");
411+
break;
412+
}
413+
414+
let pfd = Box::new(libc::pollfd{
415+
fd,
416+
events: smb2_which_events(ctx) as libc::c_short,
417+
revents: 0,
418+
});
419+
let pfd_ptr = Box::into_raw(pfd);
415420
let ret = libc::poll(pfd_ptr, 1, 1000);
416421
if ret < 0 {
417422
println!("Smb notify_change_async - called libc::poll - ret = {:?}", ret);

0 commit comments

Comments
 (0)