From 211050a4341ba037e1062cf3ae468bab526b69de Mon Sep 17 00:00:00 2001 From: MeiK2333 Date: Mon, 11 Jan 2021 19:27:03 +0800 Subject: [PATCH] Update --- src/error.rs | 1 + src/main.rs | 42 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index df6ba20..83537b4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -13,6 +13,7 @@ pub enum Error { IOError(io::Error), StringToCStringError(NulError), ParseIntError(std::num::ParseIntError), + CreateTempDirError(io::Error), } pub type Result = result::Result; diff --git a/src/main.rs b/src/main.rs index 3789984..a7d68f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,10 +3,13 @@ extern crate log; use env_logger::Env; +use futures::StreamExt; use futures_core::Stream; +use river::judge_request::Data; use river::river_server::{River, RiverServer}; use river::{JudgeRequest, JudgeResponse}; use std::pin::Pin; +use tempfile::tempdir_in; use tonic::transport::Server; use tonic::{Request, Response, Status}; @@ -34,12 +37,45 @@ impl River for RiverService { &self, request: Request>, ) -> Result, Status> { - let mut _stream = request.into_inner(); + let mut stream = request.into_inner(); + // 此处编译很慢 + // 为啥,是 try_stream! 这个宏导致的吗? let output = async_stream::try_stream! { - yield JudgeResponse { - state: Some(river::judge_response::State::Status(river::JudgeStatus::Pending as i32)) + while let Some(req) = stream.next().await { + let req = req?; + // TODO + let pwd = tempdir_in("/tmp").unwrap(); + match &req.data { + Some(Data::CompileData(data)) => { + debug!("compile request"); + let language = &data.language; + let code = &data.code; + debug!("language: {}", language); + debug!("code: {}", code); + break; + }, + Some(Data::JudgeData(data)) => { + debug!("judge request"); + let in_file = &data.in_file; + let out_file = &data.out_file; + let time_limit = &data.time_limit; + let memory_limit = &data.memory_limit; + let judge_type = &data.judge_type; + debug!("in_file: {}", in_file); + debug!("out_file: {}", out_file); + debug!("time_limit: {}", time_limit); + debug!("memory_limit: {}", memory_limit); + debug!("judge_type: {}", judge_type); + break; + }, + None => break, + _ => break, }; + } + yield JudgeResponse { + state: Some(river::judge_response::State::Status(river::JudgeStatus::Pending as i32)) + }; }; Ok(Response::new(Box::pin(output) as Self::JudgeStream))