Skip to content

Commit

Permalink
Add default setting for tcp timeout
Browse files Browse the repository at this point in the history
Co-Authored-By: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com>
  • Loading branch information
RemcoSmitsDev and Anthony-Eid committed Oct 27, 2024
1 parent 1cd3de9 commit 9302a11
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions crates/dap/src/debugger_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ pub struct DebuggerSettings {
///
/// Default: true
pub button: bool,
/// Time in milliseconds until timeout error when connecting to a TCP debug adapter
///
/// Default: 2000ms
pub timeout: u64,
}

impl Default for DebuggerSettings {
Expand All @@ -27,6 +31,7 @@ impl Default for DebuggerSettings {
button: true,
save_breakpoints: true,
stepping_granularity: SteppingGranularity::Line,
timeout: 2000,
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions crates/dap/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use dap_types::{
};
use futures::{select, AsyncBufRead, AsyncReadExt as _, AsyncWrite, FutureExt as _};
use gpui::AsyncAppContext;
use settings::Settings as _;
use smallvec::SmallVec;
use smol::{
channel::{unbounded, Receiver, Sender},
Expand All @@ -23,7 +24,7 @@ use std::{
};
use task::TCPHost;

use crate::adapters::DebugAdapterBinary;
use crate::{adapters::DebugAdapterBinary, debugger_settings::DebuggerSettings};

pub type IoHandler = Box<dyn Send + FnMut(IoKind, &str)>;

Expand Down Expand Up @@ -373,8 +374,6 @@ pub struct TcpTransport {
}

impl TcpTransport {
const DEFAULT_TIMEOUT: u64 = 2000;

pub fn new(host: Ipv4Addr, port: u16, timeout: Option<u64>) -> Self {
Self {
port,
Expand Down Expand Up @@ -425,7 +424,10 @@ impl Transport for TcpTransport {

let address = SocketAddrV4::new(self.host, self.port);

let timeout = self.timeout.unwrap_or(Self::DEFAULT_TIMEOUT);
let timeout = self.timeout.unwrap_or_else(|| {
cx.update(|cx| DebuggerSettings::get_global(cx).timeout)
.unwrap_or(2000u64)
});

let (rx, tx) = select! {
_ = cx.background_executor().timer(Duration::from_millis(timeout)).fuse() => {
Expand Down

0 comments on commit 9302a11

Please sign in to comment.