🐛 bug: fix crash when trying to open the same port twice
parent
baa5044186
commit
e4285ec17d
|
@ -53,10 +53,12 @@ impl GuiClient <'_> {
|
||||||
let params = self.gui_ports [port_idx].get_params ()?;
|
let params = self.gui_ports [port_idx].get_params ()?;
|
||||||
|
|
||||||
let _guard = self.rt.enter ();
|
let _guard = self.rt.enter ();
|
||||||
self.forwarding_instances [port_idx].replace (ForwardingInstance::new (
|
let forwarding_instance = self.rt.block_on (ForwardingInstance::new (
|
||||||
connection_p2_p3,
|
connection_p2_p3,
|
||||||
params,
|
params,
|
||||||
));
|
))?;
|
||||||
|
|
||||||
|
self.forwarding_instances [port_idx].replace (forwarding_instance);
|
||||||
|
|
||||||
self.gui_ports [port_idx].set_forwarding (true);
|
self.gui_ports [port_idx].set_forwarding (true);
|
||||||
self.sync_status ();
|
self.sync_status ();
|
||||||
|
@ -259,9 +261,9 @@ impl GuiPort {
|
||||||
input_server_id.set_value ("bogus_server");
|
input_server_id.set_value ("bogus_server");
|
||||||
input_server_port.set_value ("5900");
|
input_server_port.set_value ("5900");
|
||||||
|
|
||||||
but_open.set_trigger (CallbackTrigger::Changed);
|
but_open.set_trigger (CallbackTrigger::Release);
|
||||||
but_open.emit (fltk_tx, Message::OpenPort (port_idx));
|
but_open.emit (fltk_tx, Message::OpenPort (port_idx));
|
||||||
but_close.set_trigger (CallbackTrigger::Changed);
|
but_close.set_trigger (CallbackTrigger::Release);
|
||||||
but_close.emit (fltk_tx, Message::ClosePort (port_idx));
|
but_close.emit (fltk_tx, Message::ClosePort (port_idx));
|
||||||
|
|
||||||
set_active (&mut but_open, true);
|
set_active (&mut but_open, true);
|
||||||
|
|
|
@ -12,23 +12,27 @@ pub struct ForwardingInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ForwardingInstance {
|
impl ForwardingInstance {
|
||||||
pub fn new (
|
pub async fn new (
|
||||||
connection_p2_p3: quinn::Connection,
|
connection_p2_p3: quinn::Connection,
|
||||||
params: ForwardingParams,
|
params: ForwardingParams,
|
||||||
) -> Self
|
) -> anyhow::Result <Self>
|
||||||
{
|
{
|
||||||
let (shutdown_flag, shutdown_flag_rx) = tokio::sync::watch::channel (true);
|
let (shutdown_flag, shutdown_flag_rx) = tokio::sync::watch::channel (true);
|
||||||
|
|
||||||
|
let listener = TcpListener::bind (("127.0.0.1", params.client_tcp_port)).await?;
|
||||||
|
trace! ("Accepting local TCP connections from P1 on {}", params.client_tcp_port);
|
||||||
|
|
||||||
let task = tokio::spawn (forward_port (
|
let task = tokio::spawn (forward_port (
|
||||||
|
listener,
|
||||||
connection_p2_p3,
|
connection_p2_p3,
|
||||||
params,
|
params,
|
||||||
shutdown_flag_rx
|
shutdown_flag_rx
|
||||||
));
|
));
|
||||||
|
|
||||||
Self {
|
Ok (Self {
|
||||||
task,
|
task,
|
||||||
shutdown_flag,
|
shutdown_flag,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn close (self) -> anyhow::Result <()> {
|
pub async fn close (self) -> anyhow::Result <()> {
|
||||||
|
@ -53,6 +57,7 @@ pub struct ForwardingParams {
|
||||||
/// the same client:server port combination
|
/// the same client:server port combination
|
||||||
|
|
||||||
pub async fn forward_port (
|
pub async fn forward_port (
|
||||||
|
listener: TcpListener,
|
||||||
connection_p2_p3: quinn::Connection,
|
connection_p2_p3: quinn::Connection,
|
||||||
params: ForwardingParams,
|
params: ForwardingParams,
|
||||||
mut shutdown_flag_rx: tokio::sync::watch::Receiver <bool>,
|
mut shutdown_flag_rx: tokio::sync::watch::Receiver <bool>,
|
||||||
|
@ -64,10 +69,6 @@ pub async fn forward_port (
|
||||||
server_tcp_port,
|
server_tcp_port,
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
let listener = TcpListener::bind (("127.0.0.1", client_tcp_port)).await?;
|
|
||||||
|
|
||||||
trace! ("Accepting local TCP connections from P1 on {}", client_tcp_port);
|
|
||||||
|
|
||||||
while *shutdown_flag_rx.borrow () {
|
while *shutdown_flag_rx.borrow () {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
x = listener.accept () => {
|
x = listener.accept () => {
|
||||||
|
|
Loading…
Reference in New Issue