fix: win, file clipboard (#9243)

1. Return the result of `wait_response_event()` in
   `cliprdr_send_format_list()`
2. Add recv flags to avoid waiting a long time.

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2024-09-03 20:55:45 +08:00
committed by GitHub
parent d4377a13c5
commit ec28567362
4 changed files with 86 additions and 38 deletions

View File

@@ -5,7 +5,7 @@ use std::{
};
#[cfg(any(target_os = "windows", feature = "unix-file-copy-paste",))]
use hbb_common::{allow_err, log};
use hbb_common::{allow_err, bail};
use hbb_common::{
lazy_static,
tokio::sync::{
@@ -25,6 +25,8 @@ pub use context_send::*;
const ERR_CODE_SERVER_FUNCTION_NONE: u32 = 0x00000001;
#[cfg(target_os = "windows")]
const ERR_CODE_INVALID_PARAMETER: u32 = 0x00000002;
#[cfg(target_os = "windows")]
const ERR_CODE_SEND_MSG: u32 = 0x00000003;
pub(crate) use platform::create_cliprdr_context;
@@ -198,7 +200,7 @@ pub fn get_rx_cliprdr_server(conn_id: i32) -> Arc<TokioMutex<UnboundedReceiver<C
#[cfg(any(target_os = "windows", feature = "unix-file-copy-paste",))]
#[inline]
fn send_data(conn_id: i32, data: ClipboardFile) {
fn send_data(conn_id: i32, data: ClipboardFile) -> ResultType<()> {
#[cfg(target_os = "windows")]
return send_data_to_channel(conn_id, data);
#[cfg(not(target_os = "windows"))]
@@ -210,25 +212,28 @@ fn send_data(conn_id: i32, data: ClipboardFile) {
}
#[cfg(any(target_os = "windows", feature = "unix-file-copy-paste",))]
#[inline]
fn send_data_to_channel(conn_id: i32, data: ClipboardFile) {
// no need to handle result here
fn send_data_to_channel(conn_id: i32, data: ClipboardFile) -> ResultType<()> {
if let Some(msg_channel) = VEC_MSG_CHANNEL
.read()
.unwrap()
.iter()
.find(|x| x.conn_id == conn_id)
{
allow_err!(msg_channel.sender.send(data));
msg_channel.sender.send(data)?;
Ok(())
} else {
bail!("conn_id not found");
}
}
#[cfg(feature = "unix-file-copy-paste")]
#[inline]
fn send_data_to_all(data: ClipboardFile) {
// no need to handle result here
fn send_data_to_all(data: ClipboardFile) -> ResultType<()> {
// Need more tests to see if it's necessary to handle the error.
for msg_channel in VEC_MSG_CHANNEL.read().unwrap().iter() {
allow_err!(msg_channel.sender.send(data.clone()));
}
Ok(())
}
#[cfg(test)]