Rust: move a few things around (NFC).

This commit is contained in:
whitequark 2016-09-29 20:56:35 +00:00
parent 9c18f1b555
commit 9d00023401
5 changed files with 26 additions and 24 deletions

View File

@ -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)
});

View File

@ -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<Request> {
fn read_request(stream: &mut TcpStream) -> io::Result<Request> {
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 {