Use different port and handshake for different release channels
This commit is contained in:
parent
66bf56fc4f
commit
b70b76029e
2 changed files with 26 additions and 10 deletions
|
@ -41,8 +41,7 @@ const FALLBACK_DB_NAME: &'static str = "FALLBACK_MEMORY_DB";
|
||||||
const DB_FILE_NAME: &'static str = "db.sqlite";
|
const DB_FILE_NAME: &'static str = "db.sqlite";
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
// !!!!!!! CHANGE BACK TO DEFAULT FALSE BEFORE SHIPPING
|
pub static ref ZED_STATELESS: bool = std::env::var("ZED_STATELESS").map_or(false, |v| !v.is_empty());
|
||||||
static ref ZED_STATELESS: bool = std::env::var("ZED_STATELESS").map_or(false, |v| !v.is_empty());
|
|
||||||
pub static ref BACKUP_DB_PATH: RwLock<Option<PathBuf>> = RwLock::new(None);
|
pub static ref BACKUP_DB_PATH: RwLock<Option<PathBuf>> = RwLock::new(None);
|
||||||
pub static ref ALL_FILE_DB_FAILED: AtomicBool = AtomicBool::new(false);
|
pub static ref ALL_FILE_DB_FAILED: AtomicBool = AtomicBool::new(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,31 @@ use std::{
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
const PORT: u16 = 43739;
|
use util::channel::ReleaseChannel;
|
||||||
|
|
||||||
const LOCALHOST: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
|
const LOCALHOST: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
|
||||||
const ADDRESS: SocketAddr = SocketAddr::V4(SocketAddrV4::new(LOCALHOST, PORT));
|
|
||||||
const INSTANCE_HANDSHAKE: &str = "Zed Editor Instance Running";
|
|
||||||
const CONNECT_TIMEOUT: Duration = Duration::from_millis(10);
|
const CONNECT_TIMEOUT: Duration = Duration::from_millis(10);
|
||||||
const RECEIVE_TIMEOUT: Duration = Duration::from_millis(35);
|
const RECEIVE_TIMEOUT: Duration = Duration::from_millis(35);
|
||||||
const SEND_TIMEOUT: Duration = Duration::from_millis(20);
|
const SEND_TIMEOUT: Duration = Duration::from_millis(20);
|
||||||
|
|
||||||
|
fn address() -> SocketAddr {
|
||||||
|
let port = match *util::channel::RELEASE_CHANNEL {
|
||||||
|
ReleaseChannel::Dev => 43737,
|
||||||
|
ReleaseChannel::Preview => 43738,
|
||||||
|
ReleaseChannel::Stable => 43739,
|
||||||
|
};
|
||||||
|
|
||||||
|
SocketAddr::V4(SocketAddrV4::new(LOCALHOST, port))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn instance_handshake() -> &'static str {
|
||||||
|
match *util::channel::RELEASE_CHANNEL {
|
||||||
|
ReleaseChannel::Dev => "Zed Editor Dev Instance Running",
|
||||||
|
ReleaseChannel::Preview => "Zed Editor Preview Instance Running",
|
||||||
|
ReleaseChannel::Stable => "Zed Editor Stable Instance Running",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum IsOnlyInstance {
|
pub enum IsOnlyInstance {
|
||||||
Yes,
|
Yes,
|
||||||
|
@ -24,7 +41,7 @@ pub fn ensure_only_instance() -> IsOnlyInstance {
|
||||||
return IsOnlyInstance::No;
|
return IsOnlyInstance::No;
|
||||||
}
|
}
|
||||||
|
|
||||||
let listener = match TcpListener::bind(ADDRESS) {
|
let listener = match TcpListener::bind(address()) {
|
||||||
Ok(listener) => listener,
|
Ok(listener) => listener,
|
||||||
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
@ -50,7 +67,7 @@ pub fn ensure_only_instance() -> IsOnlyInstance {
|
||||||
|
|
||||||
_ = stream.set_nodelay(true);
|
_ = stream.set_nodelay(true);
|
||||||
_ = stream.set_read_timeout(Some(SEND_TIMEOUT));
|
_ = stream.set_read_timeout(Some(SEND_TIMEOUT));
|
||||||
_ = stream.write_all(INSTANCE_HANDSHAKE.as_bytes());
|
_ = stream.write_all(instance_handshake().as_bytes());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -58,9 +75,9 @@ pub fn ensure_only_instance() -> IsOnlyInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_got_handshake() -> bool {
|
fn check_got_handshake() -> bool {
|
||||||
match TcpStream::connect_timeout(&ADDRESS, CONNECT_TIMEOUT) {
|
match TcpStream::connect_timeout(&address(), CONNECT_TIMEOUT) {
|
||||||
Ok(mut stream) => {
|
Ok(mut stream) => {
|
||||||
let mut buf = vec![0u8; INSTANCE_HANDSHAKE.len()];
|
let mut buf = vec![0u8; instance_handshake().len()];
|
||||||
|
|
||||||
stream.set_read_timeout(Some(RECEIVE_TIMEOUT)).unwrap();
|
stream.set_read_timeout(Some(RECEIVE_TIMEOUT)).unwrap();
|
||||||
if let Err(err) = stream.read_exact(&mut buf) {
|
if let Err(err) = stream.read_exact(&mut buf) {
|
||||||
|
@ -68,7 +85,7 @@ fn check_got_handshake() -> bool {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if buf == INSTANCE_HANDSHAKE.as_bytes() {
|
if buf == instance_handshake().as_bytes() {
|
||||||
log::info!("Got instance handshake");
|
log::info!("Got instance handshake");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue