mirror of
https://github.com/rustdesk/qemu-display.git
synced 2025-07-01 23:35:36 +00:00
qemu-display: prepare for new_qmp() on unix
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
721962af92
commit
7708016f72
@ -126,16 +126,32 @@ impl<'d> Display<'d> {
|
|||||||
self.inner.peer_pid
|
self.inner.peer_pid
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(windows, feature = "qmp"))]
|
#[cfg(feature = "qmp")]
|
||||||
pub async fn new_qmp<P: AsRef<std::path::Path>>(path: P) -> Result<Display<'d>> {
|
pub async fn new_qmp<P: AsRef<std::path::Path>>(path: P) -> Result<Display<'d>> {
|
||||||
#![allow(non_snake_case, non_camel_case_types)]
|
|
||||||
|
|
||||||
use crate::win32::{duplicate_socket, unix_stream_get_peer_pid};
|
|
||||||
use qapi::{qmp, Qmp};
|
use qapi::{qmp, Qmp};
|
||||||
|
|
||||||
|
let stream = UnixStream::connect(path)?;
|
||||||
|
let mut qmp = Qmp::from_stream(&stream);
|
||||||
|
let _info = qmp.handshake()?;
|
||||||
|
|
||||||
|
let (p0, p1) = UnixStream::pair()?;
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
// FIXME: no ancillary fd API at this point
|
||||||
|
// https://github.com/rust-lang/rust/issues/76915
|
||||||
|
qmp.execute(&qmp::getfd {
|
||||||
|
fdname: "fdname".into(),
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
#[cfg(windows)]
|
||||||
|
let pid = {
|
||||||
|
use crate::win32::{duplicate_socket, unix_stream_get_peer_pid};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::os::windows::io::AsRawSocket;
|
use std::os::windows::io::AsRawSocket;
|
||||||
use windows::Win32::Networking::WinSock::SOCKET;
|
use windows::Win32::Networking::WinSock::SOCKET;
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct get_win32_socket {
|
pub struct get_win32_socket {
|
||||||
#[serde(rename = "info")]
|
#[serde(rename = "info")]
|
||||||
@ -152,18 +168,16 @@ impl<'d> Display<'d> {
|
|||||||
type Ok = qapi::Empty;
|
type Ok = qapi::Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
let stream = UnixStream::connect(path)?;
|
|
||||||
let pid = unix_stream_get_peer_pid(&stream)?;
|
let pid = unix_stream_get_peer_pid(&stream)?;
|
||||||
let mut qmp = Qmp::from_stream(&stream);
|
|
||||||
let _info = qmp.handshake()?;
|
|
||||||
|
|
||||||
let (p0, p1) = UnixStream::pair()?;
|
|
||||||
let info = duplicate_socket(pid, SOCKET(p0.as_raw_socket() as _))?;
|
let info = duplicate_socket(pid, SOCKET(p0.as_raw_socket() as _))?;
|
||||||
let info = base64::encode(info);
|
let info = base64::encode(info);
|
||||||
qmp.execute(&get_win32_socket {
|
qmp.execute(&get_win32_socket {
|
||||||
info,
|
info,
|
||||||
fdname: "fdname".into(),
|
fdname: "fdname".into(),
|
||||||
})?;
|
})?;
|
||||||
|
pid
|
||||||
|
};
|
||||||
|
|
||||||
qmp.execute(&qmp::add_client {
|
qmp.execute(&qmp::add_client {
|
||||||
skipauth: None,
|
skipauth: None,
|
||||||
tls: None,
|
tls: None,
|
||||||
@ -176,7 +190,13 @@ impl<'d> Display<'d> {
|
|||||||
.build()
|
.build()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Self::new(&conn, Option::<String>::None, pid).await
|
Self::new(
|
||||||
|
&conn,
|
||||||
|
Option::<String>::None,
|
||||||
|
#[cfg(windows)]
|
||||||
|
pid,
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn receive_owner_changed(&self) -> Result<OwnerChangedStream<'_>> {
|
pub async fn receive_owner_changed(&self) -> Result<OwnerChangedStream<'_>> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user