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