From b518fd0ef91d8ca3d9814b335c7be8684d1692a9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 12 Aug 2018 22:12:51 +0300 Subject: Sans IO dispatch --- crates/server/src/dispatch.rs | 13 +++---------- crates/server/src/main_loop/mod.rs | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) (limited to 'crates/server/src') diff --git a/crates/server/src/dispatch.rs b/crates/server/src/dispatch.rs index 381649859..bfdbd30ca 100644 --- a/crates/server/src/dispatch.rs +++ b/crates/server/src/dispatch.rs @@ -10,7 +10,7 @@ use drop_bomb::DropBomb; use ::{ Result, req::{ClientRequest, Notification}, - io::{Io, RawMsg, RawResponse, RawRequest, RawNotification}, + io::{RawResponse, RawRequest, RawNotification}, }; pub struct Responder { @@ -113,9 +113,9 @@ pub fn send_notification(params: N::Params) -> RawNotification } } +pub fn unknown_method(id: u64) -> Result { + error_response(id, ErrorCode::MethodNotFound, "unknown method") -pub fn unknown_method(io: &mut Io, raw: RawRequest) -> Result<()> { - error(io, raw.id, ErrorCode::MethodNotFound, "unknown method") } fn error_response(id: u64, code: ErrorCode, message: &'static str) -> Result { @@ -135,13 +135,6 @@ fn error_response(id: u64, code: ErrorCode, message: &'static str) -> Result Result<()> { - let resp = error_response(id, code, message)?; - io.send(RawMsg::Response(resp)); - Ok(()) -} - - #[allow(unused)] enum ErrorCode { ParseError = -32700, diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index e7b24e53f..e80b9988d 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs @@ -102,7 +102,7 @@ fn on_msg( } if let Some(req) = req { error!("unknown method: {:?}", req); - dispatch::unknown_method(io, req)?; + io.send(RawMsg::Response(dispatch::unknown_method(req.id)?)); } } RawMsg::Notification(not) => { -- cgit v1.2.3