Skip to content

Commit cdc4e9b

Browse files
committed
Windows Failing test
1 parent 02445a0 commit cdc4e9b

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/rust/src/demuxer/demux.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@ impl CcxDemuxer<'_> {
139139
if self.infd != -1 && ccx_options.input_source == DataSource::File {
140140
// Convert raw fd to Rust File to handle closing
141141
#[cfg(unix)]
142-
let file = unsafe { File::from_raw_fd(self.infd) };
143-
drop(file); // This closes the file descriptor
144-
self.infd = -1;
145-
ccx_options.activity_input_file_closed();
142+
{
143+
let file = unsafe { File::from_raw_fd(self.infd) };
144+
drop(file); // This closes the file descriptor
145+
self.infd = -1;
146+
ccx_options.activity_input_file_closed();
147+
}
146148
#[cfg(windows)]
147149
{
148150
let file = unsafe { File::from_raw_handle(self.infd as _) };
@@ -371,8 +373,11 @@ mod tests {
371373
use serial_test::serial;
372374
use std::fs::OpenOptions;
373375
use std::io::Write;
376+
#[cfg(unix)]
374377
use std::os::fd::AsRawFd;
375378
use std::os::raw::{c_char, c_int, c_uint};
379+
#[cfg(windows)]
380+
use std::os::windows::io::AsRawHandle;
376381
use std::slice;
377382
use std::sync::Once;
378383
use tempfile::NamedTempFile;
@@ -641,7 +646,10 @@ mod tests {
641646
let size = metadata.len();
642647

643648
// Get the raw file descriptor.
649+
#[cfg(unix)]
644650
let fd = tmpfile.as_file().as_raw_fd();
651+
#[cfg(windows)]
652+
let fd = tmpfile.as_file().as_raw_handle();
645653
(tmpfile, fd, size)
646654
}
647655

src/rust/src/file_functions/file.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ pub unsafe fn buffered_read_opt(
301301
// buffered - if here, then it must be files.
302302
if !buffer_ptr.is_null() {
303303
// Read
304+
#[cfg(unix)]
304305
let mut file = File::from_raw_fd(ctx.infd);
306+
#[cfg(windows)]
307+
let mut file = File::from_raw_handle(ctx.infd as _);
305308
let slice = slice::from_raw_parts_mut(buffer_ptr, bytes);
306309
match file.read(slice) {
307310
Ok(n) => i = n as isize,
@@ -317,7 +320,10 @@ pub unsafe fn buffered_read_opt(
317320
buffer_ptr = buffer_ptr.add(i as usize);
318321
} else {
319322
// Seek
323+
#[cfg(unix)]
320324
let mut file = File::from_raw_fd(ctx.infd);
325+
#[cfg(windows)]
326+
let mut file = File::from_raw_handle(ctx.infd as _);
321327
let mut op = file.stream_position().unwrap_or(i64::MAX as u64) as i64; // Get current pos
322328
if op == i64::MAX {
323329
op = -1;
@@ -387,7 +393,10 @@ pub unsafe fn buffered_read_opt(
387393
let i = if ccx_options.input_source == DataSource::File
388394
|| ccx_options.input_source == DataSource::Stdin
389395
{
396+
#[cfg(unix)]
390397
let mut file = File::from_raw_fd(ctx.infd);
398+
#[cfg(windows)]
399+
let mut file = File::from_raw_handle(ctx.infd as _);
391400
let slice = slice::from_raw_parts_mut(
392401
ctx.filebuffer.add(keep as usize),
393402
FILEBUFFERSIZE - keep as usize,
@@ -467,7 +476,10 @@ pub unsafe fn buffered_read_opt(
467476
let mut buffer_ptr = buffer;
468477
let mut i;
469478
while bytes > 0 && ctx.infd != -1 {
479+
#[cfg(unix)]
470480
let mut file = File::from_raw_fd(ctx.infd);
481+
#[cfg(windows)]
482+
let mut file = File::from_raw_handle(ctx.infd as _);
471483
let slice = slice::from_raw_parts_mut(buffer_ptr, bytes);
472484
i = file.read(slice).unwrap_or(i64::MAX as usize) as isize;
473485
if i == i64::MAX as usize as isize {
@@ -508,7 +520,10 @@ pub unsafe fn buffered_read_opt(
508520
if terminate_asap != 0 {
509521
break;
510522
}
523+
#[cfg(unix)]
511524
let mut file = File::from_raw_fd(ctx.infd);
525+
#[cfg(windows)]
526+
let mut file = File::from_raw_handle(ctx.infd as _);
512527

513528
// Try to get current position and seek
514529
let op_result = file.stream_position(); // Get current pos
@@ -789,16 +804,18 @@ pub unsafe fn buffered_skip(ctx: *mut CcxDemuxer, bytes: u32, ccx_options: &mut
789804
#[cfg(test)]
790805
mod tests {
791806
use super::*;
807+
use crate::libccxr_exports::demuxer::copy_demuxer_from_rust_to_c;
792808
use lib_ccxr::common::{Codec, StreamMode, StreamType};
793809
use lib_ccxr::util::log::{set_logger, CCExtractorLogger, DebugMessageMask, OutputTarget};
794-
use std::ffi::CString;
795-
// use std::io::{Seek, SeekFrom, Write};
796-
use crate::libccxr_exports::demuxer::copy_demuxer_from_rust_to_c;
797810
use serial_test::serial;
811+
use std::ffi::CString;
798812
#[cfg(feature = "sanity_check")]
799813
use std::io::Write;
800814
use std::os::raw::{c_char, c_int, c_ulong, c_void};
815+
#[cfg(unix)]
801816
use std::os::unix::io::IntoRawFd;
817+
#[cfg(windows)]
818+
use std::os::windows::io::IntoRawHandle;
802819
use std::slice;
803820
use std::sync::Once;
804821
#[cfg(feature = "sanity_check")]

0 commit comments

Comments
 (0)