From 9d00023401ec96e310cc5525da4f7386cf2c0900 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 29 Sep 2016 20:56:35 +0000 Subject: [PATCH] Rust: move a few things around (NFC). --- artiq/runtime.rs/src/lib.rs | 22 ++++++++------- .../src/{buffer_logger.rs => logger.rs} | 0 artiq/runtime.rs/src/{io.rs => sched.rs} | 0 .../src/{session/mod.rs => session.rs} | 28 +++++++++---------- .../{session/protocol.rs => session_proto.rs} | 0 5 files changed, 26 insertions(+), 24 deletions(-) rename artiq/runtime.rs/src/{buffer_logger.rs => logger.rs} (100%) rename artiq/runtime.rs/src/{io.rs => sched.rs} (100%) rename artiq/runtime.rs/src/{session/mod.rs => session.rs} (85%) rename artiq/runtime.rs/src/{session/protocol.rs => session_proto.rs} (100%) diff --git a/artiq/runtime.rs/src/lib.rs b/artiq/runtime.rs/src/lib.rs index edb7b06a2..d9664c588 100644 --- a/artiq/runtime.rs/src/lib.rs +++ b/artiq/runtime.rs/src/lib.rs @@ -9,16 +9,18 @@ extern crate log; extern crate log_buffer; extern crate byteorder; -use std::prelude::v1::*; -use buffer_logger::BufferLogger; +use logger::BufferLogger; -pub mod board; -pub mod io; -pub mod config; -pub mod clock; -pub mod rtio_crg; -pub mod buffer_logger; -pub mod session; +mod board; +mod sched; +mod config; +mod clock; +mod rtio_crg; + +mod logger; + +mod session_proto; +mod session; extern { fn network_init(); @@ -34,7 +36,7 @@ pub unsafe extern fn rust_main() { rtio_crg::init(); network_init(); - let mut scheduler = io::Scheduler::new(); + let mut scheduler = sched::Scheduler::new(); scheduler.spawn(4096, move |waiter| { session::handler(waiter, logger) }); diff --git a/artiq/runtime.rs/src/buffer_logger.rs b/artiq/runtime.rs/src/logger.rs similarity index 100% rename from artiq/runtime.rs/src/buffer_logger.rs rename to artiq/runtime.rs/src/logger.rs diff --git a/artiq/runtime.rs/src/io.rs b/artiq/runtime.rs/src/sched.rs similarity index 100% rename from artiq/runtime.rs/src/io.rs rename to artiq/runtime.rs/src/sched.rs diff --git a/artiq/runtime.rs/src/session/mod.rs b/artiq/runtime.rs/src/session.rs similarity index 85% rename from artiq/runtime.rs/src/session/mod.rs rename to artiq/runtime.rs/src/session.rs index ae82ab8e5..d95bc9619 100644 --- a/artiq/runtime.rs/src/session/mod.rs +++ b/artiq/runtime.rs/src/session.rs @@ -2,9 +2,9 @@ use std::prelude::v1::*; use std::str; use std::io::{self, Read, ErrorKind}; use {config, rtio_crg}; -use self::protocol::*; - -mod protocol; +use logger::BufferLogger; +use sched::{Waiter, TcpListener, TcpStream, SocketAddr, IP_ANY}; +use session_proto::*; #[derive(Debug, Clone, Copy)] enum KernelState { @@ -51,7 +51,7 @@ impl Drop for Session { } } -fn check_magic(stream: &mut ::io::TcpStream) -> io::Result<()> { +fn check_magic(stream: &mut TcpStream) -> io::Result<()> { const MAGIC: &'static [u8] = b"ARTIQ coredev\n"; let mut magic: [u8; 14] = [0; 14]; @@ -63,10 +63,10 @@ fn check_magic(stream: &mut ::io::TcpStream) -> io::Result<()> { } } -fn handle_request(stream: &mut ::io::TcpStream, - logger: &::buffer_logger::BufferLogger, +fn handle_request(stream: &mut TcpStream, + logger: &BufferLogger, session: &mut Session) -> io::Result<()> { - fn read_request(stream: &mut ::io::TcpStream) -> io::Result { + fn read_request(stream: &mut TcpStream) -> io::Result { let request = try!(Request::read_from(stream)); match &request { &Request::LoadLibrary(_) => trace!("comm<-host LoadLibrary(...)"), @@ -75,7 +75,7 @@ fn handle_request(stream: &mut ::io::TcpStream, Ok(request) } - fn write_reply(stream: &mut ::io::TcpStream, reply: Reply) -> io::Result<()> { + fn write_reply(stream: &mut TcpStream, reply: Reply) -> io::Result<()> { trace!("comm->host {:?}", reply); reply.write_to(stream) } @@ -139,8 +139,8 @@ fn handle_request(stream: &mut ::io::TcpStream, } } -fn handle_requests(stream: &mut ::io::TcpStream, - logger: &::buffer_logger::BufferLogger) -> io::Result<()> { +fn handle_requests(stream: &mut TcpStream, + logger: &BufferLogger) -> io::Result<()> { try!(check_magic(stream)); let mut session = Session::new(); @@ -149,10 +149,10 @@ fn handle_requests(stream: &mut ::io::TcpStream, } } -pub fn handler(waiter: ::io::Waiter, - logger: &::buffer_logger::BufferLogger) { - let addr = ::io::SocketAddr::new(::io::IP_ANY, 1381); - let listener = ::io::TcpListener::bind(waiter, addr).unwrap(); +pub fn handler(waiter: Waiter, + logger: &BufferLogger) { + let addr = SocketAddr::new(IP_ANY, 1381); + let listener = TcpListener::bind(waiter, addr).unwrap(); info!("accepting network sessions in Rust"); loop { diff --git a/artiq/runtime.rs/src/session/protocol.rs b/artiq/runtime.rs/src/session_proto.rs similarity index 100% rename from artiq/runtime.rs/src/session/protocol.rs rename to artiq/runtime.rs/src/session_proto.rs