mirror of https://github.com/m-labs/artiq.git
Rust: move a few things around (NFC).
This commit is contained in:
parent
9c18f1b555
commit
9d00023401
|
@ -9,16 +9,18 @@ extern crate log;
|
||||||
extern crate log_buffer;
|
extern crate log_buffer;
|
||||||
extern crate byteorder;
|
extern crate byteorder;
|
||||||
|
|
||||||
use std::prelude::v1::*;
|
use logger::BufferLogger;
|
||||||
use buffer_logger::BufferLogger;
|
|
||||||
|
|
||||||
pub mod board;
|
mod board;
|
||||||
pub mod io;
|
mod sched;
|
||||||
pub mod config;
|
mod config;
|
||||||
pub mod clock;
|
mod clock;
|
||||||
pub mod rtio_crg;
|
mod rtio_crg;
|
||||||
pub mod buffer_logger;
|
|
||||||
pub mod session;
|
mod logger;
|
||||||
|
|
||||||
|
mod session_proto;
|
||||||
|
mod session;
|
||||||
|
|
||||||
extern {
|
extern {
|
||||||
fn network_init();
|
fn network_init();
|
||||||
|
@ -34,7 +36,7 @@ pub unsafe extern fn rust_main() {
|
||||||
rtio_crg::init();
|
rtio_crg::init();
|
||||||
network_init();
|
network_init();
|
||||||
|
|
||||||
let mut scheduler = io::Scheduler::new();
|
let mut scheduler = sched::Scheduler::new();
|
||||||
scheduler.spawn(4096, move |waiter| {
|
scheduler.spawn(4096, move |waiter| {
|
||||||
session::handler(waiter, logger)
|
session::handler(waiter, logger)
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,9 +2,9 @@ use std::prelude::v1::*;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::io::{self, Read, ErrorKind};
|
use std::io::{self, Read, ErrorKind};
|
||||||
use {config, rtio_crg};
|
use {config, rtio_crg};
|
||||||
use self::protocol::*;
|
use logger::BufferLogger;
|
||||||
|
use sched::{Waiter, TcpListener, TcpStream, SocketAddr, IP_ANY};
|
||||||
mod protocol;
|
use session_proto::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
enum KernelState {
|
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";
|
const MAGIC: &'static [u8] = b"ARTIQ coredev\n";
|
||||||
|
|
||||||
let mut magic: [u8; 14] = [0; 14];
|
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,
|
fn handle_request(stream: &mut TcpStream,
|
||||||
logger: &::buffer_logger::BufferLogger,
|
logger: &BufferLogger,
|
||||||
session: &mut Session) -> io::Result<()> {
|
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));
|
let request = try!(Request::read_from(stream));
|
||||||
match &request {
|
match &request {
|
||||||
&Request::LoadLibrary(_) => trace!("comm<-host LoadLibrary(...)"),
|
&Request::LoadLibrary(_) => trace!("comm<-host LoadLibrary(...)"),
|
||||||
|
@ -75,7 +75,7 @@ fn handle_request(stream: &mut ::io::TcpStream,
|
||||||
Ok(request)
|
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);
|
trace!("comm->host {:?}", reply);
|
||||||
reply.write_to(stream)
|
reply.write_to(stream)
|
||||||
}
|
}
|
||||||
|
@ -139,8 +139,8 @@ fn handle_request(stream: &mut ::io::TcpStream,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_requests(stream: &mut ::io::TcpStream,
|
fn handle_requests(stream: &mut TcpStream,
|
||||||
logger: &::buffer_logger::BufferLogger) -> io::Result<()> {
|
logger: &BufferLogger) -> io::Result<()> {
|
||||||
try!(check_magic(stream));
|
try!(check_magic(stream));
|
||||||
|
|
||||||
let mut session = Session::new();
|
let mut session = Session::new();
|
||||||
|
@ -149,10 +149,10 @@ fn handle_requests(stream: &mut ::io::TcpStream,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handler(waiter: ::io::Waiter,
|
pub fn handler(waiter: Waiter,
|
||||||
logger: &::buffer_logger::BufferLogger) {
|
logger: &BufferLogger) {
|
||||||
let addr = ::io::SocketAddr::new(::io::IP_ANY, 1381);
|
let addr = SocketAddr::new(IP_ANY, 1381);
|
||||||
let listener = ::io::TcpListener::bind(waiter, addr).unwrap();
|
let listener = TcpListener::bind(waiter, addr).unwrap();
|
||||||
info!("accepting network sessions in Rust");
|
info!("accepting network sessions in Rust");
|
||||||
|
|
||||||
loop {
|
loop {
|
Loading…
Reference in New Issue