Deployed on proscan, update docs
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
use async_channel::{bounded, Receiver};
|
||||
use bytes::{BufMut, BytesMut};
|
||||
use err::Error;
|
||||
use futures_util::FutureExt;
|
||||
use netpod::NodeConfigCached;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
|
||||
use err::Error;
|
||||
use netpod::NodeConfigCached;
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod test;
|
||||
pub mod zmtp;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Message {
|
||||
cmd: u16,
|
||||
@@ -21,55 +26,6 @@ pub enum FetchItem {
|
||||
Message(Message),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use futures_util::StreamExt;
|
||||
use netpod::log::*;
|
||||
use netpod::{Cluster, Database, Node, NodeConfig, NodeConfigCached};
|
||||
use std::collections::BTreeMap;
|
||||
use std::iter::FromIterator;
|
||||
|
||||
#[test]
|
||||
fn ca_connect_1() {
|
||||
taskrun::run(async {
|
||||
let it = vec![(String::new(), String::new())].into_iter();
|
||||
let pairs = BTreeMap::from_iter(it);
|
||||
let node_config = NodeConfigCached {
|
||||
node: Node {
|
||||
host: "".into(),
|
||||
bin_grain_kind: 0,
|
||||
port: 123,
|
||||
port_raw: 123,
|
||||
backend: "".into(),
|
||||
split: 0,
|
||||
data_base_path: "".into(),
|
||||
listen: "".into(),
|
||||
ksprefix: "".into(),
|
||||
},
|
||||
node_config: NodeConfig {
|
||||
name: "".into(),
|
||||
cluster: Cluster {
|
||||
nodes: vec![],
|
||||
database: Database {
|
||||
host: "".into(),
|
||||
name: "".into(),
|
||||
user: "".into(),
|
||||
pass: "".into(),
|
||||
},
|
||||
},
|
||||
},
|
||||
ix: 0,
|
||||
};
|
||||
let mut rx = super::ca_connect_1(pairs, &node_config).await?;
|
||||
while let Some(item) = rx.next().await {
|
||||
info!("got next: {:?}", item);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn ca_connect_1(
|
||||
_pairs: BTreeMap<String, String>,
|
||||
_node_config: &NodeConfigCached,
|
||||
|
||||
56
netfetch/src/test.rs
Normal file
56
netfetch/src/test.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use futures_util::StreamExt;
|
||||
use netpod::log::*;
|
||||
use netpod::{Cluster, Database, Node, NodeConfig, NodeConfigCached};
|
||||
use std::collections::BTreeMap;
|
||||
use std::iter::FromIterator;
|
||||
|
||||
#[test]
|
||||
fn ca_connect_1() {
|
||||
taskrun::run(async {
|
||||
let it = vec![(String::new(), String::new())].into_iter();
|
||||
let pairs = BTreeMap::from_iter(it);
|
||||
let node_config = NodeConfigCached {
|
||||
node: Node {
|
||||
host: "".into(),
|
||||
bin_grain_kind: 0,
|
||||
port: 123,
|
||||
port_raw: 123,
|
||||
backend: "".into(),
|
||||
split: 0,
|
||||
data_base_path: "".into(),
|
||||
listen: "".into(),
|
||||
ksprefix: "".into(),
|
||||
},
|
||||
node_config: NodeConfig {
|
||||
name: "".into(),
|
||||
cluster: Cluster {
|
||||
nodes: vec![],
|
||||
database: Database {
|
||||
host: "".into(),
|
||||
name: "".into(),
|
||||
user: "".into(),
|
||||
pass: "".into(),
|
||||
},
|
||||
},
|
||||
},
|
||||
ix: 0,
|
||||
};
|
||||
let mut rx = super::ca_connect_1(pairs, &node_config).await?;
|
||||
while let Some(item) = rx.next().await {
|
||||
info!("got next: {:?}", item);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zmtp_00() {
|
||||
taskrun::run(async {
|
||||
let it = vec![(String::new(), String::new())].into_iter();
|
||||
let _pairs = BTreeMap::from_iter(it);
|
||||
crate::zmtp::zmtp_00().await?;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
70
netfetch/src/zmtp.rs
Normal file
70
netfetch/src/zmtp.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
use err::Error;
|
||||
use futures_core::Stream;
|
||||
use futures_util::{pin_mut, StreamExt};
|
||||
use netpod::log::*;
|
||||
use std::mem;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use tokio::io::{AsyncRead, ReadBuf};
|
||||
use tokio::net::TcpStream;
|
||||
|
||||
pub async fn zmtp_00() -> Result<(), Error> {
|
||||
// PV:BSREADCONFIG
|
||||
let addr = "S10-CPPM-MOT0991:9999";
|
||||
let conn = tokio::net::TcpStream::connect(addr).await?;
|
||||
let mut zmtp = Zmtp::new(conn);
|
||||
while let Some(ev) = zmtp.next().await {
|
||||
info!("got zmtp event: {:?}", ev);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
enum ConnState {
|
||||
Init,
|
||||
}
|
||||
|
||||
struct Zmtp {
|
||||
conn: TcpStream,
|
||||
conn_state: ConnState,
|
||||
buf1: Vec<u8>,
|
||||
need_min: usize,
|
||||
}
|
||||
|
||||
impl Zmtp {
|
||||
fn new(conn: TcpStream) -> Self {
|
||||
Self {
|
||||
conn,
|
||||
conn_state: ConnState::Init,
|
||||
buf1: vec![0; 1024],
|
||||
need_min: 4,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ZmtpEvent {}
|
||||
|
||||
impl Stream for Zmtp {
|
||||
type Item = Result<ZmtpEvent, Error>;
|
||||
|
||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
|
||||
use Poll::*;
|
||||
loop {
|
||||
break if let ConnState::Init = self.conn_state {
|
||||
// can it be that we already have enough bytes received in the buffer?
|
||||
let mut buf1 = mem::replace(&mut self.buf1, vec![]);
|
||||
let mut rbuf = ReadBuf::new(&mut buf1);
|
||||
let w = &mut self.conn;
|
||||
pin_mut!(w);
|
||||
let m1 = w.poll_read(cx, &mut rbuf);
|
||||
self.buf1 = buf1;
|
||||
match m1 {
|
||||
Ready(item) => Pending,
|
||||
Pending => Pending,
|
||||
}
|
||||
} else {
|
||||
Pending
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user