1
This commit is contained in:
parent
50646e5ca0
commit
3897376872
@ -1,10 +1,12 @@
|
|||||||
use std::rc::{Rc, Weak};
|
use std::rc::{Rc, Weak};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::error::Error;
|
|
||||||
use tokio::net::{TcpStream, ToSocketAddrs};
|
use tokio::net::{TcpStream, ToSocketAddrs};
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
use tokio::io::Interest;
|
||||||
|
use std::error::Error;
|
||||||
|
use std::io;
|
||||||
|
|
||||||
use r9_macro::SharedFromSelf;
|
use r9_macro::SharedFromSelf;
|
||||||
use r9_macro_derive::SharedFromSelf;
|
use r9_macro_derive::SharedFromSelf;
|
||||||
@ -17,11 +19,45 @@ pub struct UpStreamMgr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn run_app() -> Result<(), Box<dyn Error>> {
|
async fn run_app() -> Result<(), Box<dyn Error>> {
|
||||||
// Connect to a peer
|
let mut stream = TcpStream::connect("192.168.100.39:7617").await?;
|
||||||
let mut stream = TcpStream::connect("127.0.0.1:8080").await?;
|
|
||||||
|
|
||||||
// Write some data.
|
loop {
|
||||||
stream.write_all(b"hello world!").await?;
|
let ready = stream.ready(Interest::READABLE | Interest::WRITABLE).await?;
|
||||||
|
|
||||||
|
if ready.is_readable() {
|
||||||
|
let mut data = vec![0; 1024];
|
||||||
|
// Try to read data, this may still fail with `WouldBlock`
|
||||||
|
// if the readiness event is a false positive.
|
||||||
|
match stream.try_read(&mut data) {
|
||||||
|
Ok(n) => {
|
||||||
|
println!("read {} bytes", n);
|
||||||
|
}
|
||||||
|
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
//return Err(e.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ready.is_writable() {
|
||||||
|
// Try to write data, this may still fail with `WouldBlock`
|
||||||
|
// if the readiness event is a false positive.
|
||||||
|
match stream.try_write(b"hello world") {
|
||||||
|
Ok(n) => {
|
||||||
|
println!("write {} bytes", n);
|
||||||
|
}
|
||||||
|
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
//return Err(e.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -39,6 +75,7 @@ impl UpStreamMgr {
|
|||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||||
.worker_threads(4)
|
.worker_threads(4)
|
||||||
|
.enable_all()
|
||||||
.thread_name("my-custom-name")
|
.thread_name("my-custom-name")
|
||||||
.thread_stack_size(3 * 1024 * 1024)
|
.thread_stack_size(3 * 1024 * 1024)
|
||||||
.build()
|
.build()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user