Skip to content

Commit 1c79b79

Browse files
committed
---
yaml --- r: 147449 b: refs/heads/try2 c: 4538369 h: refs/heads/master i: 147447: 6af804a v: v3
1 parent cf3e348 commit 1c79b79

File tree

12 files changed

+119
-177
lines changed

12 files changed

+119
-177
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a55c57284d8341ee5b22c5372e77ac0af9479dc5
8+
refs/heads/try2: 4538369566b8b51fc8371253aa90f9725547a193
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/io/fs.rs

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use super::{SeekStyle, Read, Write, Open, IoError, Truncate,
5454
use rt::rtio::{RtioFileStream, IoFactory, LocalIo};
5555
use io;
5656
use option::{Some, None, Option};
57-
use result::{Ok, Err, Result};
57+
use result::{Ok, Err};
5858
use path;
5959
use path::{Path, GenericPath};
6060
use vec::{OwnedVector, ImmutableVector};
@@ -75,17 +75,6 @@ pub struct File {
7575
priv last_nread: int,
7676
}
7777

78-
fn io_raise<T>(f: |io: &mut IoFactory| -> Result<T, IoError>) -> Option<T> {
79-
let mut io = LocalIo::borrow();
80-
match f(io.get()) {
81-
Ok(t) => Some(t),
82-
Err(ioerr) => {
83-
io_error::cond.raise(ioerr);
84-
None
85-
}
86-
}
87-
}
88-
8978
impl File {
9079
/// Open a file at `path` in the mode specified by the `mode` and `access`
9180
/// arguments
@@ -131,18 +120,15 @@ impl File {
131120
pub fn open_mode(path: &Path,
132121
mode: FileMode,
133122
access: FileAccess) -> Option<File> {
134-
let mut io = LocalIo::borrow();
135-
match io.get().fs_open(&path.to_c_str(), mode, access) {
136-
Ok(fd) => Some(File {
137-
path: path.clone(),
138-
fd: fd,
139-
last_nread: -1
140-
}),
141-
Err(ioerr) => {
142-
io_error::cond.raise(ioerr);
143-
None
144-
}
145-
}
123+
LocalIo::maybe_raise(|io| {
124+
io.fs_open(&path.to_c_str(), mode, access).map(|fd| {
125+
File {
126+
path: path.clone(),
127+
fd: fd,
128+
last_nread: -1
129+
}
130+
})
131+
})
146132
}
147133

148134
/// Attempts to open a file in read-only mode. This function is equivalent to
@@ -242,7 +228,7 @@ impl File {
242228
/// directory, the user lacks permissions to remove the file, or if some
243229
/// other filesystem-level error occurs.
244230
pub fn unlink(path: &Path) {
245-
io_raise(|io| io.fs_unlink(&path.to_c_str()));
231+
LocalIo::maybe_raise(|io| io.fs_unlink(&path.to_c_str()));
246232
}
247233

248234
/// Given a path, query the file system to get information about a file,
@@ -270,7 +256,9 @@ pub fn unlink(path: &Path) {
270256
/// requisite permissions to perform a `stat` call on the given path or if
271257
/// there is no entry in the filesystem at the provided path.
272258
pub fn stat(path: &Path) -> FileStat {
273-
io_raise(|io| io.fs_stat(&path.to_c_str())).unwrap_or_else(dummystat)
259+
LocalIo::maybe_raise(|io| {
260+
io.fs_stat(&path.to_c_str())
261+
}).unwrap_or_else(dummystat)
274262
}
275263

276264
fn dummystat() -> FileStat {
@@ -306,7 +294,9 @@ fn dummystat() -> FileStat {
306294
///
307295
/// See `stat`
308296
pub fn lstat(path: &Path) -> FileStat {
309-
io_raise(|io| io.fs_lstat(&path.to_c_str())).unwrap_or_else(dummystat)
297+
LocalIo::maybe_raise(|io| {
298+
io.fs_lstat(&path.to_c_str())
299+
}).unwrap_or_else(dummystat)
310300
}
311301

312302
/// Rename a file or directory to a new name.
@@ -324,7 +314,7 @@ pub fn lstat(path: &Path) -> FileStat {
324314
/// the process lacks permissions to view the contents, or if some other
325315
/// intermittent I/O error occurs.
326316
pub fn rename(from: &Path, to: &Path) {
327-
io_raise(|io| io.fs_rename(&from.to_c_str(), &to.to_c_str()));
317+
LocalIo::maybe_raise(|io| io.fs_rename(&from.to_c_str(), &to.to_c_str()));
328318
}
329319

330320
/// Copies the contents of one file to another. This function will also
@@ -395,7 +385,7 @@ pub fn copy(from: &Path, to: &Path) {
395385
/// condition. Some possible error situations are not having the permission to
396386
/// change the attributes of a file or the file not existing.
397387
pub fn chmod(path: &Path, mode: io::FilePermission) {
398-
io_raise(|io| io.fs_chmod(&path.to_c_str(), mode));
388+
LocalIo::maybe_raise(|io| io.fs_chmod(&path.to_c_str(), mode));
399389
}
400390

401391
/// Change the user and group owners of a file at the specified path.
@@ -404,7 +394,7 @@ pub fn chmod(path: &Path, mode: io::FilePermission) {
404394
///
405395
/// This function will raise on the `io_error` condition on failure.
406396
pub fn chown(path: &Path, uid: int, gid: int) {
407-
io_raise(|io| io.fs_chown(&path.to_c_str(), uid, gid));
397+
LocalIo::maybe_raise(|io| io.fs_chown(&path.to_c_str(), uid, gid));
408398
}
409399

410400
/// Creates a new hard link on the filesystem. The `dst` path will be a
@@ -415,7 +405,7 @@ pub fn chown(path: &Path, uid: int, gid: int) {
415405
///
416406
/// This function will raise on the `io_error` condition on failure.
417407
pub fn link(src: &Path, dst: &Path) {
418-
io_raise(|io| io.fs_link(&src.to_c_str(), &dst.to_c_str()));
408+
LocalIo::maybe_raise(|io| io.fs_link(&src.to_c_str(), &dst.to_c_str()));
419409
}
420410

421411
/// Creates a new symbolic link on the filesystem. The `dst` path will be a
@@ -425,7 +415,7 @@ pub fn link(src: &Path, dst: &Path) {
425415
///
426416
/// This function will raise on the `io_error` condition on failure.
427417
pub fn symlink(src: &Path, dst: &Path) {
428-
io_raise(|io| io.fs_symlink(&src.to_c_str(), &dst.to_c_str()));
418+
LocalIo::maybe_raise(|io| io.fs_symlink(&src.to_c_str(), &dst.to_c_str()));
429419
}
430420

431421
/// Reads a symlink, returning the file that the symlink points to.
@@ -436,7 +426,7 @@ pub fn symlink(src: &Path, dst: &Path) {
436426
/// conditions include reading a file that does not exist or reading a file
437427
/// which is not a symlink.
438428
pub fn readlink(path: &Path) -> Option<Path> {
439-
io_raise(|io| io.fs_readlink(&path.to_c_str()))
429+
LocalIo::maybe_raise(|io| io.fs_readlink(&path.to_c_str()))
440430
}
441431

442432
/// Create a new, empty directory at the provided path
@@ -456,7 +446,7 @@ pub fn readlink(path: &Path) -> Option<Path> {
456446
/// to make a new directory at the provided path, or if the directory already
457447
/// exists.
458448
pub fn mkdir(path: &Path, mode: FilePermission) {
459-
io_raise(|io| io.fs_mkdir(&path.to_c_str(), mode));
449+
LocalIo::maybe_raise(|io| io.fs_mkdir(&path.to_c_str(), mode));
460450
}
461451

462452
/// Remove an existing, empty directory
@@ -475,7 +465,7 @@ pub fn mkdir(path: &Path, mode: FilePermission) {
475465
/// to remove the directory at the provided path, or if the directory isn't
476466
/// empty.
477467
pub fn rmdir(path: &Path) {
478-
io_raise(|io| io.fs_rmdir(&path.to_c_str()));
468+
LocalIo::maybe_raise(|io| io.fs_rmdir(&path.to_c_str()));
479469
}
480470

481471
/// Retrieve a vector containing all entries within a provided directory
@@ -502,7 +492,9 @@ pub fn rmdir(path: &Path) {
502492
/// the process lacks permissions to view the contents or if the `path` points
503493
/// at a non-directory file
504494
pub fn readdir(path: &Path) -> ~[Path] {
505-
io_raise(|io| io.fs_readdir(&path.to_c_str(), 0)).unwrap_or_else(|| ~[])
495+
LocalIo::maybe_raise(|io| {
496+
io.fs_readdir(&path.to_c_str(), 0)
497+
}).unwrap_or_else(|| ~[])
506498
}
507499

508500
/// Returns an iterator which will recursively walk the directory structure
@@ -583,7 +575,7 @@ pub fn rmdir_recursive(path: &Path) {
583575
/// happens.
584576
// FIXME(#10301) these arguments should not be u64
585577
pub fn change_file_times(path: &Path, atime: u64, mtime: u64) {
586-
io_raise(|io| io.fs_utime(&path.to_c_str(), atime, mtime));
578+
LocalIo::maybe_raise(|io| io.fs_utime(&path.to_c_str(), atime, mtime));
587579
}
588580

589581
impl Reader for File {

branches/try2/src/libstd/io/net/addrinfo.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ getaddrinfo()
1818
*/
1919

2020
use option::{Option, Some, None};
21-
use result::{Ok, Err};
22-
use io::{io_error};
2321
use io::net::ip::{SocketAddr, IpAddr};
2422
use rt::rtio::{IoFactory, LocalIo};
2523
use vec::ImmutableVector;
@@ -97,14 +95,7 @@ pub fn get_host_addresses(host: &str) -> Option<~[IpAddr]> {
9795
/// consumption just yet.
9896
fn lookup(hostname: Option<&str>, servname: Option<&str>, hint: Option<Hint>)
9997
-> Option<~[Info]> {
100-
let mut io = LocalIo::borrow();
101-
match io.get().get_host_addresses(hostname, servname, hint) {
102-
Ok(i) => Some(i),
103-
Err(ioerr) => {
104-
io_error::cond.raise(ioerr);
105-
None
106-
}
107-
}
98+
LocalIo::maybe_raise(|io| io.get_host_addresses(hostname, servname, hint))
10899
}
109100

110101
#[cfg(test)]

branches/try2/src/libstd/io/net/tcp.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,9 @@ impl TcpStream {
2626
}
2727

2828
pub fn connect(addr: SocketAddr) -> Option<TcpStream> {
29-
let result = {
30-
let mut io = LocalIo::borrow();
31-
io.get().tcp_connect(addr)
32-
};
33-
match result {
34-
Ok(s) => Some(TcpStream::new(s)),
35-
Err(ioerr) => {
36-
io_error::cond.raise(ioerr);
37-
None
38-
}
39-
}
29+
LocalIo::maybe_raise(|io| {
30+
io.tcp_connect(addr).map(TcpStream::new)
31+
})
4032
}
4133

4234
pub fn peer_name(&mut self) -> Option<SocketAddr> {
@@ -94,14 +86,9 @@ pub struct TcpListener {
9486

9587
impl TcpListener {
9688
pub fn bind(addr: SocketAddr) -> Option<TcpListener> {
97-
let mut io = LocalIo::borrow();
98-
match io.get().tcp_bind(addr) {
99-
Ok(l) => Some(TcpListener { obj: l }),
100-
Err(ioerr) => {
101-
io_error::cond.raise(ioerr);
102-
None
103-
}
104-
}
89+
LocalIo::maybe_raise(|io| {
90+
io.tcp_bind(addr).map(|l| TcpListener { obj: l })
91+
})
10592
}
10693

10794
pub fn socket_name(&mut self) -> Option<SocketAddr> {

branches/try2/src/libstd/io/net/udp.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,9 @@ pub struct UdpSocket {
2121

2222
impl UdpSocket {
2323
pub fn bind(addr: SocketAddr) -> Option<UdpSocket> {
24-
let mut io = LocalIo::borrow();
25-
match io.get().udp_bind(addr) {
26-
Ok(s) => Some(UdpSocket { obj: s }),
27-
Err(ioerr) => {
28-
io_error::cond.raise(ioerr);
29-
None
30-
}
31-
}
24+
LocalIo::maybe_raise(|io| {
25+
io.udp_bind(addr).map(|s| UdpSocket { obj: s })
26+
})
3227
}
3328

3429
pub fn recvfrom(&mut self, buf: &mut [u8]) -> Option<(uint, SocketAddr)> {

branches/try2/src/libstd/io/net/unix.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,9 @@ impl UnixStream {
5959
/// stream.write([1, 2, 3]);
6060
///
6161
pub fn connect<P: ToCStr>(path: &P) -> Option<UnixStream> {
62-
let mut io = LocalIo::borrow();
63-
match io.get().unix_connect(&path.to_c_str()) {
64-
Ok(s) => Some(UnixStream::new(s)),
65-
Err(ioerr) => {
66-
io_error::cond.raise(ioerr);
67-
None
68-
}
69-
}
62+
LocalIo::maybe_raise(|io| {
63+
io.unix_connect(&path.to_c_str()).map(UnixStream::new)
64+
})
7065
}
7166
}
7267

@@ -107,14 +102,9 @@ impl UnixListener {
107102
/// }
108103
///
109104
pub fn bind<P: ToCStr>(path: &P) -> Option<UnixListener> {
110-
let mut io = LocalIo::borrow();
111-
match io.get().unix_bind(&path.to_c_str()) {
112-
Ok(s) => Some(UnixListener{ obj: s }),
113-
Err(ioerr) => {
114-
io_error::cond.raise(ioerr);
115-
None
116-
}
117-
}
105+
LocalIo::maybe_raise(|io| {
106+
io.unix_bind(&path.to_c_str()).map(|s| UnixListener { obj: s })
107+
})
118108
}
119109
}
120110

branches/try2/src/libstd/io/pipe.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
//! enough so that pipes can be created to child processes.
1515
1616
use prelude::*;
17-
use super::{Reader, Writer};
1817
use io::{io_error, EndOfFile};
19-
use io::native::file;
20-
use rt::rtio::{LocalIo, RtioPipe};
18+
use libc;
19+
use rt::rtio::{RtioPipe, LocalIo};
2120

2221
pub struct PipeStream {
2322
priv obj: ~RtioPipe,
@@ -43,15 +42,10 @@ impl PipeStream {
4342
///
4443
/// If the pipe cannot be created, an error will be raised on the
4544
/// `io_error` condition.
46-
pub fn open(fd: file::fd_t) -> Option<PipeStream> {
47-
let mut io = LocalIo::borrow();
48-
match io.get().pipe_open(fd) {
49-
Ok(obj) => Some(PipeStream { obj: obj }),
50-
Err(e) => {
51-
io_error::cond.raise(e);
52-
None
53-
}
54-
}
45+
pub fn open(fd: libc::c_int) -> Option<PipeStream> {
46+
LocalIo::maybe_raise(|io| {
47+
io.pipe_open(fd).map(|obj| PipeStream { obj: obj })
48+
})
5549
}
5650

5751
pub fn new(inner: ~RtioPipe) -> PipeStream {

branches/try2/src/libstd/io/process.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,17 @@ impl Process {
119119
/// Creates a new pipe initialized, but not bound to any particular
120120
/// source/destination
121121
pub fn new(config: ProcessConfig) -> Option<Process> {
122-
let mut io = LocalIo::borrow();
123-
match io.get().spawn(config) {
124-
Ok((p, io)) => Some(Process{
125-
handle: p,
126-
io: io.move_iter().map(|p|
127-
p.map(|p| io::PipeStream::new(p))
128-
).collect()
129-
}),
130-
Err(ioerr) => {
131-
io_error::cond.raise(ioerr);
132-
None
133-
}
134-
}
122+
let mut config = Some(config);
123+
LocalIo::maybe_raise(|io| {
124+
io.spawn(config.take_unwrap()).map(|(p, io)| {
125+
Process {
126+
handle: p,
127+
io: io.move_iter().map(|p| {
128+
p.map(|p| io::PipeStream::new(p))
129+
}).collect()
130+
}
131+
})
132+
})
135133
}
136134

137135
/// Returns the process id of this child process

0 commit comments

Comments
 (0)