about summary refs log tree commit diff
path: root/src/libnative
AgeCommit message (Collapse)AuthorLines
2014-02-07Delete send_str, rewrite clients on top of MaybeOwned<'static>Kevin Ballard-1/+1
Declare a `type SendStr = MaybeOwned<'static>` to ease readibility of types that needed the old SendStr behavior. Implement all the traits for MaybeOwned that SendStr used to implement.
2014-02-06Add some doc examples to lib{green,native}Alex Crichton-1/+28
"How do I start in libX" is a common question that I've seen, so I figured putting the examples in as many places as possible is probably a good idea.
2014-02-05Implement clone() for TCP/UDP/Unix socketsAlex Crichton-64/+113
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-03Various bug fixes and rebase conflictsAlex Crichton-14/+17
2014-02-03std: Remove try_send_deferred plus all falloutAlex Crichton-1/+3
Now that extra::sync primitives are built on a proper mutex instead of a pthreads one, there's no longer any use for this function.
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-22/+26
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-30Remove Times traitBrendan Zabarauskas-1/+1
`Times::times` was always a second-class loop because it did not support the `break` and `continue` operations. Its playful appeal was then lost after `do` was disabled for closures. It's time to let this one go.
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-18/+18
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/+995
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-16Fixing a typo: bookeeping -> bookkeepingDerek Chiang-10/+10
2014-01-15register snapshotsDaniel Micay-24/+0
2014-01-12Bump version to 0.10-preBrian Anderson-1/+1
2014-01-09auto merge of #11360 : huonw/rust/stack_bounds, r=alexcrichtonbors-7/+26
We just approximate with a 2MB stack for native::start.
2014-01-09Remove eof() from io::ReaderAlex Crichton-1/+0
2014-01-07doc: Add libgreen and libnative to the indexBrian Anderson-0/+3
2014-01-07auto merge of #11353 : alexcrichton/rust/improve-logging, r=brsonbors-1/+5
This will allow capturing of common things like logging messages, stdout prints (using stdio println), and failure messages (printed to stderr). Any new prints added to libstd should be funneled through these task handles to allow capture as well. Additionally, this commit redirects logging back through a `Logger` trait so the log level can be usefully consumed by an arbitrary logger. This commit also introduces methods to set the task-local stdout handles: * std::io::stdio::set_stdout * std::io::stdio::set_stderr * std::io::logging::set_logger These methods all return the previous logger just in case it needs to be used for inspection. I plan on using this infrastructure for extra::test soon, but we don't quite have the primitives that I'd like to use for it, so it doesn't migrate extra::test at this time. Closes #6369
2014-01-07auto merge of #11348 : alexcrichton/rust/snapshots, r=brsonbors-3/+0
2014-01-07std::rt: require known stack bounds for all tasks.Huon Wilson-7/+26
We just approximate with a 1 or 2 MB stack for native::start.
2014-01-06Don't read forever on a file descriptorAlex Crichton-5/+5
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-06Support arbitrary stdout/stderr/logger handlesAlex Crichton-2/+6
This will allow capturing of common things like logging messages, stdout prints (using stdio println), and failure messages (printed to stderr). Any new prints added to libstd should be funneled through these task handles to allow capture as well. Additionally, this commit redirects logging back through a `Logger` trait so the log level can be usefully consumed by an arbitrary logger. This commit also introduces methods to set the task-local stdout handles: * std::io::stdio::set_stdout * std::io::stdio::set_stderr * std::io::logging::set_logger These methods all return the previous logger just in case it needs to be used for inspection. I plan on using this infrastructure for extra::test soon, but we don't quite have the primitives that I'd like to use for it, so it doesn't migrate extra::test at this time. Closes #6369
2014-01-06auto merge of #11334 : alexcrichton/rust/fix-native-tcp, r=pcwaltonbors-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-06Register new snapshotsAlex Crichton-4/+1
2014-01-06auto merge of #11315 : alexcrichton/rust/issue-11309, r=huonwbors-1/+5
There was a scheduling race where a child may not increment the global task count before the parent exits, and the parent would then think that there are no more tasks left. Closes #11039
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-05Guarantee that native tasks wait for childrenAlex Crichton-1/+5
There was a scheduling race where a child may not increment the global task count before the parent exits, and the parent would then think that there are no more tasks left.
2014-01-05auto merge of #11313 : alexcrichton/rust/fix-native-failure, r=pcwaltonbors-1/+2
2014-01-05auto merge of #11304 : alexcrichton/rust/eintr, r=brsonbors-70/+108
Closes #11214