aboutsummaryrefslogtreecommitdiff
path: root/src/modules/finger.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-06-24 22:53:39 -0700
committerFuwn <[email protected]>2024-06-24 22:53:39 -0700
commiteee8bdb3da49b1b9b14833748a51dbb8cba57166 (patch)
treea1facbf607b9b0d0a59ad593a22c4007f9f775f2 /src/modules/finger.rs
parentfeat(finger): add finger timeouts (diff)
downloadlocus-eee8bdb3da49b1b9b14833748a51dbb8cba57166.tar.xz
locus-eee8bdb3da49b1b9b14833748a51dbb8cba57166.zip
feat(finger): tokio instead of std net
Diffstat (limited to 'src/modules/finger.rs')
-rw-r--r--src/modules/finger.rs20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/modules/finger.rs b/src/modules/finger.rs
index 34140c0..44e4df6 100644
--- a/src/modules/finger.rs
+++ b/src/modules/finger.rs
@@ -1,9 +1,6 @@
use {
crate::{response::success, route::track_mount},
- std::{
- io::{Read, Write},
- time::Duration,
- },
+ tokio::io::{AsyncReadExt, AsyncWriteExt},
windmark::response::Response,
};
@@ -26,7 +23,7 @@ To visit my personal Finger server, <finger://fuwn.me>, you would visit <gemini:
router,
"/finger/*uri",
"-Finger-to-Gemini Gateway Router",
- |context| {
+ |context| async move {
if let Some(uri) = context.parameters.get("uri") {
let path;
let url = url::Url::parse({
@@ -43,21 +40,16 @@ To visit my personal Finger server, <finger://fuwn.me>, you would visit <gemini:
})
.unwrap();
- let mut stream = std::net::TcpStream::connect(url.to_string()).unwrap();
+ let mut stream =
+ tokio::net::TcpStream::connect(url.to_string()).await.unwrap();
let mut buffer = [0; 1024];
- stream
- .set_read_timeout(Some(Duration::from_secs(5)))
- .expect("error: set_read_timeout failed");
- stream
- .set_write_timeout(Some(Duration::from_secs(5)))
- .expect("error: set_write_timeout failed");
- stream.write_all(format!("{path}\n").as_bytes()).unwrap();
+ stream.write_all(format!("{path}\n").as_bytes()).await.unwrap();
let mut response = String::new();
loop {
- let bytes_read = match stream.read(&mut buffer) {
+ let bytes_read = match stream.read(&mut buffer).await {
Ok(0) => break,
Ok(n) => n,
Err(e) => {