fix(linux): process self-test capture instead of discarding it
Some checks failed
Desktop Release / Bootstrap updater signing key (push) Has been cancelled
Desktop Release / Windows x64 NSIS (push) Has been cancelled
Desktop Release / Linux x64 DEB + AppImage (push) Has been cancelled
Desktop Release / Publish public desktop release (push) Has been cancelled
Some checks failed
Desktop Release / Bootstrap updater signing key (push) Has been cancelled
Desktop Release / Windows x64 NSIS (push) Has been cancelled
Desktop Release / Linux x64 DEB + AppImage (push) Has been cancelled
Desktop Release / Publish public desktop release (push) Has been cancelled
This commit is contained in:
parent
231326caf8
commit
ba7014468b
@ -117,7 +117,11 @@ pub fn start(config: AppConfig, state: SharedState, app: AppHandle) -> Result<Ca
|
|||||||
.with_context(|| format!("bind test-capture sink {TEST_CAPTURE_SINK_ADDR}"))?;
|
.with_context(|| format!("bind test-capture sink {TEST_CAPTURE_SINK_ADDR}"))?;
|
||||||
sink.set_nonblocking(true)?;
|
sink.set_nonblocking(true)?;
|
||||||
let worker_stop = stop.clone();
|
let worker_stop = stop.clone();
|
||||||
handles.push(thread::spawn(move || test_capture_sink_loop(sink, worker_stop)));
|
let worker_state = state.clone();
|
||||||
|
let worker_app = app.clone();
|
||||||
|
handles.push(thread::spawn(move || {
|
||||||
|
test_capture_sink_loop(sink, worker_state, worker_app, worker_stop)
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if handles.is_empty() {
|
if handles.is_empty() {
|
||||||
@ -128,11 +132,18 @@ pub fn start(config: AppConfig, state: SharedState, app: AppHandle) -> Result<Ca
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn test_capture_sink_loop(listener: TcpListener, stop: Arc<AtomicBool>) {
|
fn test_capture_sink_loop(
|
||||||
|
listener: TcpListener,
|
||||||
|
state: SharedState,
|
||||||
|
app: AppHandle,
|
||||||
|
stop: Arc<AtomicBool>,
|
||||||
|
) {
|
||||||
while !stop.load(Ordering::SeqCst) {
|
while !stop.load(Ordering::SeqCst) {
|
||||||
match listener.accept() {
|
match listener.accept() {
|
||||||
Ok((stream, _)) => {
|
Ok((stream, _)) => {
|
||||||
thread::spawn(move || drain_test_capture_stream(stream));
|
let state = state.clone();
|
||||||
|
let app = app.clone();
|
||||||
|
thread::spawn(move || handle_test_capture_stream(stream, state, app));
|
||||||
}
|
}
|
||||||
Err(error) if error.kind() == ErrorKind::WouldBlock => {
|
Err(error) if error.kind() == ErrorKind::WouldBlock => {
|
||||||
thread::sleep(Duration::from_millis(80));
|
thread::sleep(Duration::from_millis(80));
|
||||||
@ -145,19 +156,43 @@ fn test_capture_sink_loop(listener: TcpListener, stop: Arc<AtomicBool>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn drain_test_capture_stream(mut stream: TcpStream) {
|
fn handle_test_capture_stream(mut stream: TcpStream, state: SharedState, app: AppHandle) {
|
||||||
let _ = stream.set_read_timeout(Some(Duration::from_secs(2)));
|
let _ = stream.set_read_timeout(Some(Duration::from_secs(2)));
|
||||||
|
let mut bytes = Vec::new();
|
||||||
let mut buffer = [0u8; 32 * 1024];
|
let mut buffer = [0u8; 32 * 1024];
|
||||||
loop {
|
loop {
|
||||||
match stream.read(&mut buffer) {
|
match stream.read(&mut buffer) {
|
||||||
Ok(0) => break,
|
Ok(0) => break,
|
||||||
Ok(_) => {}
|
Ok(read) => bytes.extend_from_slice(&buffer[..read]),
|
||||||
Err(error) if matches!(error.kind(), ErrorKind::WouldBlock | ErrorKind::TimedOut) => break,
|
Err(error) if matches!(error.kind(), ErrorKind::WouldBlock | ErrorKind::TimedOut) => break,
|
||||||
Err(_) => break,
|
Err(error) => {
|
||||||
|
process_payload(
|
||||||
|
&state,
|
||||||
|
&app,
|
||||||
|
"cups-test",
|
||||||
|
"FieldLens-Test-Capture".into(),
|
||||||
|
bytes,
|
||||||
|
false,
|
||||||
|
Some(format!("test capture read failed: {error}")),
|
||||||
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !bytes.is_empty() {
|
||||||
|
process_payload(
|
||||||
|
&state,
|
||||||
|
&app,
|
||||||
|
"cups-test",
|
||||||
|
"FieldLens-Test-Capture".into(),
|
||||||
|
bytes,
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn raw_proxy_loop(
|
fn raw_proxy_loop(
|
||||||
listener: TcpListener,
|
listener: TcpListener,
|
||||||
config: AppConfig,
|
config: AppConfig,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user