make rfb listen addr/port actually configurable
(also, actually fix the fake argv so that the listen applies.. Null termination!)
This commit is contained in:
parent
596839e4ed
commit
18b30f2148
2 changed files with 40 additions and 13 deletions
|
@ -9,7 +9,7 @@ use retro_frontend::{
|
||||||
use tracing::Level;
|
use tracing::Level;
|
||||||
use tracing_subscriber::FmtSubscriber;
|
use tracing_subscriber::FmtSubscriber;
|
||||||
|
|
||||||
use clap::{arg, command};
|
use clap::{arg, command, value_parser};
|
||||||
|
|
||||||
mod rfb;
|
mod rfb;
|
||||||
use rfb::*;
|
use rfb::*;
|
||||||
|
@ -139,6 +139,16 @@ fn main() -> Result<()> {
|
||||||
// Not that it matters, but this is only really required for cores that require
|
// Not that it matters, but this is only really required for cores that require
|
||||||
// content to be loaded; that's most cores, but libretro does support the difference.
|
// content to be loaded; that's most cores, but libretro does support the difference.
|
||||||
.arg(arg!(--rom <VALUE>).required(false))
|
.arg(arg!(--rom <VALUE>).required(false))
|
||||||
|
.arg(
|
||||||
|
arg!(--rfb_listen <ADDRESS>)
|
||||||
|
.required(false)
|
||||||
|
.default_value("127.0.0.1"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
arg!(--rfb_port <PORT>)
|
||||||
|
.value_parser(value_parser!(u16))
|
||||||
|
.required(true),
|
||||||
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let core_path: &String = matches.get_one("core").unwrap();
|
let core_path: &String = matches.get_one("core").unwrap();
|
||||||
|
@ -149,8 +159,11 @@ fn main() -> Result<()> {
|
||||||
// default WxH; this is overridden quickly
|
// default WxH; this is overridden quickly
|
||||||
width: 640,
|
width: 640,
|
||||||
height: 480,
|
height: 480,
|
||||||
listen_address: "127.0.0.1".parse::<Ipv4Addr>()?,
|
listen_address: matches
|
||||||
listen_port: 6930
|
.get_one::<String>("rfb_listen")
|
||||||
|
.unwrap()
|
||||||
|
.parse::<Ipv4Addr>()?,
|
||||||
|
listen_port: *matches.get_one::<u16>("rfb_port").unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initalize the app
|
// Initalize the app
|
||||||
|
|
|
@ -27,10 +27,12 @@ impl RfbServer {
|
||||||
|
|
||||||
let ip_string = std::ffi::CString::new(config.listen_address.to_string())?;
|
let ip_string = std::ffi::CString::new(config.listen_address.to_string())?;
|
||||||
|
|
||||||
|
info!("?? {:?}", ip_string);
|
||||||
|
|
||||||
let argc = 3;
|
let argc = 3;
|
||||||
let argv: [*const std::ffi::c_char; 3] = [
|
let argv: [*const std::ffi::c_char; 3] = [
|
||||||
b"RfbServer".as_ptr() as *const i8,
|
b"RfbServer\0".as_ptr() as *const i8,
|
||||||
b"-listen".as_ptr() as *const i8,
|
b"-listen\0".as_ptr() as *const i8,
|
||||||
ip_string.as_ptr(),
|
ip_string.as_ptr(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -64,9 +66,11 @@ impl RfbServer {
|
||||||
(*screen).newClientHook = Some(Self::connection_callback);
|
(*screen).newClientHook = Some(Self::connection_callback);
|
||||||
(*screen).kbdAddEvent = Some(Self::on_key_callback);
|
(*screen).kbdAddEvent = Some(Self::on_key_callback);
|
||||||
|
|
||||||
|
|
||||||
// testing
|
// testing
|
||||||
(*screen).port = config.listen_port as i32;
|
(*screen).port = config.listen_port as i32;
|
||||||
(*screen).ipv6port = 0;
|
(*screen).ipv6port = 0;
|
||||||
|
(*screen).deferUpdateTime = 16;
|
||||||
|
|
||||||
ret.resize(config.width, config.height);
|
ret.resize(config.width, config.height);
|
||||||
|
|
||||||
|
@ -93,14 +97,6 @@ impl RfbServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_buffer(&mut self, slice: &[u32], width: u16, height: u16) {
|
pub fn update_buffer(&mut self, slice: &[u32], width: u16, height: u16) {
|
||||||
// lame slow loop (dont use this sucks)
|
|
||||||
/*
|
|
||||||
for x in 0..width {
|
|
||||||
for y in 0..height {
|
|
||||||
self.framebuffer[(y * width + x) as usize] = slice[(y * width + x) as usize];
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
self.framebuffer.copy_from_slice(&slice);
|
self.framebuffer.copy_from_slice(&slice);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -114,6 +110,7 @@ impl RfbServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Start the server.
|
||||||
pub fn start(&mut self) {
|
pub fn start(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
rfb::bindings::rfbInitServerWithPthreadsAndZRLE(self.ptr.as_ptr());
|
rfb::bindings::rfbInitServerWithPthreadsAndZRLE(self.ptr.as_ptr());
|
||||||
|
@ -123,6 +120,14 @@ impl RfbServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shutdown the server. This does not destroy the RFB screen, therefore [RfbServer::start] can be
|
||||||
|
/// used to start it back up. (Only dropping the RfbServer will destroy the screen currently.)
|
||||||
|
pub fn shutdown(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
rfb::bindings::rfbShutdownServer(self.ptr.as_ptr(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_buttons(&self) -> [bool; 32] {
|
pub fn get_buttons(&self) -> [bool; 32] {
|
||||||
self.buttons
|
self.buttons
|
||||||
}
|
}
|
||||||
|
@ -240,6 +245,15 @@ impl RfbServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for RfbServer {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
// Shut down the server and release resources.
|
||||||
|
rfb::bindings::rfbScreenCleanup(self.ptr.as_ptr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Logging support
|
// Logging support
|
||||||
|
|
||||||
use std::ffi;
|
use std::ffi;
|
||||||
|
|
Loading…
Reference in a new issue