fix: fix builds on windows platform (#263)
This commit is contained in:
parent
fcd8bb2e62
commit
31a87032ca
5 changed files with 20 additions and 2 deletions
|
|
@ -43,6 +43,7 @@ async fn do_chainsync(client: &mut NodeClient) {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
tracing::subscriber::set_global_default(
|
||||
|
|
@ -66,6 +67,7 @@ async fn main() {
|
|||
}
|
||||
|
||||
#[cfg(not(target_family = "unix"))]
|
||||
|
||||
fn main() {
|
||||
panic!("can't use n2c unix socket on non-unix systems");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,6 +88,8 @@ pub struct NodeClient {
|
|||
}
|
||||
|
||||
impl NodeClient {
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
pub async fn connect(path: impl AsRef<Path>, magic: u64) -> Result<Self, Error> {
|
||||
debug!("connecting");
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,15 @@ use std::net::SocketAddr;
|
|||
use std::path::Path;
|
||||
use thiserror::Error;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::net::{TcpListener, TcpStream, ToSocketAddrs, UnixStream};
|
||||
use tokio::net::{TcpListener, TcpStream, ToSocketAddrs};
|
||||
use tokio::select;
|
||||
use tokio::sync::mpsc::error::SendError;
|
||||
use tokio::time::Instant;
|
||||
use tracing::{debug, error, trace};
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
use UnixStream;
|
||||
|
||||
const HEADER_LEN: usize = 8;
|
||||
|
||||
pub type Timestamp = u32;
|
||||
|
|
@ -57,6 +60,12 @@ pub struct Segment {
|
|||
pub payload: Payload,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub enum Bearer {
|
||||
Tcp(TcpStream)
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
pub enum Bearer {
|
||||
Tcp(TcpStream),
|
||||
Unix(UnixStream),
|
||||
|
|
@ -75,6 +84,7 @@ impl Bearer {
|
|||
Ok((Self::Tcp(stream), addr))
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
pub async fn connect_unix(path: impl AsRef<Path>) -> Result<Self, tokio::io::Error> {
|
||||
let stream = UnixStream::connect(path).await?;
|
||||
Ok(Self::Unix(stream))
|
||||
|
|
@ -83,6 +93,7 @@ impl Bearer {
|
|||
pub async fn readable(&self) -> tokio::io::Result<()> {
|
||||
match self {
|
||||
Bearer::Tcp(x) => x.readable().await,
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
Bearer::Unix(x) => x.readable().await,
|
||||
}
|
||||
}
|
||||
|
|
@ -90,6 +101,7 @@ impl Bearer {
|
|||
fn try_read(&mut self, buf: &mut [u8]) -> tokio::io::Result<usize> {
|
||||
match self {
|
||||
Bearer::Tcp(x) => x.try_read(buf),
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
Bearer::Unix(x) => x.try_read(buf),
|
||||
}
|
||||
}
|
||||
|
|
@ -97,6 +109,7 @@ impl Bearer {
|
|||
async fn write_all(&mut self, buf: &[u8]) -> tokio::io::Result<()> {
|
||||
match self {
|
||||
Bearer::Tcp(x) => x.write_all(buf).await,
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
Bearer::Unix(x) => x.write_all(buf).await,
|
||||
}
|
||||
}
|
||||
|
|
@ -104,6 +117,7 @@ impl Bearer {
|
|||
async fn flush(&mut self) -> tokio::io::Result<()> {
|
||||
match self {
|
||||
Bearer::Tcp(x) => x.flush().await,
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
Bearer::Unix(x) => x.flush().await,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use pallas_primitives::{alonzo, babbage, byron};
|
|||
mod support;
|
||||
|
||||
pub mod assets;
|
||||
pub mod aux;
|
||||
pub mod auxiliary;
|
||||
pub mod block;
|
||||
pub mod cert;
|
||||
pub mod era;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue