Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newsched TCP #6313

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
34be071
core::rt: Remove Close trait
brson Apr 25, 2013
0b4d4ed
core::rt: Fix a warning about unnecessary mutable variable
brson Apr 25, 2013
b2fbd34
core::rt: Begin implementing TcpStream
brson Apr 25, 2013
93ca5eb
core::rt: Clean up the interface to rtio
brson Apr 27, 2013
23bf892
core::rt: Improve docs
brson Apr 27, 2013
ab284d4
core::rt Restructure some modules
brson Apr 27, 2013
4e1fac8
Move `position` and `rposition` methods to `ImmutableVector` trait
gifnksm May 14, 2013
043d022
auto merge of #6468 : gifnksm/rust/rposition-immutable, r=brson
bors May 14, 2013
01b7b7d
core::rt: Use unsafe pointers instead of transmuted regions
brson Apr 27, 2013
b771c99
core::rt: Fix the finalizer on UvTcpStream and UvTcpListener
brson Apr 27, 2013
cfd183d
core::rt: Fix some copies in uv
brson Apr 28, 2013
6ab02c0
core::rt: Convert some uv functions to extension methods
brson Apr 28, 2013
91ca3a9
core::rt: Reording code
brson Apr 28, 2013
9138fea
core::rt: Only use one mechanism for attaching custom data to uv handles
brson Apr 28, 2013
dbf8966
core::rt: Move the implementation of IdleWatcher to its own file
brson Apr 28, 2013
a134503
core::rt: Move all the uv callback definitions to one place
brson Apr 28, 2013
ad6719e
core::rt: Just a small fix to TcpStream
brson May 3, 2013
10355d7
core::rt Wire up logging to newsched tasks
brson Apr 28, 2013
272c3c2
Tidy
brson May 3, 2013
936fce5
Warnings
brson May 3, 2013
40a9de5
core::rt: Add a very simple ref counted pointer
brson May 3, 2013
414f3c7
core::rt: Add a simple channel type for passing buffered messages bet…
brson May 5, 2013
d234cf7
core::rt: Make TCP servers work
brson May 6, 2013
101aaa3
core::rt: 0 is a valid TLS key
brson May 7, 2013
4472a50
rtdebug off
brson May 7, 2013
52f015a
core: Cleanup warnings
brson May 7, 2013
329dfca
core: Move unstable::exchange_alloc to rt::global_heap
brson May 7, 2013
f934fa7
core::rt: Docs
brson May 7, 2013
204e3d8
core::rt: Register stacks with valgrind. #6428
brson May 12, 2013
ee0ce64
core::rt: Wait for handles to close
brson May 12, 2013
b04fce6
Merge remote-tracking branch 'brson/io-upstream' into incoming
brson May 14, 2013
6a6076a
core::rt: Ignore tcp test multiple_connect_interleaved_lazy_schedule
brson May 15, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/libcore/core.rc
Expand Up @@ -205,8 +205,11 @@ mod unicode;
#[path = "num/cmath.rs"]
mod cmath;
mod stackwalk;

// XXX: This shouldn't be pub, and it should be reexported under 'unstable'
// but name resolution doesn't work without it being pub.
#[path = "rt/mod.rs"]
mod rt;
pub mod rt;

// A curious inner-module that's not exported that contains the binding
// 'core' so that macro-expanded references to core::error and such
Expand Down
63 changes: 50 additions & 13 deletions src/libcore/logging.rs
Expand Up @@ -10,17 +10,16 @@

//! Logging

pub mod rustrt {
use libc;

pub extern {
unsafe fn rust_log_console_on();
unsafe fn rust_log_console_off();
unsafe fn rust_log_str(level: u32,
string: *libc::c_char,
size: libc::size_t);
}
}
use option::*;
use either::*;
use rt;
use rt::logging::{Logger, StdErrLogger};
use io;
use libc;
use repr;
use vec;
use cast;
use str;

/// Turns on logging to stdout globally
pub fn console_on() {
Expand Down Expand Up @@ -55,8 +54,46 @@ pub fn log_type<T>(level: u32, object: &T) {
let bytes = do io::with_bytes_writer |writer| {
repr::write_repr(writer, object);
};

match rt::context() {
rt::OldTaskContext => {
unsafe {
let len = bytes.len() as libc::size_t;
rustrt::rust_log_str(level, cast::transmute(vec::raw::to_ptr(bytes)), len);
}
}
_ => {
// XXX: Bad allocation
let msg = str::from_bytes(bytes);
newsched_log_str(msg);
}
}
}

fn newsched_log_str(msg: ~str) {
unsafe {
let len = bytes.len() as libc::size_t;
rustrt::rust_log_str(level, transmute(vec::raw::to_ptr(bytes)), len);
match rt::local_services::unsafe_try_borrow_local_services() {
Some(local) => {
// Use the available logger
(*local).logger.log(Left(msg));
}
None => {
// There is no logger anywhere, just write to stderr
let mut logger = StdErrLogger;
logger.log(Left(msg));
}
}
}
}

pub mod rustrt {
use libc;

pub extern {
unsafe fn rust_log_console_on();
unsafe fn rust_log_console_off();
unsafe fn rust_log_str(level: u32,
string: *libc::c_char,
size: libc::size_t);
}
}
16 changes: 15 additions & 1 deletion src/libcore/macros.rs
Expand Up @@ -30,10 +30,24 @@ macro_rules! rtdebug (
($( $arg:expr),+) => ( $(let _ = $arg)*; )
)

macro_rules! rtassert (
( $arg:expr ) => ( {
if !$arg {
abort!("assertion failed: %s", stringify!($arg));
}
} )
)

macro_rules! abort(
($( $msg:expr),+) => ( {
rtdebug!($($msg),+);

unsafe { ::libc::abort(); }
do_abort();

// NB: This is in a fn to avoid putting the `unsafe` block in a macro,
// which causes spurious 'unnecessary unsafe block' warnings.
fn do_abort() -> ! {
unsafe { ::libc::abort(); }
}
} )
)
2 changes: 1 addition & 1 deletion src/libcore/os.rs
Expand Up @@ -722,7 +722,7 @@ pub fn list_dir(p: &Path) -> ~[~str] {
use os::win32::{
as_utf16_p
};
use unstable::exchange_alloc::{malloc_raw, free_raw};
use rt::global_heap::{malloc_raw, free_raw};
#[nolink]
extern {
unsafe fn rust_list_dir_wfd_size() -> libc::size_t;
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/rt/context.rs
Expand Up @@ -111,9 +111,9 @@ fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp:
let sp = align_down(sp);
let sp = mut_offset(sp, -4);

unsafe { *sp = arg as uint; }
unsafe { *sp = arg as uint };
let sp = mut_offset(sp, -1);
unsafe { *sp = 0; } // The final return address
unsafe { *sp = 0 }; // The final return address

regs.esp = sp as u32;
regs.eip = fptr as u32;
Expand Down Expand Up @@ -195,7 +195,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp:

fn align_down(sp: *mut uint) -> *mut uint {
unsafe {
let sp = transmute::<*mut uint, uint>(sp);
let sp: uint = transmute(sp);
let sp = sp & !(16 - 1);
transmute::<uint, *mut uint>(sp)
}
Expand Down
File renamed without changes.
6 changes: 1 addition & 5 deletions src/libcore/rt/io/file.rs
Expand Up @@ -10,7 +10,7 @@

use prelude::*;
use super::support::PathLike;
use super::{Reader, Writer, Seek, Close};
use super::{Reader, Writer, Seek};
use super::SeekStyle;

/// # XXX
Expand Down Expand Up @@ -69,10 +69,6 @@ impl Seek for FileStream {
fn seek(&mut self, _pos: i64, _style: SeekStyle) { fail!() }
}

impl Close for FileStream {
fn close(&mut self) { fail!() }
}

#[test]
#[ignore]
fn super_simple_smoke_test_lets_go_read_some_files_and_have_a_good_time() {
Expand Down
23 changes: 10 additions & 13 deletions src/libcore/rt/io/mod.rs
Expand Up @@ -238,6 +238,7 @@ Out of scope
* How does I/O relate to the Iterator trait?
* std::base64 filters
* Using conditions is a big unknown since we don't have much experience with them
* Too many uses of OtherIoError

*/

Expand All @@ -252,7 +253,9 @@ pub use self::stdio::println;

pub use self::file::FileStream;
pub use self::net::ip::IpAddr;
#[cfg(not(stage0))]
pub use self::net::tcp::TcpListener;
#[cfg(not(stage0))]
pub use self::net::tcp::TcpStream;
pub use self::net::udp::UdpStream;

Expand All @@ -266,6 +269,7 @@ pub mod file;

/// Synchronous, non-blocking network I/O.
pub mod net {
#[cfg(not(stage0))]
pub mod tcp;
pub mod udp;
pub mod ip;
Expand Down Expand Up @@ -326,12 +330,14 @@ pub struct IoError {

#[deriving(Eq)]
pub enum IoErrorKind {
PreviousIoError,
OtherIoError,
EndOfFile,
FileNotFound,
FilePermission,
PermissionDenied,
ConnectionFailed,
Closed,
OtherIoError,
PreviousIoError
ConnectionRefused,
}

// XXX: Can't put doc comments on macros
Expand Down Expand Up @@ -383,16 +389,7 @@ pub trait Writer {
fn flush(&mut self);
}

/// I/O types that may be closed
///
/// Any further operations performed on a closed resource will raise
/// on `io_error`
pub trait Close {
/// Close the I/O resource
fn close(&mut self);
}

pub trait Stream: Reader + Writer + Close { }
pub trait Stream: Reader + Writer { }

pub enum SeekStyle {
/// Seek from the beginning of the stream
Expand Down
8 changes: 0 additions & 8 deletions src/libcore/rt/io/native/file.rs
Expand Up @@ -40,10 +40,6 @@ impl Writer for FileDesc {
fn flush(&mut self) { fail!() }
}

impl Close for FileDesc {
fn close(&mut self) { fail!() }
}

impl Seek for FileDesc {
fn tell(&self) -> u64 { fail!() }

Expand Down Expand Up @@ -72,10 +68,6 @@ impl Writer for CFile {
fn flush(&mut self) { fail!() }
}

impl Close for CFile {
fn close(&mut self) { fail!() }
}

impl Seek for CFile {
fn tell(&self) -> u64 { fail!() }
fn seek(&mut self, _pos: i64, _style: SeekStyle) { fail!() }
Expand Down