Remove IoFactoryObject for ~IoFactory
This involved changing a fair amount of code, rooted in how we access the local IoFactory instance. I added a helper method to the rtio module to access the optional local IoFactory. This is different than before in which it was assumed that a local IoFactory was *always* present. Now, a separate io_error is raised when an IoFactory is not present, yet I/O is requested.
This commit is contained in:
@@ -382,6 +382,7 @@ mod tests {
|
|||||||
use libc;
|
use libc;
|
||||||
use ptr;
|
use ptr;
|
||||||
use option::{Some, None};
|
use option::{Some, None};
|
||||||
|
use vec;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_str_multistring_parsing() {
|
fn test_str_multistring_parsing() {
|
||||||
@@ -391,7 +392,8 @@ mod tests {
|
|||||||
let expected = ["zero", "one"];
|
let expected = ["zero", "one"];
|
||||||
let mut it = expected.iter();
|
let mut it = expected.iter();
|
||||||
let result = do from_c_multistring(ptr as *libc::c_char, None) |c| {
|
let result = do from_c_multistring(ptr as *libc::c_char, None) |c| {
|
||||||
assert_eq!(c.as_str(), expected.next().unwrap());
|
let cbytes = c.as_bytes().slice_to(c.len());
|
||||||
|
assert_eq!(cbytes, it.next().unwrap().as_bytes());
|
||||||
};
|
};
|
||||||
assert_eq!(result, 2);
|
assert_eq!(result, 2);
|
||||||
assert!(it.next().is_none());
|
assert!(it.next().is_none());
|
||||||
|
|||||||
@@ -34,12 +34,11 @@ use prelude::*;
|
|||||||
use c_str::ToCStr;
|
use c_str::ToCStr;
|
||||||
use super::{Reader, Writer, Seek};
|
use super::{Reader, Writer, Seek};
|
||||||
use super::{SeekStyle, Read, Write};
|
use super::{SeekStyle, Read, Write};
|
||||||
use rt::rtio::{RtioFileStream, IoFactory, IoFactoryObject};
|
use rt::rtio::{RtioFileStream, IoFactory, with_local_io};
|
||||||
use rt::io::{io_error, read_error, EndOfFile,
|
use rt::io::{io_error, read_error, EndOfFile,
|
||||||
FileMode, FileAccess, FileStat, IoError,
|
FileMode, FileAccess, FileStat, IoError,
|
||||||
PathAlreadyExists, PathDoesntExist,
|
PathAlreadyExists, PathDoesntExist,
|
||||||
MismatchedFileTypeForOperation, ignore_io_error};
|
MismatchedFileTypeForOperation, ignore_io_error};
|
||||||
use rt::local::Local;
|
|
||||||
use option::{Some, None};
|
use option::{Some, None};
|
||||||
use path::Path;
|
use path::Path;
|
||||||
|
|
||||||
@@ -91,11 +90,8 @@ pub fn open<P: ToCStr>(path: &P,
|
|||||||
mode: FileMode,
|
mode: FileMode,
|
||||||
access: FileAccess
|
access: FileAccess
|
||||||
) -> Option<FileStream> {
|
) -> Option<FileStream> {
|
||||||
let open_result = unsafe {
|
do with_local_io |io| {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.fs_open(&path.to_c_str(), mode, access) {
|
||||||
(*io).fs_open(&path.to_c_str(), mode, access)
|
|
||||||
};
|
|
||||||
match open_result {
|
|
||||||
Ok(fd) => Some(FileStream {
|
Ok(fd) => Some(FileStream {
|
||||||
fd: fd,
|
fd: fd,
|
||||||
last_nread: -1
|
last_nread: -1
|
||||||
@@ -106,6 +102,7 @@ pub fn open<P: ToCStr>(path: &P,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Unlink a file from the underlying filesystem.
|
/// Unlink a file from the underlying filesystem.
|
||||||
///
|
///
|
||||||
@@ -129,16 +126,15 @@ pub fn open<P: ToCStr>(path: &P,
|
|||||||
/// This function will raise an `io_error` condition if the user lacks permissions to
|
/// This function will raise an `io_error` condition if the user lacks permissions to
|
||||||
/// remove the file or if some other filesystem-level error occurs
|
/// remove the file or if some other filesystem-level error occurs
|
||||||
pub fn unlink<P: ToCStr>(path: &P) {
|
pub fn unlink<P: ToCStr>(path: &P) {
|
||||||
let unlink_result = unsafe {
|
do with_local_io |io| {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.fs_unlink(&path.to_c_str()) {
|
||||||
(*io).fs_unlink(&path.to_c_str())
|
Ok(_) => Some(()),
|
||||||
};
|
|
||||||
match unlink_result {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(ioerr) => {
|
Err(ioerr) => {
|
||||||
io_error::cond.raise(ioerr);
|
io_error::cond.raise(ioerr);
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new, empty directory at the provided path
|
/// Create a new, empty directory at the provided path
|
||||||
@@ -158,16 +154,15 @@ pub fn unlink<P: ToCStr>(path: &P) {
|
|||||||
/// This call will raise an `io_error` condition if the user lacks permissions to make a
|
/// This call will raise an `io_error` condition if the user lacks permissions to make a
|
||||||
/// new directory at the provided path, or if the directory already exists
|
/// new directory at the provided path, or if the directory already exists
|
||||||
pub fn mkdir<P: ToCStr>(path: &P) {
|
pub fn mkdir<P: ToCStr>(path: &P) {
|
||||||
let mkdir_result = unsafe {
|
do with_local_io |io| {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.fs_mkdir(&path.to_c_str()) {
|
||||||
(*io).fs_mkdir(&path.to_c_str())
|
Ok(_) => Some(()),
|
||||||
};
|
|
||||||
match mkdir_result {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(ioerr) => {
|
Err(ioerr) => {
|
||||||
io_error::cond.raise(ioerr);
|
io_error::cond.raise(ioerr);
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove an existing, empty directory
|
/// Remove an existing, empty directory
|
||||||
@@ -187,16 +182,15 @@ pub fn mkdir<P: ToCStr>(path: &P) {
|
|||||||
/// This call will raise an `io_error` condition if the user lacks permissions to remove the
|
/// This call will raise an `io_error` condition if the user lacks permissions to remove the
|
||||||
/// directory at the provided path, or if the directory isn't empty
|
/// directory at the provided path, or if the directory isn't empty
|
||||||
pub fn rmdir<P: ToCStr>(path: &P) {
|
pub fn rmdir<P: ToCStr>(path: &P) {
|
||||||
let rmdir_result = unsafe {
|
do with_local_io |io| {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.fs_rmdir(&path.to_c_str()) {
|
||||||
(*io).fs_rmdir(&path.to_c_str())
|
Ok(_) => Some(()),
|
||||||
};
|
|
||||||
match rmdir_result {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(ioerr) => {
|
Err(ioerr) => {
|
||||||
io_error::cond.raise(ioerr);
|
io_error::cond.raise(ioerr);
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get information on the file, directory, etc at the provided path
|
/// Get information on the file, directory, etc at the provided path
|
||||||
@@ -235,20 +229,16 @@ pub fn rmdir<P: ToCStr>(path: &P) {
|
|||||||
/// permissions to perform a `stat` call on the given path or if there is no
|
/// permissions to perform a `stat` call on the given path or if there is no
|
||||||
/// entry in the filesystem at the provided path.
|
/// entry in the filesystem at the provided path.
|
||||||
pub fn stat<P: ToCStr>(path: &P) -> Option<FileStat> {
|
pub fn stat<P: ToCStr>(path: &P) -> Option<FileStat> {
|
||||||
let open_result = unsafe {
|
do with_local_io |io| {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.fs_stat(&path.to_c_str()) {
|
||||||
(*io).fs_stat(&path.to_c_str())
|
Ok(p) => Some(p),
|
||||||
};
|
|
||||||
match open_result {
|
|
||||||
Ok(p) => {
|
|
||||||
Some(p)
|
|
||||||
},
|
|
||||||
Err(ioerr) => {
|
Err(ioerr) => {
|
||||||
io_error::cond.raise(ioerr);
|
io_error::cond.raise(ioerr);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Retrieve a vector containing all entries within a provided directory
|
/// Retrieve a vector containing all entries within a provided directory
|
||||||
///
|
///
|
||||||
@@ -275,20 +265,16 @@ pub fn stat<P: ToCStr>(path: &P) -> Option<FileStat> {
|
|||||||
/// the process lacks permissions to view the contents or if the `path` points
|
/// the process lacks permissions to view the contents or if the `path` points
|
||||||
/// at a non-directory file
|
/// at a non-directory file
|
||||||
pub fn readdir<P: ToCStr>(path: &P) -> Option<~[Path]> {
|
pub fn readdir<P: ToCStr>(path: &P) -> Option<~[Path]> {
|
||||||
let readdir_result = unsafe {
|
do with_local_io |io| {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.fs_readdir(&path.to_c_str(), 0) {
|
||||||
(*io).fs_readdir(&path.to_c_str(), 0)
|
Ok(p) => Some(p),
|
||||||
};
|
|
||||||
match readdir_result {
|
|
||||||
Ok(p) => {
|
|
||||||
Some(p)
|
|
||||||
},
|
|
||||||
Err(ioerr) => {
|
Err(ioerr) => {
|
||||||
io_error::cond.raise(ioerr);
|
io_error::cond.raise(ioerr);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Constrained version of `FileStream` that only exposes read-specific operations.
|
/// Constrained version of `FileStream` that only exposes read-specific operations.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -369,7 +369,8 @@ pub enum IoErrorKind {
|
|||||||
BrokenPipe,
|
BrokenPipe,
|
||||||
PathAlreadyExists,
|
PathAlreadyExists,
|
||||||
PathDoesntExist,
|
PathDoesntExist,
|
||||||
MismatchedFileTypeForOperation
|
MismatchedFileTypeForOperation,
|
||||||
|
IoUnavailable,
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: #8242 implementing manually because deriving doesn't work for some reason
|
// FIXME: #8242 implementing manually because deriving doesn't work for some reason
|
||||||
@@ -389,7 +390,8 @@ impl ToStr for IoErrorKind {
|
|||||||
BrokenPipe => ~"BrokenPipe",
|
BrokenPipe => ~"BrokenPipe",
|
||||||
PathAlreadyExists => ~"PathAlreadyExists",
|
PathAlreadyExists => ~"PathAlreadyExists",
|
||||||
PathDoesntExist => ~"PathDoesntExist",
|
PathDoesntExist => ~"PathDoesntExist",
|
||||||
MismatchedFileTypeForOperation => ~"MismatchedFileTypeForOperation"
|
MismatchedFileTypeForOperation => ~"MismatchedFileTypeForOperation",
|
||||||
|
IoUnavailable => ~"IoUnavailable",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,9 @@ getaddrinfo()
|
|||||||
|
|
||||||
use option::{Option, Some, None};
|
use option::{Option, Some, None};
|
||||||
use result::{Ok, Err};
|
use result::{Ok, Err};
|
||||||
use rt::io::io_error;
|
use rt::io::{io_error};
|
||||||
use rt::io::net::ip::{SocketAddr, IpAddr};
|
use rt::io::net::ip::{SocketAddr, IpAddr};
|
||||||
use rt::rtio::{IoFactory, IoFactoryObject};
|
use rt::rtio::{IoFactory, with_local_io};
|
||||||
use rt::local::Local;
|
|
||||||
|
|
||||||
/// Hints to the types of sockets that are desired when looking up hosts
|
/// Hints to the types of sockets that are desired when looking up hosts
|
||||||
pub enum SocketType {
|
pub enum SocketType {
|
||||||
@@ -94,12 +93,8 @@ pub fn get_host_addresses(host: &str) -> Option<~[IpAddr]> {
|
|||||||
/// On failure, this will raise on the `io_error` condition.
|
/// On failure, this will raise on the `io_error` condition.
|
||||||
pub fn lookup(hostname: Option<&str>, servname: Option<&str>,
|
pub fn lookup(hostname: Option<&str>, servname: Option<&str>,
|
||||||
hint: Option<Hint>) -> Option<~[Info]> {
|
hint: Option<Hint>) -> Option<~[Info]> {
|
||||||
let ipaddrs = unsafe {
|
do with_local_io |io| {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.get_host_addresses(hostname, servname, hint) {
|
||||||
(*io).get_host_addresses(hostname, servname, hint)
|
|
||||||
};
|
|
||||||
|
|
||||||
match ipaddrs {
|
|
||||||
Ok(i) => Some(i),
|
Ok(i) => Some(i),
|
||||||
Err(ioerr) => {
|
Err(ioerr) => {
|
||||||
io_error::cond.raise(ioerr);
|
io_error::cond.raise(ioerr);
|
||||||
@@ -107,6 +102,7 @@ pub fn lookup(hostname: Option<&str>, servname: Option<&str>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
|||||||
@@ -13,9 +13,8 @@ use result::{Ok, Err};
|
|||||||
use rt::io::net::ip::SocketAddr;
|
use rt::io::net::ip::SocketAddr;
|
||||||
use rt::io::{Reader, Writer, Listener, Acceptor};
|
use rt::io::{Reader, Writer, Listener, Acceptor};
|
||||||
use rt::io::{io_error, read_error, EndOfFile};
|
use rt::io::{io_error, read_error, EndOfFile};
|
||||||
use rt::rtio::{IoFactory, IoFactoryObject, RtioTcpListenerObject,
|
use rt::rtio::{IoFactory, RtioTcpListenerObject, with_local_io,
|
||||||
RtioSocket, RtioTcpListener, RtioTcpAcceptor, RtioTcpStream};
|
RtioSocket, RtioTcpListener, RtioTcpAcceptor, RtioTcpStream};
|
||||||
use rt::local::Local;
|
|
||||||
|
|
||||||
pub struct TcpStream {
|
pub struct TcpStream {
|
||||||
priv obj: ~RtioTcpStream
|
priv obj: ~RtioTcpStream
|
||||||
@@ -27,22 +26,16 @@ impl TcpStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn connect(addr: SocketAddr) -> Option<TcpStream> {
|
pub fn connect(addr: SocketAddr) -> Option<TcpStream> {
|
||||||
let stream = unsafe {
|
do with_local_io |io| {
|
||||||
rtdebug!("borrowing io to connect");
|
match io.tcp_connect(addr) {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
|
||||||
rtdebug!("about to connect");
|
|
||||||
(*io).tcp_connect(addr)
|
|
||||||
};
|
|
||||||
|
|
||||||
match stream {
|
|
||||||
Ok(s) => Some(TcpStream::new(s)),
|
Ok(s) => Some(TcpStream::new(s)),
|
||||||
Err(ioerr) => {
|
Err(ioerr) => {
|
||||||
rtdebug!("failed to connect: {:?}", ioerr);
|
|
||||||
io_error::cond.raise(ioerr);
|
io_error::cond.raise(ioerr);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn peer_name(&mut self) -> Option<SocketAddr> {
|
pub fn peer_name(&mut self) -> Option<SocketAddr> {
|
||||||
match self.obj.peer_name() {
|
match self.obj.peer_name() {
|
||||||
@@ -101,15 +94,13 @@ pub struct TcpListener {
|
|||||||
|
|
||||||
impl TcpListener {
|
impl TcpListener {
|
||||||
pub fn bind(addr: SocketAddr) -> Option<TcpListener> {
|
pub fn bind(addr: SocketAddr) -> Option<TcpListener> {
|
||||||
let listener = unsafe {
|
do with_local_io |io| {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.tcp_bind(addr) {
|
||||||
(*io).tcp_bind(addr)
|
|
||||||
};
|
|
||||||
match listener {
|
|
||||||
Ok(l) => Some(TcpListener { obj: l }),
|
Ok(l) => Some(TcpListener { obj: l }),
|
||||||
Err(ioerr) => {
|
Err(ioerr) => {
|
||||||
io_error::cond.raise(ioerr);
|
io_error::cond.raise(ioerr);
|
||||||
return None;
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ use result::{Ok, Err};
|
|||||||
use rt::io::net::ip::SocketAddr;
|
use rt::io::net::ip::SocketAddr;
|
||||||
use rt::io::{Reader, Writer};
|
use rt::io::{Reader, Writer};
|
||||||
use rt::io::{io_error, read_error, EndOfFile};
|
use rt::io::{io_error, read_error, EndOfFile};
|
||||||
use rt::rtio::{RtioSocket, RtioUdpSocket, IoFactory, IoFactoryObject};
|
use rt::rtio::{RtioSocket, RtioUdpSocket, IoFactory, with_local_io};
|
||||||
use rt::local::Local;
|
|
||||||
|
|
||||||
pub struct UdpSocket {
|
pub struct UdpSocket {
|
||||||
priv obj: ~RtioUdpSocket
|
priv obj: ~RtioUdpSocket
|
||||||
@@ -22,11 +21,8 @@ pub struct UdpSocket {
|
|||||||
|
|
||||||
impl UdpSocket {
|
impl UdpSocket {
|
||||||
pub fn bind(addr: SocketAddr) -> Option<UdpSocket> {
|
pub fn bind(addr: SocketAddr) -> Option<UdpSocket> {
|
||||||
let socket = unsafe {
|
do with_local_io |io| {
|
||||||
let factory: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.udp_bind(addr) {
|
||||||
(*factory).udp_bind(addr)
|
|
||||||
};
|
|
||||||
match socket {
|
|
||||||
Ok(s) => Some(UdpSocket { obj: s }),
|
Ok(s) => Some(UdpSocket { obj: s }),
|
||||||
Err(ioerr) => {
|
Err(ioerr) => {
|
||||||
io_error::cond.raise(ioerr);
|
io_error::cond.raise(ioerr);
|
||||||
@@ -34,6 +30,7 @@ impl UdpSocket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn recvfrom(&mut self, buf: &mut [u8]) -> Option<(uint, SocketAddr)> {
|
pub fn recvfrom(&mut self, buf: &mut [u8]) -> Option<(uint, SocketAddr)> {
|
||||||
match self.obj.recvfrom(buf) {
|
match self.obj.recvfrom(buf) {
|
||||||
|
|||||||
@@ -25,11 +25,10 @@ instances as clients.
|
|||||||
use prelude::*;
|
use prelude::*;
|
||||||
|
|
||||||
use c_str::ToCStr;
|
use c_str::ToCStr;
|
||||||
use rt::rtio::{IoFactory, IoFactoryObject, RtioUnixListener};
|
use rt::rtio::{IoFactory, RtioUnixListener, with_local_io};
|
||||||
use rt::rtio::{RtioUnixAcceptor, RtioPipe, RtioUnixListenerObject};
|
use rt::rtio::{RtioUnixAcceptor, RtioPipe, RtioUnixListenerObject};
|
||||||
use rt::io::pipe::PipeStream;
|
use rt::io::pipe::PipeStream;
|
||||||
use rt::io::{io_error, Listener, Acceptor, Reader, Writer};
|
use rt::io::{io_error, Listener, Acceptor, Reader, Writer};
|
||||||
use rt::local::Local;
|
|
||||||
|
|
||||||
/// A stream which communicates over a named pipe.
|
/// A stream which communicates over a named pipe.
|
||||||
pub struct UnixStream {
|
pub struct UnixStream {
|
||||||
@@ -60,12 +59,8 @@ impl UnixStream {
|
|||||||
/// stream.write([1, 2, 3]);
|
/// stream.write([1, 2, 3]);
|
||||||
///
|
///
|
||||||
pub fn connect<P: ToCStr>(path: &P) -> Option<UnixStream> {
|
pub fn connect<P: ToCStr>(path: &P) -> Option<UnixStream> {
|
||||||
let pipe = unsafe {
|
do with_local_io |io| {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.unix_connect(&path.to_c_str()) {
|
||||||
(*io).unix_connect(path)
|
|
||||||
};
|
|
||||||
|
|
||||||
match pipe {
|
|
||||||
Ok(s) => Some(UnixStream::new(s)),
|
Ok(s) => Some(UnixStream::new(s)),
|
||||||
Err(ioerr) => {
|
Err(ioerr) => {
|
||||||
io_error::cond.raise(ioerr);
|
io_error::cond.raise(ioerr);
|
||||||
@@ -74,6 +69,7 @@ impl UnixStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Reader for UnixStream {
|
impl Reader for UnixStream {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> Option<uint> { self.obj.read(buf) }
|
fn read(&mut self, buf: &mut [u8]) -> Option<uint> { self.obj.read(buf) }
|
||||||
@@ -113,11 +109,8 @@ impl UnixListener {
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
pub fn bind<P: ToCStr>(path: &P) -> Option<UnixListener> {
|
pub fn bind<P: ToCStr>(path: &P) -> Option<UnixListener> {
|
||||||
let listener = unsafe {
|
do with_local_io |io| {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.unix_bind(&path.to_c_str()) {
|
||||||
(*io).unix_bind(path)
|
|
||||||
};
|
|
||||||
match listener {
|
|
||||||
Ok(s) => Some(UnixListener{ obj: s }),
|
Ok(s) => Some(UnixListener{ obj: s }),
|
||||||
Err(ioerr) => {
|
Err(ioerr) => {
|
||||||
io_error::cond.raise(ioerr);
|
io_error::cond.raise(ioerr);
|
||||||
@@ -126,6 +119,7 @@ impl UnixListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Listener<UnixStream, UnixAcceptor> for UnixListener {
|
impl Listener<UnixStream, UnixAcceptor> for UnixListener {
|
||||||
fn listen(self) -> Option<UnixAcceptor> {
|
fn listen(self) -> Option<UnixAcceptor> {
|
||||||
|
|||||||
@@ -11,12 +11,12 @@
|
|||||||
//! Bindings for executing child processes
|
//! Bindings for executing child processes
|
||||||
|
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
|
use cell::Cell;
|
||||||
|
|
||||||
use libc;
|
use libc;
|
||||||
use rt::io;
|
use rt::io;
|
||||||
use rt::io::io_error;
|
use rt::io::io_error;
|
||||||
use rt::local::Local;
|
use rt::rtio::{RtioProcess, IoFactory, with_local_io};
|
||||||
use rt::rtio::{RtioProcess, IoFactoryObject, IoFactory};
|
|
||||||
|
|
||||||
// windows values don't matter as long as they're at least one of unix's
|
// windows values don't matter as long as they're at least one of unix's
|
||||||
// TERM/KILL/INT signals
|
// TERM/KILL/INT signals
|
||||||
@@ -83,11 +83,9 @@ impl Process {
|
|||||||
/// Creates a new pipe initialized, but not bound to any particular
|
/// Creates a new pipe initialized, but not bound to any particular
|
||||||
/// source/destination
|
/// source/destination
|
||||||
pub fn new(config: ProcessConfig) -> Option<Process> {
|
pub fn new(config: ProcessConfig) -> Option<Process> {
|
||||||
let process = unsafe {
|
let config = Cell::new(config);
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
do with_local_io |io| {
|
||||||
(*io).spawn(config)
|
match io.spawn(config.take()) {
|
||||||
};
|
|
||||||
match process {
|
|
||||||
Ok((p, io)) => Some(Process{
|
Ok((p, io)) => Some(Process{
|
||||||
handle: p,
|
handle: p,
|
||||||
io: io.move_iter().map(|p|
|
io: io.move_iter().map(|p|
|
||||||
@@ -100,6 +98,7 @@ impl Process {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the process id of this child process
|
/// Returns the process id of this child process
|
||||||
pub fn id(&self) -> libc::pid_t { self.handle.id() }
|
pub fn id(&self) -> libc::pid_t { self.handle.id() }
|
||||||
|
|||||||
@@ -12,19 +12,22 @@ use fmt;
|
|||||||
use libc;
|
use libc;
|
||||||
use option::{Option, Some, None};
|
use option::{Option, Some, None};
|
||||||
use result::{Ok, Err};
|
use result::{Ok, Err};
|
||||||
use rt::local::Local;
|
use rt::rtio::{IoFactory, RtioTTY, with_local_io};
|
||||||
use rt::rtio::{IoFactoryObject, IoFactory, RtioTTY};
|
|
||||||
use super::{Reader, Writer, io_error};
|
use super::{Reader, Writer, io_error};
|
||||||
|
|
||||||
/// Creates a new non-blocking handle to the stdin of the current process.
|
/// Creates a new non-blocking handle to the stdin of the current process.
|
||||||
///
|
///
|
||||||
/// See `stdout()` for notes about this function.
|
/// See `stdout()` for notes about this function.
|
||||||
pub fn stdin() -> StdReader {
|
pub fn stdin() -> StdReader {
|
||||||
let stream = unsafe {
|
do with_local_io |io| {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.tty_open(libc::STDIN_FILENO, true, false) {
|
||||||
(*io).tty_open(libc::STDIN_FILENO, true, false)
|
Ok(tty) => Some(StdReader { inner: tty }),
|
||||||
}.unwrap();
|
Err(e) => {
|
||||||
StdReader { inner: stream }
|
io_error::cond.raise(e);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new non-blocking handle to the stdout of the current process.
|
/// Creates a new non-blocking handle to the stdout of the current process.
|
||||||
@@ -34,22 +37,30 @@ pub fn stdin() -> StdReader {
|
|||||||
/// task context because the stream returned will be a non-blocking object using
|
/// task context because the stream returned will be a non-blocking object using
|
||||||
/// the local scheduler to perform the I/O.
|
/// the local scheduler to perform the I/O.
|
||||||
pub fn stdout() -> StdWriter {
|
pub fn stdout() -> StdWriter {
|
||||||
let stream = unsafe {
|
do with_local_io |io| {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.tty_open(libc::STDOUT_FILENO, false, false) {
|
||||||
(*io).tty_open(libc::STDOUT_FILENO, false, false)
|
Ok(tty) => Some(StdWriter { inner: tty }),
|
||||||
}.unwrap();
|
Err(e) => {
|
||||||
StdWriter { inner: stream }
|
io_error::cond.raise(e);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new non-blocking handle to the stderr of the current process.
|
/// Creates a new non-blocking handle to the stderr of the current process.
|
||||||
///
|
///
|
||||||
/// See `stdout()` for notes about this function.
|
/// See `stdout()` for notes about this function.
|
||||||
pub fn stderr() -> StdWriter {
|
pub fn stderr() -> StdWriter {
|
||||||
let stream = unsafe {
|
do with_local_io |io| {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
match io.tty_open(libc::STDERR_FILENO, false, false) {
|
||||||
(*io).tty_open(libc::STDERR_FILENO, false, false)
|
Ok(tty) => Some(StdWriter { inner: tty }),
|
||||||
}.unwrap();
|
Err(e) => {
|
||||||
StdWriter { inner: stream }
|
io_error::cond.raise(e);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints a string to the stdout of the current process. No newline is emitted
|
/// Prints a string to the stdout of the current process. No newline is emitted
|
||||||
|
|||||||
@@ -10,9 +10,8 @@
|
|||||||
|
|
||||||
use option::{Option, Some, None};
|
use option::{Option, Some, None};
|
||||||
use result::{Ok, Err};
|
use result::{Ok, Err};
|
||||||
use rt::io::{io_error};
|
use rt::io::io_error;
|
||||||
use rt::rtio::{IoFactory, IoFactoryObject, RtioTimer};
|
use rt::rtio::{IoFactory, RtioTimer, with_local_io};
|
||||||
use rt::local::Local;
|
|
||||||
|
|
||||||
pub struct Timer {
|
pub struct Timer {
|
||||||
priv obj: ~RtioTimer
|
priv obj: ~RtioTimer
|
||||||
@@ -27,14 +26,11 @@ pub fn sleep(msecs: u64) {
|
|||||||
|
|
||||||
impl Timer {
|
impl Timer {
|
||||||
|
|
||||||
|
/// Creates a new timer which can be used to put the current task to sleep
|
||||||
|
/// for a number of milliseconds.
|
||||||
pub fn new() -> Option<Timer> {
|
pub fn new() -> Option<Timer> {
|
||||||
let timer = unsafe {
|
do with_local_io |io| {
|
||||||
rtdebug!("Timer::init: borrowing io to init timer");
|
match io.timer_init() {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
|
||||||
rtdebug!("about to init timer");
|
|
||||||
(*io).timer_init()
|
|
||||||
};
|
|
||||||
match timer {
|
|
||||||
Ok(t) => Some(Timer { obj: t }),
|
Ok(t) => Some(Timer { obj: t }),
|
||||||
Err(ioerr) => {
|
Err(ioerr) => {
|
||||||
rtdebug!("Timer::init: failed to init: {:?}", ioerr);
|
rtdebug!("Timer::init: failed to init: {:?}", ioerr);
|
||||||
@@ -42,6 +38,8 @@ impl Timer {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sleep(&mut self, msecs: u64) {
|
pub fn sleep(&mut self, msecs: u64) {
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ use option::{Option, Some, None};
|
|||||||
use rt::sched::Scheduler;
|
use rt::sched::Scheduler;
|
||||||
use rt::task::Task;
|
use rt::task::Task;
|
||||||
use rt::local_ptr;
|
use rt::local_ptr;
|
||||||
use rt::rtio::{EventLoop, IoFactoryObject};
|
|
||||||
//use borrow::to_uint;
|
|
||||||
use cell::Cell;
|
use cell::Cell;
|
||||||
|
|
||||||
pub trait Local {
|
pub trait Local {
|
||||||
@@ -122,24 +120,6 @@ impl Local for Scheduler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: This formulation won't work once ~IoFactoryObject is a real trait pointer
|
|
||||||
impl Local for IoFactoryObject {
|
|
||||||
fn put(_value: ~IoFactoryObject) { rtabort!("unimpl") }
|
|
||||||
fn take() -> ~IoFactoryObject { rtabort!("unimpl") }
|
|
||||||
fn exists(_: Option<IoFactoryObject>) -> bool { rtabort!("unimpl") }
|
|
||||||
fn borrow<T>(_f: &fn(&mut IoFactoryObject) -> T) -> T { rtabort!("unimpl") }
|
|
||||||
unsafe fn unsafe_take() -> ~IoFactoryObject { rtabort!("unimpl") }
|
|
||||||
unsafe fn unsafe_borrow() -> *mut IoFactoryObject {
|
|
||||||
let sched: *mut Scheduler = Local::unsafe_borrow();
|
|
||||||
let io: *mut IoFactoryObject = (*sched).event_loop.io().unwrap();
|
|
||||||
return io;
|
|
||||||
}
|
|
||||||
unsafe fn try_unsafe_borrow() -> Option<*mut IoFactoryObject> {
|
|
||||||
rtabort!("unimpl")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use option::None;
|
use option::None;
|
||||||
|
|||||||
@@ -33,8 +33,10 @@ pub trait EventLoop {
|
|||||||
fn pausible_idle_callback(&mut self) -> ~PausibleIdleCallback;
|
fn pausible_idle_callback(&mut self) -> ~PausibleIdleCallback;
|
||||||
fn callback_ms(&mut self, ms: u64, ~fn());
|
fn callback_ms(&mut self, ms: u64, ~fn());
|
||||||
fn remote_callback(&mut self, ~fn()) -> ~RemoteCallback;
|
fn remote_callback(&mut self, ~fn()) -> ~RemoteCallback;
|
||||||
|
|
||||||
/// The asynchronous I/O services. Not all event loops may provide one
|
/// The asynchronous I/O services. Not all event loops may provide one
|
||||||
fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory>;
|
// FIXME(#9382) this is an awful interface
|
||||||
|
fn io<'a>(&'a mut self, f: &fn(&'a mut IoFactory));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RemoteCallback {
|
pub trait RemoteCallback {
|
||||||
@@ -59,16 +61,36 @@ pub struct FileOpenConfig {
|
|||||||
priv mode: int
|
priv mode: int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_local_io<T>(f: &fn(&mut IoFactory) -> Option<T>) -> Option<T> {
|
||||||
|
use rt::sched::Scheduler;
|
||||||
|
use rt::local::Local;
|
||||||
|
use rt::io::{io_error, standard_error, IoUnavailable};
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let sched: *mut Scheduler = Local::unsafe_borrow();
|
||||||
|
let mut io = None;
|
||||||
|
(*sched).event_loop.io(|i| io = Some(i));
|
||||||
|
match io {
|
||||||
|
Some(io) => f(io),
|
||||||
|
None => {
|
||||||
|
io_error::cond.raise(standard_error(IoUnavailable));
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait IoFactory {
|
pub trait IoFactory {
|
||||||
fn tcp_connect(&mut self, addr: SocketAddr) -> Result<~RtioTcpStream, IoError>;
|
fn tcp_connect(&mut self, addr: SocketAddr) -> Result<~RtioTcpStream, IoError>;
|
||||||
fn tcp_bind(&mut self, addr: SocketAddr) -> Result<~RtioTcpListenerObject, IoError>;
|
fn tcp_bind(&mut self, addr: SocketAddr) -> Result<~RtioTcpListenerObject, IoError>;
|
||||||
fn udp_bind(&mut self, addr: SocketAddr) -> Result<~RtioUdpSocket, IoError>;
|
fn udp_bind(&mut self, addr: SocketAddr) -> Result<~RtioUdpSocket, IoError>;
|
||||||
|
fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>,
|
||||||
|
hint: Option<ai::Hint>) -> Result<~[ai::Info], IoError>;
|
||||||
fn timer_init(&mut self) -> Result<~RtioTimer, IoError>;
|
fn timer_init(&mut self) -> Result<~RtioTimer, IoError>;
|
||||||
fn fs_from_raw_fd(&mut self, fd: c_int, close_on_drop: bool) -> ~RtioFileStream;
|
fn fs_from_raw_fd(&mut self, fd: c_int, close_on_drop: bool) -> ~RtioFileStream;
|
||||||
fn fs_open(&mut self, path: &CString, fm: FileMode, fa: FileAccess)
|
fn fs_open(&mut self, path: &CString, fm: FileMode, fa: FileAccess)
|
||||||
-> Result<~RtioFileStream, IoError>;
|
-> Result<~RtioFileStream, IoError>;
|
||||||
fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>,
|
fn fs_unlink(&mut self, path: &CString) -> Result<(), IoError>;
|
||||||
hint: Option<ai::Hint>) -> Result<~[ai::Info], IoError>;
|
|
||||||
fn fs_stat(&mut self, path: &CString) -> Result<FileStat, IoError>;
|
fn fs_stat(&mut self, path: &CString) -> Result<FileStat, IoError>;
|
||||||
fn fs_mkdir(&mut self, path: &CString) -> Result<(), IoError>;
|
fn fs_mkdir(&mut self, path: &CString) -> Result<(), IoError>;
|
||||||
fn fs_rmdir(&mut self, path: &CString) -> Result<(), IoError>;
|
fn fs_rmdir(&mut self, path: &CString) -> Result<(), IoError>;
|
||||||
@@ -77,10 +99,9 @@ pub trait IoFactory {
|
|||||||
fn spawn(&mut self, config: ProcessConfig)
|
fn spawn(&mut self, config: ProcessConfig)
|
||||||
-> Result<(~RtioProcess, ~[Option<~RtioPipe>]), IoError>;
|
-> Result<(~RtioProcess, ~[Option<~RtioPipe>]), IoError>;
|
||||||
|
|
||||||
fn unix_bind<P: PathLike>(&mut self, path: &P) ->
|
fn unix_bind(&mut self, path: &CString) ->
|
||||||
Result<~RtioUnixListenerObject, IoError>;
|
Result<~RtioUnixListenerObject, IoError>;
|
||||||
fn unix_connect<P: PathLike>(&mut self, path: &P) ->
|
fn unix_connect(&mut self, path: &CString) -> Result<~RtioPipe, IoError>;
|
||||||
Result<~RtioPipe, IoError>;
|
|
||||||
fn tty_open(&mut self, fd: c_int, readable: bool, close_on_drop: bool)
|
fn tty_open(&mut self, fd: c_int, readable: bool, close_on_drop: bool)
|
||||||
-> Result<~RtioTTY, IoError>;
|
-> Result<~RtioTTY, IoError>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -905,6 +905,7 @@ mod test {
|
|||||||
use cell::Cell;
|
use cell::Cell;
|
||||||
use rt::thread::Thread;
|
use rt::thread::Thread;
|
||||||
use rt::task::{Task, Sched};
|
use rt::task::{Task, Sched};
|
||||||
|
use rt::rtio::EventLoop;
|
||||||
use rt::util;
|
use rt::util;
|
||||||
use option::{Some};
|
use option::{Some};
|
||||||
|
|
||||||
@@ -1020,7 +1021,7 @@ mod test {
|
|||||||
|
|
||||||
// Our normal scheduler
|
// Our normal scheduler
|
||||||
let mut normal_sched = ~Scheduler::new(
|
let mut normal_sched = ~Scheduler::new(
|
||||||
~UvEventLoop::new(),
|
~UvEventLoop::new() as ~EventLoop,
|
||||||
normal_queue,
|
normal_queue,
|
||||||
queues.clone(),
|
queues.clone(),
|
||||||
sleepers.clone());
|
sleepers.clone());
|
||||||
@@ -1031,7 +1032,7 @@ mod test {
|
|||||||
|
|
||||||
// Our special scheduler
|
// Our special scheduler
|
||||||
let mut special_sched = ~Scheduler::new_special(
|
let mut special_sched = ~Scheduler::new_special(
|
||||||
~UvEventLoop::new(),
|
~UvEventLoop::new() as ~EventLoop,
|
||||||
special_queue.clone(),
|
special_queue.clone(),
|
||||||
queues.clone(),
|
queues.clone(),
|
||||||
sleepers.clone(),
|
sleepers.clone(),
|
||||||
@@ -1202,7 +1203,7 @@ mod test {
|
|||||||
let queues = ~[queue.clone()];
|
let queues = ~[queue.clone()];
|
||||||
|
|
||||||
let mut sched = ~Scheduler::new(
|
let mut sched = ~Scheduler::new(
|
||||||
~UvEventLoop::new(),
|
~UvEventLoop::new() as ~EventLoop,
|
||||||
queue,
|
queue,
|
||||||
queues.clone(),
|
queues.clone(),
|
||||||
sleepers.clone());
|
sleepers.clone());
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use rand::Rng;
|
|||||||
use os;
|
use os;
|
||||||
use libc;
|
use libc;
|
||||||
use option::{Some, None};
|
use option::{Some, None};
|
||||||
use path::{Path, GenericPath};
|
use path::Path;
|
||||||
use cell::Cell;
|
use cell::Cell;
|
||||||
use clone::Clone;
|
use clone::Clone;
|
||||||
use container::Container;
|
use container::Container;
|
||||||
@@ -335,7 +335,7 @@ pub fn next_test_port() -> u16 {
|
|||||||
/// Get a temporary path which could be the location of a unix socket
|
/// Get a temporary path which could be the location of a unix socket
|
||||||
#[fixed_stack_segment] #[inline(never)]
|
#[fixed_stack_segment] #[inline(never)]
|
||||||
pub fn next_test_unix() -> Path {
|
pub fn next_test_unix() -> Path {
|
||||||
os::tmpdir().push(rand::task_rng().gen_ascii_str(20))
|
os::tmpdir().join(rand::task_rng().gen_ascii_str(20))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a unique IPv4 localhost:port pair starting at 9600
|
/// Get a unique IPv4 localhost:port pair starting at 9600
|
||||||
|
|||||||
@@ -272,7 +272,6 @@ impl FsRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn each_path(&mut self, f: &fn(&CString)) {
|
pub fn each_path(&mut self, f: &fn(&CString)) {
|
||||||
use str;
|
|
||||||
let ptr = self.get_ptr();
|
let ptr = self.get_ptr();
|
||||||
match self.get_result() {
|
match self.get_result() {
|
||||||
n if (n <= 0) => {}
|
n if (n <= 0) => {}
|
||||||
@@ -350,7 +349,6 @@ mod test {
|
|||||||
use vec;
|
use vec;
|
||||||
use str;
|
use str;
|
||||||
use unstable::run_in_bare_thread;
|
use unstable::run_in_bare_thread;
|
||||||
use path::Path;
|
|
||||||
use rt::uv::{Loop, Buf, slice_to_uv_buf};
|
use rt::uv::{Loop, Buf, slice_to_uv_buf};
|
||||||
use libc::{O_CREAT, O_RDWR, O_RDONLY, S_IWUSR, S_IRUSR};
|
use libc::{O_CREAT, O_RDWR, O_RDONLY, S_IWUSR, S_IRUSR};
|
||||||
|
|
||||||
@@ -373,10 +371,9 @@ mod test {
|
|||||||
let read_mem = vec::from_elem(read_buf_len, 0u8);
|
let read_mem = vec::from_elem(read_buf_len, 0u8);
|
||||||
let read_buf = slice_to_uv_buf(read_mem);
|
let read_buf = slice_to_uv_buf(read_mem);
|
||||||
let read_buf_ptr: *Buf = &read_buf;
|
let read_buf_ptr: *Buf = &read_buf;
|
||||||
let p = Path::new(path_str);
|
|
||||||
let open_req = FsRequest::new();
|
let open_req = FsRequest::new();
|
||||||
do open_req.open(&loop_, &p, create_flags as int, mode as int)
|
do open_req.open(&loop_, &path_str.to_c_str(), create_flags as int,
|
||||||
|req, uverr| {
|
mode as int) |req, uverr| {
|
||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let fd = req.get_result();
|
let fd = req.get_result();
|
||||||
let buf = unsafe { *write_buf_ptr };
|
let buf = unsafe { *write_buf_ptr };
|
||||||
@@ -387,8 +384,8 @@ mod test {
|
|||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let loop_ = req.get_loop();
|
let loop_ = req.get_loop();
|
||||||
let open_req = FsRequest::new();
|
let open_req = FsRequest::new();
|
||||||
do open_req.open(&loop_, &Path::new(path_str), read_flags as int,0)
|
do open_req.open(&loop_, &path_str.to_c_str(),
|
||||||
|req, uverr| {
|
read_flags as int,0) |req, uverr| {
|
||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let loop_ = req.get_loop();
|
let loop_ = req.get_loop();
|
||||||
let fd = req.get_result();
|
let fd = req.get_result();
|
||||||
@@ -413,7 +410,8 @@ mod test {
|
|||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let loop_ = &req.get_loop();
|
let loop_ = &req.get_loop();
|
||||||
let unlink_req = FsRequest::new();
|
let unlink_req = FsRequest::new();
|
||||||
do unlink_req.unlink(loop_, &Path::new(path_str))
|
do unlink_req.unlink(loop_,
|
||||||
|
&path_str.to_c_str())
|
||||||
|_,uverr| {
|
|_,uverr| {
|
||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
};
|
};
|
||||||
@@ -447,7 +445,7 @@ mod test {
|
|||||||
let write_buf = slice_to_uv_buf(write_val);
|
let write_buf = slice_to_uv_buf(write_val);
|
||||||
// open/create
|
// open/create
|
||||||
let open_req = FsRequest::new();
|
let open_req = FsRequest::new();
|
||||||
let result = open_req.open_sync(&loop_, &Path::new(path_str),
|
let result = open_req.open_sync(&loop_, &path_str.to_c_str(),
|
||||||
create_flags as int, mode as int);
|
create_flags as int, mode as int);
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let fd = result.unwrap();
|
let fd = result.unwrap();
|
||||||
@@ -461,7 +459,7 @@ mod test {
|
|||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
// re-open
|
// re-open
|
||||||
let open_req = FsRequest::new();
|
let open_req = FsRequest::new();
|
||||||
let result = open_req.open_sync(&loop_, &Path::new(path_str),
|
let result = open_req.open_sync(&loop_, &path_str.to_c_str(),
|
||||||
read_flags as int,0);
|
read_flags as int,0);
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let len = 1028;
|
let len = 1028;
|
||||||
@@ -485,7 +483,7 @@ mod test {
|
|||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
// unlink
|
// unlink
|
||||||
let unlink_req = FsRequest::new();
|
let unlink_req = FsRequest::new();
|
||||||
let result = unlink_req.unlink_sync(&loop_, &Path::new(path_str));
|
let result = unlink_req.unlink_sync(&loop_, &path_str.to_c_str());
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
} else { fail!("nread was 0.. wudn't expectin' that."); }
|
} else { fail!("nread was 0.. wudn't expectin' that."); }
|
||||||
loop_.close();
|
loop_.close();
|
||||||
@@ -521,8 +519,8 @@ mod test {
|
|||||||
let write_buf = slice_to_uv_buf(write_val);
|
let write_buf = slice_to_uv_buf(write_val);
|
||||||
let write_buf_ptr: *Buf = &write_buf;
|
let write_buf_ptr: *Buf = &write_buf;
|
||||||
let open_req = FsRequest::new();
|
let open_req = FsRequest::new();
|
||||||
do open_req.open(&loop_, &path, create_flags as int, mode as int)
|
do open_req.open(&loop_, &path.to_c_str(), create_flags as int,
|
||||||
|req, uverr| {
|
mode as int) |req, uverr| {
|
||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let fd = req.get_result();
|
let fd = req.get_result();
|
||||||
let buf = unsafe { *write_buf_ptr };
|
let buf = unsafe { *write_buf_ptr };
|
||||||
@@ -531,7 +529,7 @@ mod test {
|
|||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let loop_ = req.get_loop();
|
let loop_ = req.get_loop();
|
||||||
let stat_req = FsRequest::new();
|
let stat_req = FsRequest::new();
|
||||||
do stat_req.stat(&loop_, &path) |req, uverr| {
|
do stat_req.stat(&loop_, &path.to_c_str()) |req, uverr| {
|
||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let loop_ = req.get_loop();
|
let loop_ = req.get_loop();
|
||||||
let stat = req.get_stat();
|
let stat = req.get_stat();
|
||||||
@@ -542,11 +540,13 @@ mod test {
|
|||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let loop_ = req.get_loop();
|
let loop_ = req.get_loop();
|
||||||
let unlink_req = FsRequest::new();
|
let unlink_req = FsRequest::new();
|
||||||
do unlink_req.unlink(&loop_, &path) |req,uverr| {
|
do unlink_req.unlink(&loop_,
|
||||||
|
&path.to_c_str()) |req,uverr| {
|
||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let loop_ = req.get_loop();
|
let loop_ = req.get_loop();
|
||||||
let stat_req = FsRequest::new();
|
let stat_req = FsRequest::new();
|
||||||
do stat_req.stat(&loop_, &path) |_, uverr| {
|
do stat_req.stat(&loop_,
|
||||||
|
&path.to_c_str()) |_, uverr| {
|
||||||
// should cause an error because the
|
// should cause an error because the
|
||||||
// file doesn't exist anymore
|
// file doesn't exist anymore
|
||||||
assert!(uverr.is_some());
|
assert!(uverr.is_some());
|
||||||
@@ -569,22 +569,23 @@ mod test {
|
|||||||
let mode = S_IWUSR |
|
let mode = S_IWUSR |
|
||||||
S_IRUSR;
|
S_IRUSR;
|
||||||
let mkdir_req = FsRequest::new();
|
let mkdir_req = FsRequest::new();
|
||||||
do mkdir_req.mkdir(&loop_, &path, mode as int) |req,uverr| {
|
do mkdir_req.mkdir(&loop_, &path.to_c_str(),
|
||||||
|
mode as int) |req,uverr| {
|
||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let loop_ = req.get_loop();
|
let loop_ = req.get_loop();
|
||||||
let stat_req = FsRequest::new();
|
let stat_req = FsRequest::new();
|
||||||
do stat_req.stat(&loop_, &path) |req, uverr| {
|
do stat_req.stat(&loop_, &path.to_c_str()) |req, uverr| {
|
||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let loop_ = req.get_loop();
|
let loop_ = req.get_loop();
|
||||||
let stat = req.get_stat();
|
let stat = req.get_stat();
|
||||||
naive_print(&loop_, format!("{:?}", stat));
|
naive_print(&loop_, format!("{:?}", stat));
|
||||||
assert!(stat.is_dir());
|
assert!(stat.is_dir());
|
||||||
let rmdir_req = FsRequest::new();
|
let rmdir_req = FsRequest::new();
|
||||||
do rmdir_req.rmdir(&loop_, &path) |req,uverr| {
|
do rmdir_req.rmdir(&loop_, &path.to_c_str()) |req,uverr| {
|
||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let loop_ = req.get_loop();
|
let loop_ = req.get_loop();
|
||||||
let stat_req = FsRequest::new();
|
let stat_req = FsRequest::new();
|
||||||
do stat_req.stat(&loop_, &path) |_req, uverr| {
|
do stat_req.stat(&loop_, &path.to_c_str()) |_req, uverr| {
|
||||||
assert!(uverr.is_some());
|
assert!(uverr.is_some());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -602,16 +603,17 @@ mod test {
|
|||||||
let mode = S_IWUSR |
|
let mode = S_IWUSR |
|
||||||
S_IRUSR;
|
S_IRUSR;
|
||||||
let mkdir_req = FsRequest::new();
|
let mkdir_req = FsRequest::new();
|
||||||
do mkdir_req.mkdir(&loop_, &path, mode as int) |req,uverr| {
|
do mkdir_req.mkdir(&loop_, &path.to_c_str(), mode as int) |req,uverr| {
|
||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let loop_ = req.get_loop();
|
let loop_ = req.get_loop();
|
||||||
let mkdir_req = FsRequest::new();
|
let mkdir_req = FsRequest::new();
|
||||||
do mkdir_req.mkdir(&loop_, &path, mode as int) |req,uverr| {
|
do mkdir_req.mkdir(&loop_, &path.to_c_str(),
|
||||||
|
mode as int) |req,uverr| {
|
||||||
assert!(uverr.is_some());
|
assert!(uverr.is_some());
|
||||||
let loop_ = req.get_loop();
|
let loop_ = req.get_loop();
|
||||||
let _stat = req.get_stat();
|
let _stat = req.get_stat();
|
||||||
let rmdir_req = FsRequest::new();
|
let rmdir_req = FsRequest::new();
|
||||||
do rmdir_req.rmdir(&loop_, &path) |req,uverr| {
|
do rmdir_req.rmdir(&loop_, &path.to_c_str()) |req,uverr| {
|
||||||
assert!(uverr.is_none());
|
assert!(uverr.is_none());
|
||||||
let _loop = req.get_loop();
|
let _loop = req.get_loop();
|
||||||
}
|
}
|
||||||
@@ -627,7 +629,7 @@ mod test {
|
|||||||
let mut loop_ = Loop::new();
|
let mut loop_ = Loop::new();
|
||||||
let path = "./tmp/never_existed_dir";
|
let path = "./tmp/never_existed_dir";
|
||||||
let rmdir_req = FsRequest::new();
|
let rmdir_req = FsRequest::new();
|
||||||
do rmdir_req.rmdir(&loop_, &path) |_req, uverr| {
|
do rmdir_req.rmdir(&loop_, &path.to_c_str()) |_req, uverr| {
|
||||||
assert!(uverr.is_some());
|
assert!(uverr.is_some());
|
||||||
}
|
}
|
||||||
loop_.run();
|
loop_.run();
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ use ops::Drop;
|
|||||||
use option::*;
|
use option::*;
|
||||||
use ptr;
|
use ptr;
|
||||||
use str;
|
use str;
|
||||||
use str::Str;
|
|
||||||
use result::*;
|
use result::*;
|
||||||
use rt::io::IoError;
|
use rt::io::IoError;
|
||||||
use rt::io::net::ip::{SocketAddr, IpAddr};
|
use rt::io::net::ip::{SocketAddr, IpAddr};
|
||||||
@@ -234,8 +233,8 @@ impl EventLoop for UvEventLoop {
|
|||||||
~UvRemoteCallback::new(self.uvio.uv_loop(), f) as ~RemoteCallback
|
~UvRemoteCallback::new(self.uvio.uv_loop(), f) as ~RemoteCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory> {
|
fn io<'a>(&'a mut self, f: &fn(&'a mut IoFactory)) {
|
||||||
Some(&mut self.uvio as &mut IoFactory)
|
f(&mut self.uvio as &mut IoFactory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +244,7 @@ pub struct UvPausibleIdleCallback {
|
|||||||
priv closed: bool
|
priv closed: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RtioPausibleIdleCallback for UvPausibleIdleCallback {
|
impl PausibleIdleCallback for UvPausibleIdleCallback {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn start(&mut self, f: ~fn()) {
|
fn start(&mut self, f: ~fn()) {
|
||||||
do self.watcher.start |_idle_watcher, _status| {
|
do self.watcher.start |_idle_watcher, _status| {
|
||||||
@@ -626,7 +625,9 @@ impl IoFactory for UvIoFactory {
|
|||||||
do scheduler.deschedule_running_task_and_then |_, task| {
|
do scheduler.deschedule_running_task_and_then |_, task| {
|
||||||
let task_cell = Cell::new(task);
|
let task_cell = Cell::new(task);
|
||||||
let path = path_cell.take();
|
let path = path_cell.take();
|
||||||
let path_instance = Cell::new(Path::new(path.as_bytes()));
|
// Don't pick up the null byte
|
||||||
|
let slice = path.as_bytes().slice(0, path.len());
|
||||||
|
let path_instance = Cell::new(Path::new(slice));
|
||||||
do stat_req.stat(self.uv_loop(), path) |req,err| {
|
do stat_req.stat(self.uv_loop(), path) |req,err| {
|
||||||
let res = match err {
|
let res = match err {
|
||||||
None => {
|
None => {
|
||||||
@@ -720,14 +721,17 @@ impl IoFactory for UvIoFactory {
|
|||||||
do scheduler.deschedule_running_task_and_then |_, task| {
|
do scheduler.deschedule_running_task_and_then |_, task| {
|
||||||
let task_cell = Cell::new(task);
|
let task_cell = Cell::new(task);
|
||||||
let path = path_cell.take();
|
let path = path_cell.take();
|
||||||
let path_parent = Cell::new(Path::new(path.as_bytes()));
|
// Don't pick up the null byte
|
||||||
|
let slice = path.as_bytes().slice(0, path.len());
|
||||||
|
let path_parent = Cell::new(Path::new(slice));
|
||||||
do stat_req.readdir(self.uv_loop(), path, flags) |req,err| {
|
do stat_req.readdir(self.uv_loop(), path, flags) |req,err| {
|
||||||
let parent = path_parent.take();
|
let parent = path_parent.take();
|
||||||
let res = match err {
|
let res = match err {
|
||||||
None => {
|
None => {
|
||||||
let mut paths = ~[];
|
let mut paths = ~[];
|
||||||
do req.each_path |rel_path| {
|
do req.each_path |rel_path| {
|
||||||
paths.push(parent.join(rel_path.as_bytes()));
|
let p = rel_path.as_bytes();
|
||||||
|
paths.push(parent.join(p.slice_to(rel_path.len())));
|
||||||
}
|
}
|
||||||
Ok(paths)
|
Ok(paths)
|
||||||
},
|
},
|
||||||
@@ -799,10 +803,10 @@ impl IoFactory for UvIoFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unix_bind<P: PathLike>(&mut self, path: &P) ->
|
fn unix_bind(&mut self, path: &CString) ->
|
||||||
Result<~RtioUnixListenerObject, IoError> {
|
Result<~RtioUnixListenerObject, IoError> {
|
||||||
let mut pipe = Pipe::new(self.uv_loop(), false);
|
let mut pipe = Pipe::new(self.uv_loop(), false);
|
||||||
match pipe.bind(&path.path_as_str(|s| s.to_c_str())) {
|
match pipe.bind(path) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
let handle = get_handle_to_current_scheduler!();
|
let handle = get_handle_to_current_scheduler!();
|
||||||
let pipe = UvUnboundPipe::new(pipe, handle);
|
let pipe = UvUnboundPipe::new(pipe, handle);
|
||||||
@@ -823,9 +827,7 @@ impl IoFactory for UvIoFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unix_connect<P: PathLike>(&mut self, path: &P) ->
|
fn unix_connect(&mut self, path: &CString) -> Result<~RtioPipe, IoError> {
|
||||||
Result<~RtioPipe, IoError>
|
|
||||||
{
|
|
||||||
let scheduler: ~Scheduler = Local::take();
|
let scheduler: ~Scheduler = Local::take();
|
||||||
let mut pipe = Pipe::new(self.uv_loop(), false);
|
let mut pipe = Pipe::new(self.uv_loop(), false);
|
||||||
let result_cell = Cell::new_empty();
|
let result_cell = Cell::new_empty();
|
||||||
@@ -833,8 +835,7 @@ impl IoFactory for UvIoFactory {
|
|||||||
|
|
||||||
do scheduler.deschedule_running_task_and_then |_, task| {
|
do scheduler.deschedule_running_task_and_then |_, task| {
|
||||||
let task_cell = Cell::new(task);
|
let task_cell = Cell::new(task);
|
||||||
let cstr = do path.path_as_str |s| { s.to_c_str() };
|
do pipe.connect(path) |stream, err| {
|
||||||
do pipe.connect(&cstr) |stream, err| {
|
|
||||||
let res = match err {
|
let res = match err {
|
||||||
None => {
|
None => {
|
||||||
let handle = stream.native_handle();
|
let handle = stream.native_handle();
|
||||||
@@ -1841,13 +1842,22 @@ impl RtioTTY for UvTTY {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this function is full of lies
|
||||||
|
unsafe fn local_io() -> &'static mut IoFactory {
|
||||||
|
do Local::borrow |sched: &mut Scheduler| {
|
||||||
|
let mut io = None;
|
||||||
|
sched.event_loop.io(|i| io = Some(i));
|
||||||
|
cast::transmute(io.unwrap())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_simple_io_no_connect() {
|
fn test_simple_io_no_connect() {
|
||||||
do run_in_mt_newsched_task {
|
do run_in_mt_newsched_task {
|
||||||
unsafe {
|
unsafe {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let addr = next_test_ip4();
|
let addr = next_test_ip4();
|
||||||
let maybe_chan = (*io).tcp_connect(addr);
|
let maybe_chan = io.tcp_connect(addr);
|
||||||
assert!(maybe_chan.is_err());
|
assert!(maybe_chan.is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1857,9 +1867,9 @@ fn test_simple_io_no_connect() {
|
|||||||
fn test_simple_udp_io_bind_only() {
|
fn test_simple_udp_io_bind_only() {
|
||||||
do run_in_mt_newsched_task {
|
do run_in_mt_newsched_task {
|
||||||
unsafe {
|
unsafe {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let addr = next_test_ip4();
|
let addr = next_test_ip4();
|
||||||
let maybe_socket = (*io).udp_bind(addr);
|
let maybe_socket = io.udp_bind(addr);
|
||||||
assert!(maybe_socket.is_ok());
|
assert!(maybe_socket.is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1878,9 +1888,11 @@ fn test_simple_homed_udp_io_bind_then_move_task_then_home_and_close() {
|
|||||||
let work_queue2 = WorkQueue::new();
|
let work_queue2 = WorkQueue::new();
|
||||||
let queues = ~[work_queue1.clone(), work_queue2.clone()];
|
let queues = ~[work_queue1.clone(), work_queue2.clone()];
|
||||||
|
|
||||||
let mut sched1 = ~Scheduler::new(~UvEventLoop::new(), work_queue1, queues.clone(),
|
let loop1 = ~UvEventLoop::new() as ~EventLoop;
|
||||||
|
let mut sched1 = ~Scheduler::new(loop1, work_queue1, queues.clone(),
|
||||||
sleepers.clone());
|
sleepers.clone());
|
||||||
let mut sched2 = ~Scheduler::new(~UvEventLoop::new(), work_queue2, queues.clone(),
|
let loop2 = ~UvEventLoop::new() as ~EventLoop;
|
||||||
|
let mut sched2 = ~Scheduler::new(loop2, work_queue2, queues.clone(),
|
||||||
sleepers.clone());
|
sleepers.clone());
|
||||||
|
|
||||||
let handle1 = Cell::new(sched1.make_handle());
|
let handle1 = Cell::new(sched1.make_handle());
|
||||||
@@ -1894,11 +1906,9 @@ fn test_simple_homed_udp_io_bind_then_move_task_then_home_and_close() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let test_function: ~fn() = || {
|
let test_function: ~fn() = || {
|
||||||
let io: *mut IoFactoryObject = unsafe {
|
let io = unsafe { local_io() };
|
||||||
Local::unsafe_borrow()
|
|
||||||
};
|
|
||||||
let addr = next_test_ip4();
|
let addr = next_test_ip4();
|
||||||
let maybe_socket = unsafe { (*io).udp_bind(addr) };
|
let maybe_socket = io.udp_bind(addr);
|
||||||
// this socket is bound to this event loop
|
// this socket is bound to this event loop
|
||||||
assert!(maybe_socket.is_ok());
|
assert!(maybe_socket.is_ok());
|
||||||
|
|
||||||
@@ -1957,9 +1967,11 @@ fn test_simple_homed_udp_io_bind_then_move_handle_then_home_and_close() {
|
|||||||
let work_queue2 = WorkQueue::new();
|
let work_queue2 = WorkQueue::new();
|
||||||
let queues = ~[work_queue1.clone(), work_queue2.clone()];
|
let queues = ~[work_queue1.clone(), work_queue2.clone()];
|
||||||
|
|
||||||
let mut sched1 = ~Scheduler::new(~UvEventLoop::new(), work_queue1, queues.clone(),
|
let loop1 = ~UvEventLoop::new() as ~EventLoop;
|
||||||
|
let mut sched1 = ~Scheduler::new(loop1, work_queue1, queues.clone(),
|
||||||
sleepers.clone());
|
sleepers.clone());
|
||||||
let mut sched2 = ~Scheduler::new(~UvEventLoop::new(), work_queue2, queues.clone(),
|
let loop2 = ~UvEventLoop::new() as ~EventLoop;
|
||||||
|
let mut sched2 = ~Scheduler::new(loop2, work_queue2, queues.clone(),
|
||||||
sleepers.clone());
|
sleepers.clone());
|
||||||
|
|
||||||
let handle1 = Cell::new(sched1.make_handle());
|
let handle1 = Cell::new(sched1.make_handle());
|
||||||
@@ -1970,11 +1982,9 @@ fn test_simple_homed_udp_io_bind_then_move_handle_then_home_and_close() {
|
|||||||
let chan = Cell::new(chan);
|
let chan = Cell::new(chan);
|
||||||
|
|
||||||
let body1: ~fn() = || {
|
let body1: ~fn() = || {
|
||||||
let io: *mut IoFactoryObject = unsafe {
|
let io = unsafe { local_io() };
|
||||||
Local::unsafe_borrow()
|
|
||||||
};
|
|
||||||
let addr = next_test_ip4();
|
let addr = next_test_ip4();
|
||||||
let socket = unsafe { (*io).udp_bind(addr) };
|
let socket = io.udp_bind(addr);
|
||||||
assert!(socket.is_ok());
|
assert!(socket.is_ok());
|
||||||
chan.take().send(socket);
|
chan.take().send(socket);
|
||||||
};
|
};
|
||||||
@@ -2028,8 +2038,8 @@ fn test_simple_tcp_server_and_client() {
|
|||||||
// Start the server first so it's listening when we connect
|
// Start the server first so it's listening when we connect
|
||||||
do spawntask {
|
do spawntask {
|
||||||
unsafe {
|
unsafe {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let listener = (*io).tcp_bind(addr).unwrap();
|
let listener = io.tcp_bind(addr).unwrap();
|
||||||
let mut acceptor = listener.listen().unwrap();
|
let mut acceptor = listener.listen().unwrap();
|
||||||
chan.take().send(());
|
chan.take().send(());
|
||||||
let mut stream = acceptor.accept().unwrap();
|
let mut stream = acceptor.accept().unwrap();
|
||||||
@@ -2046,8 +2056,8 @@ fn test_simple_tcp_server_and_client() {
|
|||||||
do spawntask {
|
do spawntask {
|
||||||
unsafe {
|
unsafe {
|
||||||
port.take().recv();
|
port.take().recv();
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let mut stream = (*io).tcp_connect(addr).unwrap();
|
let mut stream = io.tcp_connect(addr).unwrap();
|
||||||
stream.write([0, 1, 2, 3, 4, 5, 6, 7]);
|
stream.write([0, 1, 2, 3, 4, 5, 6, 7]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2071,9 +2081,11 @@ fn test_simple_tcp_server_and_client_on_diff_threads() {
|
|||||||
let client_work_queue = WorkQueue::new();
|
let client_work_queue = WorkQueue::new();
|
||||||
let queues = ~[server_work_queue.clone(), client_work_queue.clone()];
|
let queues = ~[server_work_queue.clone(), client_work_queue.clone()];
|
||||||
|
|
||||||
let mut server_sched = ~Scheduler::new(~UvEventLoop::new(), server_work_queue,
|
let sloop = ~UvEventLoop::new() as ~EventLoop;
|
||||||
|
let mut server_sched = ~Scheduler::new(sloop, server_work_queue,
|
||||||
queues.clone(), sleepers.clone());
|
queues.clone(), sleepers.clone());
|
||||||
let mut client_sched = ~Scheduler::new(~UvEventLoop::new(), client_work_queue,
|
let cloop = ~UvEventLoop::new() as ~EventLoop;
|
||||||
|
let mut client_sched = ~Scheduler::new(cloop, client_work_queue,
|
||||||
queues.clone(), sleepers.clone());
|
queues.clone(), sleepers.clone());
|
||||||
|
|
||||||
let server_handle = Cell::new(server_sched.make_handle());
|
let server_handle = Cell::new(server_sched.make_handle());
|
||||||
@@ -2090,8 +2102,8 @@ fn test_simple_tcp_server_and_client_on_diff_threads() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let server_fn: ~fn() = || {
|
let server_fn: ~fn() = || {
|
||||||
let io: *mut IoFactoryObject = unsafe { Local::unsafe_borrow() };
|
let io = unsafe { local_io() };
|
||||||
let listener = unsafe { (*io).tcp_bind(server_addr).unwrap() };
|
let listener = io.tcp_bind(server_addr).unwrap();
|
||||||
let mut acceptor = listener.listen().unwrap();
|
let mut acceptor = listener.listen().unwrap();
|
||||||
let mut stream = acceptor.accept().unwrap();
|
let mut stream = acceptor.accept().unwrap();
|
||||||
let mut buf = [0, .. 2048];
|
let mut buf = [0, .. 2048];
|
||||||
@@ -2103,12 +2115,10 @@ fn test_simple_tcp_server_and_client_on_diff_threads() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let client_fn: ~fn() = || {
|
let client_fn: ~fn() = || {
|
||||||
let io: *mut IoFactoryObject = unsafe {
|
let io = unsafe { local_io() };
|
||||||
Local::unsafe_borrow()
|
let mut stream = io.tcp_connect(client_addr);
|
||||||
};
|
|
||||||
let mut stream = unsafe { (*io).tcp_connect(client_addr) };
|
|
||||||
while stream.is_err() {
|
while stream.is_err() {
|
||||||
stream = unsafe { (*io).tcp_connect(client_addr) };
|
stream = io.tcp_connect(client_addr);
|
||||||
}
|
}
|
||||||
stream.unwrap().write([0, 1, 2, 3, 4, 5, 6, 7]);
|
stream.unwrap().write([0, 1, 2, 3, 4, 5, 6, 7]);
|
||||||
};
|
};
|
||||||
@@ -2147,8 +2157,8 @@ fn test_simple_udp_server_and_client() {
|
|||||||
|
|
||||||
do spawntask {
|
do spawntask {
|
||||||
unsafe {
|
unsafe {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let mut server_socket = (*io).udp_bind(server_addr).unwrap();
|
let mut server_socket = io.udp_bind(server_addr).unwrap();
|
||||||
chan.take().send(());
|
chan.take().send(());
|
||||||
let mut buf = [0, .. 2048];
|
let mut buf = [0, .. 2048];
|
||||||
let (nread,src) = server_socket.recvfrom(buf).unwrap();
|
let (nread,src) = server_socket.recvfrom(buf).unwrap();
|
||||||
@@ -2163,8 +2173,8 @@ fn test_simple_udp_server_and_client() {
|
|||||||
|
|
||||||
do spawntask {
|
do spawntask {
|
||||||
unsafe {
|
unsafe {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let mut client_socket = (*io).udp_bind(client_addr).unwrap();
|
let mut client_socket = io.udp_bind(client_addr).unwrap();
|
||||||
port.take().recv();
|
port.take().recv();
|
||||||
client_socket.sendto([0, 1, 2, 3, 4, 5, 6, 7], server_addr);
|
client_socket.sendto([0, 1, 2, 3, 4, 5, 6, 7], server_addr);
|
||||||
}
|
}
|
||||||
@@ -2181,8 +2191,8 @@ fn test_read_and_block() {
|
|||||||
let chan = Cell::new(chan);
|
let chan = Cell::new(chan);
|
||||||
|
|
||||||
do spawntask {
|
do spawntask {
|
||||||
let io: *mut IoFactoryObject = unsafe { Local::unsafe_borrow() };
|
let io = unsafe { local_io() };
|
||||||
let listener = unsafe { (*io).tcp_bind(addr).unwrap() };
|
let listener = io.tcp_bind(addr).unwrap();
|
||||||
let mut acceptor = listener.listen().unwrap();
|
let mut acceptor = listener.listen().unwrap();
|
||||||
chan.take().send(());
|
chan.take().send(());
|
||||||
let mut stream = acceptor.accept().unwrap();
|
let mut stream = acceptor.accept().unwrap();
|
||||||
@@ -2220,8 +2230,8 @@ fn test_read_and_block() {
|
|||||||
do spawntask {
|
do spawntask {
|
||||||
unsafe {
|
unsafe {
|
||||||
port.take().recv();
|
port.take().recv();
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let mut stream = (*io).tcp_connect(addr).unwrap();
|
let mut stream = io.tcp_connect(addr).unwrap();
|
||||||
stream.write([0, 1, 2, 3, 4, 5, 6, 7]);
|
stream.write([0, 1, 2, 3, 4, 5, 6, 7]);
|
||||||
stream.write([0, 1, 2, 3, 4, 5, 6, 7]);
|
stream.write([0, 1, 2, 3, 4, 5, 6, 7]);
|
||||||
stream.write([0, 1, 2, 3, 4, 5, 6, 7]);
|
stream.write([0, 1, 2, 3, 4, 5, 6, 7]);
|
||||||
@@ -2243,8 +2253,8 @@ fn test_read_read_read() {
|
|||||||
|
|
||||||
do spawntask {
|
do spawntask {
|
||||||
unsafe {
|
unsafe {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let listener = (*io).tcp_bind(addr).unwrap();
|
let listener = io.tcp_bind(addr).unwrap();
|
||||||
let mut acceptor = listener.listen().unwrap();
|
let mut acceptor = listener.listen().unwrap();
|
||||||
chan.take().send(());
|
chan.take().send(());
|
||||||
let mut stream = acceptor.accept().unwrap();
|
let mut stream = acceptor.accept().unwrap();
|
||||||
@@ -2260,8 +2270,8 @@ fn test_read_read_read() {
|
|||||||
do spawntask {
|
do spawntask {
|
||||||
unsafe {
|
unsafe {
|
||||||
port.take().recv();
|
port.take().recv();
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let mut stream = (*io).tcp_connect(addr).unwrap();
|
let mut stream = io.tcp_connect(addr).unwrap();
|
||||||
let mut buf = [0, .. 2048];
|
let mut buf = [0, .. 2048];
|
||||||
let mut total_bytes_read = 0;
|
let mut total_bytes_read = 0;
|
||||||
while total_bytes_read < MAX {
|
while total_bytes_read < MAX {
|
||||||
@@ -2289,8 +2299,8 @@ fn test_udp_twice() {
|
|||||||
|
|
||||||
do spawntask {
|
do spawntask {
|
||||||
unsafe {
|
unsafe {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let mut client = (*io).udp_bind(client_addr).unwrap();
|
let mut client = io.udp_bind(client_addr).unwrap();
|
||||||
port.take().recv();
|
port.take().recv();
|
||||||
assert!(client.sendto([1], server_addr).is_ok());
|
assert!(client.sendto([1], server_addr).is_ok());
|
||||||
assert!(client.sendto([2], server_addr).is_ok());
|
assert!(client.sendto([2], server_addr).is_ok());
|
||||||
@@ -2299,8 +2309,8 @@ fn test_udp_twice() {
|
|||||||
|
|
||||||
do spawntask {
|
do spawntask {
|
||||||
unsafe {
|
unsafe {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let mut server = (*io).udp_bind(server_addr).unwrap();
|
let mut server = io.udp_bind(server_addr).unwrap();
|
||||||
chan.take().send(());
|
chan.take().send(());
|
||||||
let mut buf1 = [0];
|
let mut buf1 = [0];
|
||||||
let mut buf2 = [0];
|
let mut buf2 = [0];
|
||||||
@@ -2334,9 +2344,9 @@ fn test_udp_many_read() {
|
|||||||
|
|
||||||
do spawntask {
|
do spawntask {
|
||||||
unsafe {
|
unsafe {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let mut server_out = (*io).udp_bind(server_out_addr).unwrap();
|
let mut server_out = io.udp_bind(server_out_addr).unwrap();
|
||||||
let mut server_in = (*io).udp_bind(server_in_addr).unwrap();
|
let mut server_in = io.udp_bind(server_in_addr).unwrap();
|
||||||
let (port, chan) = first.take();
|
let (port, chan) = first.take();
|
||||||
chan.send(());
|
chan.send(());
|
||||||
port.recv();
|
port.recv();
|
||||||
@@ -2360,9 +2370,9 @@ fn test_udp_many_read() {
|
|||||||
|
|
||||||
do spawntask {
|
do spawntask {
|
||||||
unsafe {
|
unsafe {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let mut client_out = (*io).udp_bind(client_out_addr).unwrap();
|
let mut client_out = io.udp_bind(client_out_addr).unwrap();
|
||||||
let mut client_in = (*io).udp_bind(client_in_addr).unwrap();
|
let mut client_in = io.udp_bind(client_in_addr).unwrap();
|
||||||
let (port, chan) = second.take();
|
let (port, chan) = second.take();
|
||||||
port.recv();
|
port.recv();
|
||||||
chan.send(());
|
chan.send(());
|
||||||
@@ -2392,8 +2402,8 @@ fn test_udp_many_read() {
|
|||||||
fn test_timer_sleep_simple() {
|
fn test_timer_sleep_simple() {
|
||||||
do run_in_mt_newsched_task {
|
do run_in_mt_newsched_task {
|
||||||
unsafe {
|
unsafe {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let timer = (*io).timer_init();
|
let timer = io.timer_init();
|
||||||
do timer.map_move |mut t| { t.sleep(1) };
|
do timer.map_move |mut t| { t.sleep(1) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2403,29 +2413,28 @@ fn file_test_uvio_full_simple_impl() {
|
|||||||
use str::StrSlice; // why does this have to be explicitly imported to work?
|
use str::StrSlice; // why does this have to be explicitly imported to work?
|
||||||
// compiler was complaining about no trait for str that
|
// compiler was complaining about no trait for str that
|
||||||
// does .as_bytes() ..
|
// does .as_bytes() ..
|
||||||
use path::Path;
|
|
||||||
use rt::io::{Open, Create, ReadWrite, Read};
|
use rt::io::{Open, Create, ReadWrite, Read};
|
||||||
unsafe {
|
unsafe {
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
let write_val = "hello uvio!";
|
let write_val = "hello uvio!";
|
||||||
let path = "./tmp/file_test_uvio_full.txt";
|
let path = "./tmp/file_test_uvio_full.txt";
|
||||||
{
|
{
|
||||||
let create_fm = Create;
|
let create_fm = Create;
|
||||||
let create_fa = ReadWrite;
|
let create_fa = ReadWrite;
|
||||||
let mut fd = (*io).fs_open(&path.to_c_str(), create_fm, create_fa).unwrap();
|
let mut fd = io.fs_open(&path.to_c_str(), create_fm, create_fa).unwrap();
|
||||||
let write_buf = write_val.as_bytes();
|
let write_buf = write_val.as_bytes();
|
||||||
fd.write(write_buf);
|
fd.write(write_buf);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let ro_fm = Open;
|
let ro_fm = Open;
|
||||||
let ro_fa = Read;
|
let ro_fa = Read;
|
||||||
let mut fd = (*io).fs_open(&path.to_c_str(), ro_fm, ro_fa).unwrap();
|
let mut fd = io.fs_open(&path.to_c_str(), ro_fm, ro_fa).unwrap();
|
||||||
let mut read_vec = [0, .. 1028];
|
let mut read_vec = [0, .. 1028];
|
||||||
let nread = fd.read(read_vec).unwrap();
|
let nread = fd.read(read_vec).unwrap();
|
||||||
let read_val = str::from_utf8(read_vec.slice(0, nread as uint));
|
let read_val = str::from_utf8(read_vec.slice(0, nread as uint));
|
||||||
assert!(read_val == write_val.to_owned());
|
assert!(read_val == write_val.to_owned());
|
||||||
}
|
}
|
||||||
(*io).fs_unlink(&path.to_c_str());
|
io.fs_unlink(&path.to_c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2440,9 +2449,9 @@ fn uvio_naive_print(input: &str) {
|
|||||||
use str::StrSlice;
|
use str::StrSlice;
|
||||||
unsafe {
|
unsafe {
|
||||||
use libc::{STDOUT_FILENO};
|
use libc::{STDOUT_FILENO};
|
||||||
let io: *mut IoFactoryObject = Local::unsafe_borrow();
|
let io = local_io();
|
||||||
{
|
{
|
||||||
let mut fd = (*io).fs_from_raw_fd(STDOUT_FILENO, false);
|
let mut fd = io.fs_from_raw_fd(STDOUT_FILENO, false);
|
||||||
let write_buf = input.as_bytes();
|
let write_buf = input.as_bytes();
|
||||||
fd.write(write_buf);
|
fd.write(write_buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1018,7 +1018,6 @@ static TAG_CONT_U8: u8 = 128u8;
|
|||||||
|
|
||||||
/// Unsafe operations
|
/// Unsafe operations
|
||||||
pub mod raw {
|
pub mod raw {
|
||||||
use option::{Option, Some};
|
|
||||||
use cast;
|
use cast;
|
||||||
use libc;
|
use libc;
|
||||||
use ptr;
|
use ptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user