about summary refs log tree commit diff
path: root/src/libnative/io
AgeCommit message (Collapse)AuthorLines
2014-02-03Various bug fixes and rebase conflictsAlex Crichton-14/+17
2014-02-03extra: Re-add the Once primitve to extra::syncAlex Crichton-8/+14
This originally lived in std::unstable::mutex, but now it has a new home (and a more proper one).
2014-02-03Fixing remaining warnings and errors throughoutAlex Crichton-24/+25
2014-02-03std: Fixing all documentationAlex Crichton-3/+4
* Stop referencing io_error * Start changing "Failure" sections to "Error" sections * Update all doc examples to work.
2014-02-03native: Require all results are used and fix falloutAlex Crichton-19/+20
2014-02-03native: Remove io_error usageAlex Crichton-7/+4
2014-02-02libnative: fix epoll_event struct layoutBen Noordhuis-9/+10
Make the definition of epoll_event use natural alignment on all architectures except x86_64. Before this commit, the struct was always 12 bytes big, which works okay on x86 and x86_64 but not on ARM and MIPS, where it should be 16 bytes big with the `data` field aligned on an 8 byte boundary.
2014-01-29auto merge of #11754 : alexcrichton/rust/unused-result, r=brsonbors-17/+15
The general consensus is that we want to move away from conditions for I/O, and I propose a two-step plan for doing so: 1. Warn about unused `Result` types. When all of I/O returns `Result`, it will require you inspect the return value for an error *only if* you have a result you want to look at. By default, for things like `write` returning `Result<(), Error>`, these will all go silently ignored. This lint will prevent blind ignorance of these return values, letting you know that there's something you should do about them. 2. Implement a `try!` macro: ``` macro_rules! try( ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) }) ) ``` With these two tools combined, I feel that we get almost all the benefits of conditions. The first step (the lint) is a sanity check that you're not ignoring return values at callsites. The second step is to provide a convenience method of returning early out of a sequence of computations. After thinking about this for awhile, I don't think that we need the so-called "do-notation" in the compiler itself because I think it's just *too* specialized. Additionally, the `try!` macro is super lightweight, easy to understand, and works almost everywhere. As soon as you want to do something more fancy, my answer is "use match". Basically, with these two tools in action, I would be comfortable removing conditions. What do others think about this strategy? ---- This PR specifically implements the `unused_result` lint. I actually added two lints, `unused_result` and `unused_must_use`, and the first commit has the rationale for why `unused_result` is turned off by default.
2014-01-29Flag Result as #[must_use] and deal with fallout.Alex Crichton-17/+15
2014-01-29Removing do keyword from libnativeScott Lawrence-2/+2
2014-01-27Set SO_REUSEADDR by default in libnative.xales-0/+11
Fixes std::net test error when re-running too quickly.
2014-01-26Removed all instances of XXX in preparation for relaxing of FIXME ruleSalem Talha-5/+5
2014-01-26std,extra: Make some types public and other private.Huon Wilson-1/+1
These are either returned from public functions, and really should appear in the documentation, but don't since they're private, or are implementation details that are currently public.
2014-01-24auto merge of #11748 : brson/rust/timerfdandroid, r=alexcrichtonbors-1/+2
It doesn't seem to exist.
2014-01-24auto merge of #11732 : luqmana/rust/native-getaddrinfo, r=alexcrichtonbors-11/+129
The last bit I needed to be able to use libnative :P
2014-01-24libnative: Avoid gai_strerror on windows.Luqman Aden-11/+28
2014-01-23auto merge of #11686 : mankyKitty/rust/rename-invert-to-flip-issue-10632, ↵bors-1/+1
r=alexcrichton Renamed the ```invert()``` function in ```iter.rs``` to ```flip()```, from #10632 Also renamed the ```Invert<T>``` type to ```Flip<T>```. Some related code comments changed. Documentation that I could find has been updated, and all the instances I could locate where the function/type were called have been updated as well. This is my first contribution to Rust! Apologies in advance if I've snarfed the PR process, I'm not used to rebase. I initially had issues with the ```codegen``` section of the tests failing, however the ```make check``` process is not reporting any failures at this time. I think that was a local env issue more than me facerolling my changes. :)
2014-01-23Update flip() to be rev().Sean Chalmers-1/+1
Consensus leaned in favour of using rev instead of flip.
2014-01-23Rename Invert to Flip - Issue 10632Sean Chalmers-1/+1
Renamed the invert() function in iter.rs to flip(). Also renamed the Invert<T> type to Flip<T>. Some related code comments changed. Documentation that I could find has been updated, and all the instances I could locate where the function/type were called have been updated as well.
2014-01-23Handle EINTR in epoll for native timersAlex Crichton-0/+1
2014-01-23native: Don't use timerfd on AndroidBrian Anderson-1/+2
It doesn't seem to exist.
2014-01-22auto merge of #11682 : thestinger/rust/vector, r=brsonbors-3/+3
This is just an initial implementation and does not yet fully replace `~[T]`. A generic initialization syntax for containers is missing, and the slice functionality needs to be reworked to make auto-slicing unnecessary. Traits for supporting indexing properly are also required. This also needs to be fixed to make ring buffers as easy to use as vectors. The tests and documentation for `~[T]` can be ported over to this type when it is removed. I don't really expect DST to happen for vectors as having both `~[T]` and `Vec<T>` is overcomplicated and changing the slice representation to 3 words is not at all appealing. Unlike with traits, it's possible (and easy) to implement `RcSlice<T>` and `GcSlice<T>` without compiler help.
2014-01-22libc: switch `free` to the proper signatureDaniel Micay-3/+3
This does not attempt to fully propagate the mutability everywhere, but gives new code a hint to avoid the same issues.
2014-01-22Implement native timersAlex Crichton-1/+994
Native timers are a much hairier thing to deal with than green timers due to the interface that we would like to expose (both a blocking sleep() and a channel-based interface). I ended up implementing timers in three different ways for the various platforms that we supports. In all three of the implementations, there is a worker thread which does send()s on channels for timers. This worker thread is initialized once and then communicated to in a platform-specific manner, but there's always a shared channel available for sending messages to the worker thread. * Windows - I decided to use windows kernel timer objects via CreateWaitableTimer and SetWaitableTimer in order to provide sleeping capabilities. The worker thread blocks via WaitForMultipleObjects where one of the objects is an event that is used to wake up the helper thread (which then drains the incoming message channel for requests). * Linux/(Android?) - These have the ideal interface for implementing timers, timerfd_create. Each timer corresponds to a timerfd, and the helper thread uses epoll to wait for all active timers and then send() for the next one that wakes up. The tricky part in this implementation is updating a timerfd, but see the implementation for the fun details * OSX/FreeBSD - These obviously don't have the windows APIs, and sadly don't have the timerfd api available to them, so I have thrown together a solution which uses select() plus a timeout in order to ad-hoc-ly implement a timer solution for threads. The implementation is backed by a sorted array of timers which need to fire. As I said, this is an ad-hoc solution which is certainly not accurate timing-wise. I have done this implementation due to the lack of other primitives to provide an implementation, and I've done it the best that I could, but I'm sure that there's room for improvement. I'm pretty happy with how these implementations turned out. In theory we could drop the timerfd implementation and have linux use the select() + timeout implementation, but it's so inaccurate that I would much rather continue to use timerfd rather than my ad-hoc select() implementation. The only change that I would make to the API in general is to have a generic sleep() method on an IoFactory which doesn't require allocating a Timer object. For everything but windows it's super-cheap to request a blocking sleep for a set amount of time, and it's probably worth it to provide a sleep() which doesn't do something like allocate a file descriptor on linux.
2014-01-22libnative: Implement get_host_addresses.Luqman Aden-11/+112
2014-01-21Remove unnecessary parentheses.Huon Wilson-2/+2
2014-01-17handle zero-size allocations correctlyDaniel Micay-2/+2
The `malloc` family of functions may return a null pointer for a zero-size allocation, which should not be interpreted as an out-of-memory error. If the implementation does not return a null pointer, then handling this will result in memory savings for zero-size types. This also switches some code to `malloc_raw` in order to maintain a centralized point for handling out-of-memory in `rt::global_heap`. Closes #11634
2014-01-09Remove eof() from io::ReaderAlex Crichton-1/+0
2014-01-06Don't read forever on a file descriptorAlex Crichton-4/+4
Similarly to the recent commit to do this for networking, there's no reason that a read on a file descriptor should continue reading until the entire buffer is full. This makes sense when dealing with literal files, but when dealing with things like stdin this doesn't make sense.
2014-01-06Don't wait for a full buffer when reading TCPAlex Crichton-4/+4
libnative erroneously would attempt to fill the entire buffer in a call to `read` before returning, when rather it should return immediately because there's not guaranteed to be any data that will ever be received again. Close #11328
2014-01-05Handle EINTR throughout libnativeAlex Crichton-70/+108
Closes #11214
2014-01-01libnative: Use [from|to]_be16 instead of bswap16Carl-Anton Ingmarsson-6/+2
2013-12-31auto merge of #11187 : alexcrichton/rust/once, r=brsonbors-9/+4
Rationale can be found in the first commit, but this is basically the same thing as `pthread_once`
2013-12-31Convert relevant static mutexes to OnceAlex Crichton-9/+4
2013-12-31Implement native UDP I/OAlex Crichton-89/+264
2013-12-27Implement native TCP I/OAlex Crichton-15/+462
2013-12-27Bring native process bindings up to dateAlex Crichton-70/+136
Move the tests into libstd, use the `iotest!` macro to test both native and uv bindings, and use the cloexec trick to figure out when the child process fails in exec.
2013-12-25Test fixes and rebase conflictsAlex Crichton-1/+2
* 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-3/+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-24native: Add tests and cleanup entry pointsAlex Crichton-2/+1
This adds a few smoke tests associated with libnative tasks (not much code to test here anyway), and cleans up the entry points a little bit to be a little more like libgreen. The I/O code doesn't need much testing because that's all tested in libstd (with the iotest! macro).
2013-12-24native: Introduce libnativeAlex Crichton-0/+1835
This commit introduces a new crate called "native" which will be the crate that implements the 1:1 runtime of rust. This currently entails having an implementation of std::rt::Runtime inside of libnative as well as moving all of the native I/O implementations to libnative. The current snag is that the start lang item must currently be defined in libnative in order to start running, but this will change in the future. Cool fact about this crate, there are no extra features that are enabled. Note that this commit does not include any makefile support necessary for building libnative, that's all coming in a later commit.