-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: add unix stream & listener (#74)
- Loading branch information
1 parent
523dae0
commit 3176149
Showing
15 changed files
with
283 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::env; | ||
|
||
use tokio_uring::net::UnixListener; | ||
|
||
fn main() { | ||
let args: Vec<_> = env::args().collect(); | ||
|
||
if args.len() <= 1 { | ||
panic!("no addr specified"); | ||
} | ||
|
||
let socket_addr: String = args[1].clone(); | ||
|
||
tokio_uring::start(async { | ||
let listener = UnixListener::bind(&socket_addr).unwrap(); | ||
|
||
loop { | ||
let stream = listener.accept().await.unwrap(); | ||
let socket_addr = socket_addr.clone(); | ||
tokio_uring::spawn(async move { | ||
let buf = vec![1u8; 128]; | ||
|
||
let (result, buf) = stream.write(buf).await; | ||
println!("written to {}: {}", &socket_addr, result.unwrap()); | ||
|
||
let (result, buf) = stream.read(buf).await; | ||
let read = result.unwrap(); | ||
println!("read from {}: {:?}", &socket_addr, &buf[..read]); | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::env; | ||
|
||
use tokio_uring::net::UnixStream; | ||
|
||
fn main() { | ||
let args: Vec<_> = env::args().collect(); | ||
|
||
if args.len() <= 1 { | ||
panic!("no addr specified"); | ||
} | ||
|
||
let socket_addr: &String = &args[1]; | ||
|
||
tokio_uring::start(async { | ||
let stream = UnixStream::connect(socket_addr).await.unwrap(); | ||
let buf = vec![1u8; 128]; | ||
|
||
let (result, buf) = stream.write(buf).await; | ||
println!("written: {}", result.unwrap()); | ||
|
||
let (result, buf) = stream.read(buf).await; | ||
let read = result.unwrap(); | ||
println!("read: {:?}", &buf[..read]); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.