[web] [WIP] Use smol's constituent crates instead of all of smol

This commit is contained in:
Emi Simpson 2021-11-03 10:44:39 -04:00
parent 2bfdf0ef49
commit 4ed748cf1e
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
2 changed files with 13 additions and 10 deletions

View File

@ -8,7 +8,9 @@ edition = "2021"
[dependencies]
pronouns_today = {path = ".."}
async-scgi = "0.1.0"
smol = "1.2"
async-executor = "1.4"
async-net = "1.6"
futures-lite = "1.12"
log = "0.4"
env_logger = "0.9"
askama = "0.10"

View File

@ -6,8 +6,10 @@ pub mod configuration;
use crate::configuration::Conf;
use std::io::IoSlice;
use crate::statics::StaticAsset;
use smol::io::AsyncWriteExt;
use smol::stream::StreamExt;
use async_net::TcpListener;
use async_executor::LocalExecutor;
use futures_lite::io::AsyncWriteExt;
use futures_lite::stream::StreamExt;
use std::borrow::Cow;
use form_urlencoded;
use percent_encoding::{percent_decode_str, percent_encode, NON_ALPHANUMERIC};
@ -24,7 +26,6 @@ use askama::Template;
use async_scgi::{ScgiReadError, ScgiRequest};
use pronouns_today::user_preferences::Preference;
use pronouns_today::{InstanceSettings, Pronoun};
use smol;
#[cfg(feature = "ogp_images")]
use image::{DynamicImage, ImageOutputFormat};
@ -63,9 +64,9 @@ fn main() {
}
};
let executor = smol::LocalExecutor::new();
let executor = LocalExecutor::new();
log::info!("Starting with configuration {:?}", config);
smol::block_on(executor.run(start_server(config, &executor))).unwrap();
futures_lite::future::block_on(executor.run(start_server(config, &executor))).unwrap();
}
}
}
@ -76,13 +77,13 @@ fn main() {
/// connection is fully processed, but not in this method. Actual handling of the
/// requests is delegated to the [`handle_request()`], which is the actual task that is
/// spawned into the Executor.
async fn start_server(config: configuration::Conf, executor: &smol::LocalExecutor<'_>) -> std::io::Result<()> {
async fn start_server(config: configuration::Conf, executor: &LocalExecutor<'_>) -> std::io::Result<()> {
// Where we binding bois
let socket_addr = SocketAddr::new(config.address, config.port);
println!("Starting pronouns-today-web on {}", &socket_addr);
let connection = smol::net::TcpListener::bind(socket_addr).await?;
let connection = TcpListener::bind(socket_addr).await?;
let mut incoming = connection.incoming();
// Make the configuration immortal
@ -114,10 +115,10 @@ async fn start_server(config: configuration::Conf, executor: &smol::LocalExecuto
/// - Generation of the response is done using [`Route::generate_response()`]
/// - Serialization of the response is done using [`Response::into_bytes()`]
async fn handle_request(
raw_stream: impl smol::io::AsyncRead + smol::io::AsyncWrite + Unpin,
raw_stream: impl futures_lite::AsyncRead + futures_lite::AsyncWrite + Unpin,
conf: &Conf,
) {
let mut stream = smol::io::BufReader::new(raw_stream);
let mut stream = futures_lite::io::BufReader::new(raw_stream);
let req = match async_scgi::read_request(&mut stream).await {
Ok(req) => req,