summary refs log tree commit diff
path: root/src/libstd/rt/rtio.rs
AgeCommit message (Collapse)AuthorLines
2014-03-27Fix fallout of removing default boundsAlex Crichton-78/+81
This is all purely fallout of getting the previous commit to compile.
2014-03-13auto merge of #12855 : alexcrichton/rust/shutdown, r=brsonbors-0/+1
This is something that is plausibly useful, and is provided by libuv. This is not currently surfaced as part of the `TcpStream` type, but it may possibly appear in the future. For now only the raw functionality is provided through the Rtio objects.
2014-03-13io: Bind to shutdown() for TCP streamsAlex Crichton-0/+1
This is something that is plausibly useful, and is provided by libuv. This is not currently surfaced as part of the `TcpStream` type, but it may possibly appear in the future. For now only the raw functionality is provided through the Rtio objects.
2014-03-13std: Rename Chan/Port types and constructorAlex Crichton-4/+4
* Chan<T> => Sender<T> * Port<T> => Receiver<T> * Chan::new() => channel() * constructor returns (Sender, Receiver) instead of (Receiver, Sender) * local variables named `port` renamed to `rx` * local variables named `chan` renamed to `tx` Closes #11765
2014-02-23Roll std::run into std::io::processAlex Crichton-0/+1
The std::run module is a relic from a standard library long since past, and there's not much use to having two modules to execute processes with where one is slightly more convenient. This commit merges the two modules, moving lots of functionality from std::run into std::io::process and then deleting std::run. New things you can find in std::io::process are: * Process::new() now only takes prog/args * Process::configure() takes a ProcessConfig * Process::status() is the same as run::process_status * Process::output() is the same as run::process_output * I/O for spawned tasks is now defaulted to captured in pipes instead of ignored * Process::kill() was added (plus an associated green/native implementation) * Process::wait_with_output() is the same as the old finish_with_output() * destroy() is now signal_exit() * force_destroy() is now signal_kill() Closes #2625 Closes #10016
2014-02-12Expose whether event loops have active I/OAlex Crichton-0/+1
The green scheduler can optimize its runtime based on this by deciding to not go to sleep in epoll() if there is no active I/O and there is a task to be stolen. This is implemented for librustuv by keeping a count of the number of tasks which are currently homed. If a task is homed, and then performs a blocking I/O operation, the count will be nonzero while the task is blocked. The homing count is intentionally 0 when there are I/O handles, but no handles currently blocked. The reason for this is that epoll() would only be used to wake up the scheduler anyway. The crux of this change was to have a `HomingMissile` contain a mutable borrowed reference back to the `HomeHandle`. The rest of the change was just dealing with this fallout. This reference is used to decrement the homed handle count in a HomingMissile's destructor. Also note that the count maintained is not atomic because all of its increments/decrements/reads are all on the same I/O thread.
2014-02-11Rewrite channels yet again for upgradeabilityAlex Crichton-2/+2
This, the Nth rewrite of channels, is not a rewrite of the core logic behind channels, but rather their API usage. In the past, we had the distinction between oneshot, stream, and shared channels, but the most recent rewrite dropped oneshots in favor of streams and shared channels. This distinction of stream vs shared has shown that it's not quite what we'd like either, and this moves the `std::comm` module in the direction of "one channel to rule them all". There now remains only one Chan and one Port. This new channel is actually a hybrid oneshot/stream/shared channel under the hood in order to optimize for the use cases in question. Additionally, this also reduces the cognitive burden of having to choose between a Chan or a SharedChan in an API. My simple benchmarks show no reduction in efficiency over the existing channels today, and a 3x improvement in the oneshot case. I sadly don't have a pre-last-rewrite compiler to test out the old old oneshots, but I would imagine that the performance is comparable, but slightly slower (due to atomic reference counting). This commit also brings the bonus bugfix to channels that the pending queue of messages are all dropped when a Port disappears rather then when both the Port and the Chan disappear.
2014-02-05Implement clone() for TCP/UDP/Unix socketsAlex Crichton-0/+4
This is part of the overall strategy I would like to take when approaching issue #11165. The only two I/O objects that reasonably want to be "split" are the network stream objects. Everything else can be "split" by just creating another version. The initial idea I had was the literally split the object into a reader and a writer half, but that would just introduce lots of clutter with extra interfaces that were a little unnnecssary, or it would return a ~Reader and a ~Writer which means you couldn't access things like the remote peer name or local socket name. The solution I found to be nicer was to just clone the stream itself. The clone is just a clone of the handle, nothing fancy going on at the kernel level. Conceptually I found this very easy to wrap my head around (everything else supports clone()), and it solved the "split" problem at the same time. The cloning support is pretty specific per platform/lib combination: * native/win32 - uses some specific WSA apis to clone the SOCKET handle * native/unix - uses dup() to get another file descriptor * green/all - This is where things get interesting. When we support full clones of a handle, this implies that we're allowing simultaneous writes and reads to happen. It turns out that libuv doesn't support two simultaneous reads or writes of the same object. It does support *one* read and *one* write at the same time, however. Some extra infrastructure was added to just block concurrent writers/readers until the previous read/write operation was completed. I've added tests to the tcp/unix modules to make sure that this functionality is supported everywhere.
2014-02-03std: Remove io::io_errorAlex Crichton-17/+6
* All I/O now returns IoResult<T> = Result<T, IoError> * All formatting traits now return fmt::Result = IoResult<()> * The if_ok!() macro was added to libstd
2014-01-26Removed all instances of XXX in preparation for relaxing of FIXME ruleSalem Talha-2/+2
2013-12-25Test fixes and rebase conflictsAlex Crichton-8/+10
* vec::raw::to_ptr is gone * Pausible => Pausable * Removing @ * Calling the main task "<main>" * Removing unused imports * Removing unused mut * Bringing some libextra tests up to date * Allowing compiletest to work at stage0 * Fixing the bootstrap-from-c rmake tests * assert => rtassert in a few cases * printing to stderr instead of stdout in fail!()
2013-12-24rustuv: Remove the id() function from IoFactoryAlex Crichton-2/+0
The only user of this was the homing code in librustuv, and it just manually does the cast from a pointer to a uint now.
2013-12-24green: Rip the bandaid off, introduce libgreenAlex Crichton-4/+7
This extracts everything related to green scheduling from libstd and introduces a new libgreen crate. This mostly involves deleting most of std::rt and moving it to libgreen. Along with the movement of code, this commit rearchitects many functions in the scheduler in order to adapt to the fact that Local::take now *only* works on a Task, not a scheduler. This mostly just involved threading the current green task through in a few locations, but there were one or two spots where things got hairy. There are a few repercussions of this commit: * tube/rc have been removed (the runtime implementation of rc) * There is no longer a "single threaded" spawning mode for tasks. This is now encompassed by 1:1 scheduling + communication. Convenience methods have been introduced that are specific to libgreen to assist in the spawning of pools of schedulers.
2013-12-24std: Expose that LocalIo may not always be availableAlex Crichton-23/+37
It is not the case that all programs will always be able to acquire an instance of the LocalIo borrow, so this commit exposes this limitation by returning Option<LocalIo> from LocalIo::borrow(). At the same time, a helper method LocalIo::maybe_raise() has been added in order to encapsulate the functionality of raising on io_error if there is on local I/O available.
2013-12-16Fallout of rewriting std::commAlex Crichton-2/+2
2013-12-15std::rt: s/pausible/pausable/.Huon Wilson-2/+2
2013-12-10libstd: Remove `Cell` from the library.Patrick Walton-8/+15
2013-12-10librustuv: Change `with_local_io` to use RAII.Patrick Walton-23/+48
2013-11-19libstd: Change all uses of `&fn(A)->B` over to `|A|->B` in libstdPatrick Walton-2/+2
2013-11-18Allow piped stdout/stderr use uv_tty_tAlex Crichton-0/+1
There are issues with reading stdin when it is actually attached to a pipe, but I have run into no problems in writing to stdout/stderr when they are attached to pipes.
2013-11-13Implement native::IoFactoryAlex Crichton-9/+17
This commit re-organizes the io::native module slightly in order to have a working implementation of rtio::IoFactory which uses native implementations. The goal is to seamlessly multiplex among libuv/native implementations wherever necessary. Right now most of the native I/O is unimplemented, but we have existing bindings for file descriptors and processes which have been hooked up. What this means is that you can now invoke println!() from libstd with no local task, no local scheduler, and even without libuv. There's still plenty of work to do on the native I/O factory, but this is the first steps into making it an official portion of the standard library. I don't expect anyone to reach into io::native directly, but rather only std::io primitives will be used. Each std::io interface seamlessly falls back onto the native I/O implementation if the local scheduler doesn't have a libuv one (hurray trait ojects!)
2013-11-11Move std::rt::io to std::ioAlex Crichton-12/+12
2013-11-12Implemented a ProcessExit enum and helper methods to std::rt::io::process ↵Matthew Iselin-2/+2
for getting process termination status, or the signal that terminated a process. A test has been added to rtio-processes.rs to ensure signal termination is picked up correctly.
2013-11-10Fall back from uv tty instances more aggressivelyAlex Crichton-1/+0
It appears that uv's support for interacting with a stdio stream as a tty when it's actually a pipe is pretty problematic. To get around this, promote a check to see if the stream is a tty to the top of the tty constructor, and bail out quickly if it's not identified as a tty. Closes #10237
2013-11-10Rework the idle callback to have a safer interfaceAlex Crichton-3/+1
It turns out that the uv implementation would cause use-after-free if the idle callback was used after the call to `close`, and additionally nothing would ever really work that well if `start()` were called twice. To change this, the `start` and `close` methods were removed in favor of specifying the callback at creation, and allowing destruction to take care of closing the watcher.
2013-11-10Add bindings to uv's utime functionAlex Crichton-0/+2
This exposes the ability to change the modification and access times on a file. Closes #10266
2013-11-10Start migrating stream I/O away from ~fn()Alex Crichton-2/+0
2013-11-10Remove usage of ~fn() from uv async/idleAlex Crichton-3/+7
2013-11-03Fill out the remaining functionality in io::fileAlex Crichton-5/+18
This adds bindings to the remaining functions provided by libuv, all of which are useful operations on files which need to get exposed somehow. Some highlights: * Dropped `FileReader` and `FileWriter` and `FileStream` for one `File` type * Moved all file-related methods to be static methods under `File` * All directory related methods are still top-level functions * Created `io::FilePermission` types (backed by u32) that are what you'd expect * Created `io::FileType` and refactored `FileStat` to use FileType and FilePermission * Removed the expanding matrix of `FileMode` operations. The mode of reading a file will not have the O_CREAT flag, but a write mode will always have the O_CREAT flag. Closes #10130 Closes #10131 Closes #10121
2013-11-03Remove all blocking std::os blocking functionsAlex Crichton-2/+5
This commit moves all thread-blocking I/O functions from the std::os module. Their replacements can be found in either std::rt::io::file or in a hidden "old_os" module inside of native::file. I didn't want to outright delete these functions because they have a lot of special casing learned over time for each OS/platform, and I imagine that these will someday get integrated into a blocking implementation of IoFactory. For now, they're moved to a private module to prevent bitrot and still have tests to ensure that they work. I've also expanded the extensions to a few more methods defined on Path, most of which were previously defined in std::os but now have non-thread-blocking implementations as part of using the current IoFactory. The api of io::file is in flux, but I plan on changing it in the next commit as well. Closes #10057
2013-11-03Modify IoFactory's fs_mkdir, and add fs_renameAlex Crichton-1/+2
The invocation for making a directory should be able to specify a mode to make the directory with (instead of defaulting to one particular mode). Additionally, libuv and various OSes implement efficient versions of renaming files, so this operation is exposed as an IoFactory call.
2013-10-30Make Writer::flush a no-op default methodAlex Crichton-1/+0
Closes #9126
2013-10-25Enhance timers to create portsAlex Crichton-1/+3
In addition to being able to sleep the current task, timers should be able to create ports which get notified after a period of time. Closes #10014
2013-10-24Remove the 'callback_ms' function from EventLoopAlex Crichton-1/+0
This is a peculiar function to require event loops to implement, and it's only used in one spot during tests right now. Instead, a possibly more robust apis for timers should be used rather than requiring all event loops to implement a curious-looking function.
2013-10-24Another round of test fixes and merge conflictsAlex Crichton-1/+15
2013-10-24wrapping libuv signal for use in RustDo Nhat Minh-0/+6
descriptive names easier-to-use api reorganize and document
2013-10-24Move stdin to using libuv's pipes instead of a ttyAlex Crichton-0/+1
I was seeing a lot of weird behavior with stdin behaving as a tty, and it doesn't really quite make sense, so instead this moves to using libuv's pipes instead (which make more sense for stdin specifically). This prevents piping input to rustc hanging forever.
2013-10-24Move as much I/O as possible off of native::ioAlex Crichton-1/+2
When uv's TTY I/O is used for the stdio streams, the file descriptors are put into a non-blocking mode. This means that other concurrent writes to the same stream can fail with EAGAIN or EWOULDBLOCK. By all I/O to event-loop I/O, we avoid this error. There is one location which cannot move, which is the runtime's dumb_println function. This was implemented to handle the EAGAIN and EWOULDBLOCK errors and simply retry again and again.
2013-10-24Migrate the last typedefs to ~Trait in rtioAlex Crichton-9/+4
There are no longer any remnants of typedefs, and everything is now built on true trait objects.
2013-10-24Don't attempt to export uv functions directlyAlex Crichton-1/+0
2013-10-24Remove IoFactoryObject for ~IoFactoryAlex Crichton-6/+27
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.
2013-10-24Remove rt::io::supportAlex Crichton-7/+6
This removes the PathLike trait associated with this "support module". This is yet another "container of bytes" trait, so I didn't want to duplicate what already exists throughout libstd. In actuality, we're going to pass of C strings to the libuv APIs, so instead the arguments are now bound with the 'ToCStr' trait instead. Additionally, a layer of complexity was removed by immediately converting these type-generic parameters into CStrings to get handed off to libuv apis.
2013-10-24Migrate Rtio objects to true trait objectsAlex Crichton-26/+20
This moves as many as I could over to ~Trait instead of ~Typedef. The only remaining one is the IoFactoryObject which should be coming soon...
2013-10-24Move rt::io::stdio from FileStream to a TTYAlex Crichton-0/+11
We get a little more functionality from libuv for these kinds of streams (things like terminal dimentions), and it also appears to more gracefully handle the stream being a window. Beforehand, if you used stdio and hit CTRL+d on a process, libuv would continually return 0-length successful reads instead of interpreting that the stream was closed. I was hoping to be able to write tests for this, but currently the testing infrastructure doesn't allow tests with a stdin and a stdout, but this has been manually tested! (not that it means much)
2013-10-24Remove unbound pipes from io::pipeAlex Crichton-2/+0
This isn't necessary for creating processes (or at least not right now), and it inherently attempts to expose implementation details.
2013-10-24Finish implementing io::net::addrinfoAlex Crichton-1/+3
This fills in the `hints` structure and exposes libuv's full functionality for doing dns lookups.
2013-10-24Implement io::net::unixAlex Crichton-1/+18
2013-10-23Removed Unnecessary comments and white spaces #4386reedlepee-1/+0
2013-10-23Making fields in std and extra : private #4386reedlepee-1/+2
2013-09-18Implement process bindings to libuvAlex Crichton-0/+19
This is a re-landing of #8645, except that the bindings are *not* being used to power std::run just yet. Instead, this adds the bindings as standalone bindings inside the rt::io::process module. I made one major change from before, having to do with how pipes are created/bound. It's much clearer now when you can read/write to a pipe, as there's an explicit difference (different types) between an unbound and a bound pipe. The process configuration now takes unbound pipes (and consumes ownership of them), and will return corresponding pipe structures back if spawning is successful (otherwise everything is destroyed normally).