about summary refs log tree commit diff
path: root/src/libnative/io
AgeCommit message (Collapse)AuthorLines
2014-02-21Changed NonCamelCaseTypes lint to warn by defaultmr.Shu-4/+15
Added allow(non_camel_case_types) to librustc where necesary Tried to fix problems with non_camel_case_types outside rustc fixed failing tests Docs updated Moved #[allow(non_camel_case_types)] a level higher. markdown.rs reverted Fixed timer that was failing tests Fixed another timer
2014-02-20Mass rename if_ok! to try!Alex Crichton-8/+8
This "bubble up an error" macro was originally named if_ok! in order to get it landed, but after the fact it was discovered that this name is not exactly desirable. The name `if_ok!` isn't immediately clear that is has much to do with error handling, and it doesn't look fantastic in all contexts (if if_ok!(...) {}). In general, the agreed opinion about `if_ok!` is that is came in as subpar. The name `try!` is more invocative of error handling, it's shorter by 2 letters, and it looks fitting in almost all circumstances. One concern about the word `try!` is that it's too invocative of exceptions, but the belief is that this will be overcome with documentation and examples. Close #12037
2014-02-19librustc: Remove unique vector patterns from the language.Patrick Walton-19/+17
Preparatory work for removing unique vectors from the language, which is itself preparatory work for dynamically sized types.
2014-02-18auto merge of #12317 : huonw/rust/utf16, r=alexcrichtonbors-1/+3
Iterators! Use them (in `is_utf16`), create them (in `utf16_items`). Handle errors gracefully (`from_utf16_lossy`) and `from_utf16` returning `Option<~str>` instead of failing. Add a pile of tests.
2014-02-19str: add a function for truncating a vector of u16 at NUL.Huon Wilson-1/+2
Many of the functions interacting with Windows APIs allocate a vector of 0's and do not retrieve a length directly from the API call, and so need to be sure to remove the unmodified junk at the end of the vector.
2014-02-18std: make str::from_utf16 return an Option.Huon Wilson-1/+2
The rest of the codebase is moving toward avoiding `fail!` so we do it here too!
2014-02-16Implement named pipes for windows, touch up unixAlex Crichton-237/+666
* Implementation of pipe_win32 filled out for libnative * Reorganize pipes to be clone-able * Fix a few file descriptor leaks on error * Factor out some common code into shared functions * Make use of the if_ok!() macro for less indentation Closes #11201
2014-02-16Move unix pipes implementation to pipe_unix.rsAlex Crichton-307/+312
The windows named pipes implementation will have almost nothing to do with unix pipes, so I think it's best if they live in separate files.
2014-02-16Implement Unix domain sockets in libnativeGeoffroy Couprie-2/+358
2014-02-16Allow configuration of uid/gid/detach on processesAlex Crichton-21/+74
This just copies the libuv implementation for libnative which seems reasonable enough (uid/gid fail on windows). Closes #12082
2014-02-17Remove CloneableTuple and ImmutableTuple traitsBrendan Zabarauskas-2/+2
These are adequately covered by the Tuple2 trait.
2014-02-16std: Rename unstable::mutex::Mutex to StaticNativeMutex.Huon Wilson-4/+4
This better reflects its purpose and design.
2014-02-16std: add an RAII unlocker to Mutex.Huon Wilson-4/+2
This automatically unlocks its lock when it goes out of scope, and provides a safe(ish) method to call .wait.
2014-02-11Rewrite channels yet again for upgradeabilityAlex Crichton-6/+7
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-09auto merge of #12136 : alexcrichton/rust/issue-12123, r=brsonbors-1/+1
Closes #12123
2014-02-09Fix the signature of CreateSymbolicLinkWAlex Crichton-1/+1
Closes #12123
2014-02-09std: Move byteswap functions to memBrian Anderson-3/+2
2014-02-09std: Add init and uninit to mem. Replace direct intrinsic usageBrian Anderson-17/+17
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-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