add adbity to send to client thread from server_thread_receiver_handler (to_server_sender)

This commit is contained in:
Horhik 2021-03-26 23:25:30 +03:00
parent 604f1dc026
commit a1f77298c7
4 changed files with 14 additions and 4 deletions

View file

@ -2,19 +2,25 @@ use super::request::*;
use crate::chat::types::SP;
use async_std::io::Result;
use rusqlite::Connection;
use crate::db::{messages, users};
use crate::chat::types::PackedMessage;
pub fn start_app(request: StartAppReq, server_sender: &SP) -> Result<()> {
Ok(())
//sending *JSON*, what everything is OK
}
pub fn stop_app(request: StopAppReq, conn: &Connection, server_sender: &SP) -> Result<()> {
unimplemented!()
std::process::exit(0)
}
pub fn load_users(request: LoadUsersReq, conn: &Connection, server_sender: &SP) -> Result<()> {
unimplemented!()
let users = users::load_all_users(conn);
unimplemented!();
//sending *JSON*
}
pub fn send_message(request: SendMessageReq, conn: &Connection, server_sender: &SP) -> Result<()> {
unimplemented!()
//sending FCP request
}
pub fn load_messages(
@ -23,7 +29,9 @@ pub fn load_messages(
server_sender: &SP,
) -> Result<()> {
unimplemented!()
//sending *JSON*
}
pub fn add_user(request: AddUserReq, conn: &Connection, server_sender: &SP) -> Result<()> {
unimplemented!()
//sending *JSON* what user is created
}

View file

@ -17,6 +17,7 @@ pub async fn request_selector(json: String, server_sender: &SP, conn: &Connectio
}
if let Ok(res) = from_str::<StopAppReq>(&json) {
handlers::stop_app(res, conn, server_sender)?
}
if let Ok(res) = from_str::<LoadUsersReq>(&json) {
handlers::load_users(res, conn, server_sender)?

View file

@ -18,10 +18,11 @@ async fn connect_to_server(client_sender: SP, server_receiver: RP) -> io::Result
.nth(1)
.unwrap_or_else(|| "127.0.0.1:9481".to_string());
let sr = client_sender.clone();
let stream = TcpStream::connect(&addr).await.expect("weeror here");
let (receiver, sender) = stream.into_split();
let t = task::spawn(server_responce_getter(receiver, client_sender));
to_server_sender(sender, server_receiver).await?;
to_server_sender(sender, server_receiver, sr).await?;
match t.await {
Ok(_) => Ok(()),
Err(e) => Err(e),

View file

@ -9,7 +9,7 @@ use tokio::{
use fcpv2::client::fcp_types::{ClientHello, ClientPut};
use fcpv2::types::{traits::{FcpRequest, FcpParser}, SSK} ;
pub async fn to_server_sender(mut sender: OwnedWriteHalf, server_receiver: RP) -> io::Result<()> {
pub async fn to_server_sender(mut sender: OwnedWriteHalf, server_receiver: RP, client_sender: SP) -> io::Result<()> {
while let Ok(res) = server_receiver.recv() {
//TODO from_core_to_server_handler
if res.message == "STARTAPP!" {