about summary refs log tree commit diff
path: root/src/libnative
AgeCommit message (Collapse)AuthorLines
2014-05-04auto merge of #13865 : alexcrichton/rust/issue-13861, r=brsonbors-1/+1
Previously, windows was using the CREATE_NEW flag which fails if the file previously existed, which differed from the unix semantics. This alters the opening to use the OPEN_ALWAYS flag to mirror the unix semantics. Closes #13861
2014-05-04Implement fallbacks for functions unavailable in older versions of WindowsAlan Williams-5/+7
2014-05-02Replace most ~exprs with 'box'. #11779Brian Anderson-29/+29
2014-05-03Add lint check for negating uint literals and variables.Falco Hirschenberger-3/+3
See #11273 and #13318
2014-04-30native: Always open a file with Open/Write modesAlex Crichton-1/+1
Previously, windows was using the CREATE_NEW flag which fails if the file previously existed, which differed from the unix semantics. This alters the opening to use the OPEN_ALWAYS flag to mirror the unix semantics. Closes #13861
2014-04-24std: Add timeouts to unix connect/acceptAlex Crichton-159/+228
This adds support for connecting to a unix socket with a timeout (a named pipe on windows), and accepting a connection with a timeout. The goal is to bring unix pipes/named sockets back in line with TCP support for timeouts. Similarly to the TCP sockets, all methods are marked #[experimental] due to uncertainty about the type of the timeout argument. This internally involved a good bit of refactoring to share as much code as possible between TCP servers and pipe servers, but the core implementation did not change drastically as part of this commit. cc #13523
2014-04-24native: Remove unused and untested UnixDatagramAlex Crichton-71/+0
2014-04-23std: Add support for an accept() timeoutAlex Crichton-30/+70
This adds experimental support for timeouts when accepting sockets through `TcpAcceptor::accept`. This does not add a separate `accept_timeout` function, but rather it adds a `set_timeout` function instead. This second function is intended to be used as a hard deadline after which all accepts will never block and fail immediately. This idea was derived from Go's SetDeadline() methods. We do not currently have a robust time abstraction in the standard library, so I opted to have the argument be a relative time in millseconds into the future. I believe a more appropriate argument type is an absolute time, but this concept does not exist yet (this is also why the function is marked #[experimental]). The native support is built on select(), similarly to connect_timeout(), and the green support is based on channel select and a timer. cc #13523
2014-04-22native: Unlink unix socket paths on dropAlex Crichton-1/+15
This prevents unix sockets from remaining on the system all over the place, and more closely mirrors the behavior of libuv and windows pipes.
2014-04-19std: Add an experimental connect_timeout functionAlex Crichton-112/+284
This adds a `TcpStream::connect_timeout` function in order to assist opening connections with a timeout (cc #13523). There isn't really much design space for this specific operation (unlike timing out normal blocking reads/writes), so I am fairly confident that this is the correct interface for this function. The function is marked #[experimental] because it takes a u64 timeout argument, and the u64 type is likely to change in the future.
2014-04-18Replace all ~"" with "".to_owned()Richo Healey-8/+8
2014-04-18Update the rest of the compiler with ~[T] changesAlex Crichton-14/+9
2014-04-15Use the unsigned integer types for bitwise intrinsics.Huon Wilson-2/+2
Exposing ctpop, ctlz, cttz and bswap as taking signed i8/i16/... is just exposing the internal LLVM names pointlessly (LLVM doesn't have "signed integers" or "unsigned integers", it just has sized integer types with (un)signed *operations*). These operations are semantically working with raw bytes, which the unsigned types model better.
2014-04-15native: Fix a race in select()Alex Crichton-9/+20
During selection, libnative would erroneously re-acquire ownership of a task when a separate thread still had ownership of the task. The loop in select() was rewritten to acknowledge this race and instead block waiting to re-acquire ownership rather than plowing through. Closes #13494
2014-04-15native: Be more stringent about pattern matchingAlex Crichton-1/+1
Trying to avoid a wildcard where possible.
2014-04-12native: Remove timerfd implementation on linuxAlex Crichton-333/+6
Rust advertises itself as being compatible with linux 2.6.18, but the timerfd set of syscalls weren't added until linux 2.6.25. There is no real need for a specialized timer implementation beyond being a "little more accurate", but the select() implementation will suffice for now. If it is later deemed that an accurate timerfd implementation is needed, it can be added then through some method which will allow the standard distribution to continue to be compatible with 2.6.18 Closes #13447
2014-04-12auto merge of #13448 : alexcrichton/rust/rework-chan-return-values, r=brsonbors-16/+13
There are currently a number of return values from the std::comm methods, not all of which are necessarily completely expressive: * `Sender::try_send(t: T) -> bool` This method currently doesn't transmit back the data `t` if the send fails due to the other end having disconnected. Additionally, this shares the name of the synchronous try_send method, but it differs in semantics in that it only has one failure case, not two (the buffer can never be full). * `SyncSender::try_send(t: T) -> TrySendResult<T>` This method accurately conveys all possible information, but it uses a custom type to the std::comm module with no convenience methods on it. Additionally, if you want to inspect the result you're forced to import something from `std::comm`. * `SyncSender::send_opt(t: T) -> Option<T>` This method uses Some(T) as an "error value" and None as a "success value", but almost all other uses of Option<T> have Some/None the other way * `Receiver::try_recv(t: T) -> TryRecvResult<T>` Similarly to the synchronous try_send, this custom return type is lacking in terms of usability (no convenience methods). With this number of drawbacks in mind, I believed it was time to re-work the return types of these methods. The new API for the comm module is: Sender::send(t: T) -> () Sender::send_opt(t: T) -> Result<(), T> SyncSender::send(t: T) -> () SyncSender::send_opt(t: T) -> Result<(), T> SyncSender::try_send(t: T) -> Result<(), TrySendError<T>> Receiver::recv() -> T Receiver::recv_opt() -> Result<T, ()> Receiver::try_recv() -> Result<T, TryRecvError> The notable changes made are: * Sender::try_send => Sender::send_opt. This renaming brings the semantics in line with the SyncSender::send_opt method. An asychronous send only has one failure case, unlike the synchronous try_send method which has two failure cases (full/disconnected). * Sender::send_opt returns the data back to the caller if the send is guaranteed to fail. This method previously returned `bool`, but then it was unable to retrieve the data if the data was guaranteed to fail to send. There is still a race such that when `Ok(())` is returned the data could still fail to be received, but that's inherent to an asynchronous channel. * Result is now the basis of all return values. This not only adds lots of convenience methods to all return values for free, but it also means that you can inspect the return values with no extra imports (Ok/Err are in the prelude). Additionally, it's now self documenting when something failed or not because the return value has "Err" in the name. Things I'm a little uneasy about: * The methods send_opt and recv_opt are not returning options, but rather results. I felt more strongly that Option was the wrong return type than the _opt prefix was wrong, and I coudn't think of a much better name for these methods. One possible way to think about them is to read the _opt suffix as "optionally". * Result<T, ()> is often better expressed as Option<T>. This is only applicable to the recv_opt() method, but I thought it would be more consistent for everything to return Result rather than one method returning an Option. Despite my two reasons to feel uneasy, I feel much better about the consistency in return values at this point, and I think the only real open question is if there's a better suffix for {send,recv}_opt. Closes #11527
2014-04-10std: Make std::comm return types consistentAlex Crichton-16/+13
There are currently a number of return values from the std::comm methods, not all of which are necessarily completely expressive: Sender::try_send(t: T) -> bool This method currently doesn't transmit back the data `t` if the send fails due to the other end having disconnected. Additionally, this shares the name of the synchronous try_send method, but it differs in semantics in that it only has one failure case, not two (the buffer can never be full). SyncSender::try_send(t: T) -> TrySendResult<T> This method accurately conveys all possible information, but it uses a custom type to the std::comm module with no convenience methods on it. Additionally, if you want to inspect the result you're forced to import something from `std::comm`. SyncSender::send_opt(t: T) -> Option<T> This method uses Some(T) as an "error value" and None as a "success value", but almost all other uses of Option<T> have Some/None the other way Receiver::try_recv(t: T) -> TryRecvResult<T> Similarly to the synchronous try_send, this custom return type is lacking in terms of usability (no convenience methods). With this number of drawbacks in mind, I believed it was time to re-work the return types of these methods. The new API for the comm module is: Sender::send(t: T) -> () Sender::send_opt(t: T) -> Result<(), T> SyncSender::send(t: T) -> () SyncSender::send_opt(t: T) -> Result<(), T> SyncSender::try_send(t: T) -> Result<(), TrySendError<T>> Receiver::recv() -> T Receiver::recv_opt() -> Result<T, ()> Receiver::try_recv() -> Result<T, TryRecvError> The notable changes made are: * Sender::try_send => Sender::send_opt. This renaming brings the semantics in line with the SyncSender::send_opt method. An asychronous send only has one failure case, unlike the synchronous try_send method which has two failure cases (full/disconnected). * Sender::send_opt returns the data back to the caller if the send is guaranteed to fail. This method previously returned `bool`, but then it was unable to retrieve the data if the data was guaranteed to fail to send. There is still a race such that when `Ok(())` is returned the data could still fail to be received, but that's inherent to an asynchronous channel. * Result is now the basis of all return values. This not only adds lots of convenience methods to all return values for free, but it also means that you can inspect the return values with no extra imports (Ok/Err are in the prelude). Additionally, it's now self documenting when something failed or not because the return value has "Err" in the name. Things I'm a little uneasy about: * The methods send_opt and recv_opt are not returning options, but rather results. I felt more strongly that Option was the wrong return type than the _opt prefix was wrong, and I coudn't think of a much better name for these methods. One possible way to think about them is to read the _opt suffix as "optionally". * Result<T, ()> is often better expressed as Option<T>. This is only applicable to the recv_opt() method, but I thought it would be more consistent for everything to return Result rather than one method returning an Option. Despite my two reasons to feel uneasy, I feel much better about the consistency in return values at this point, and I think the only real open question is if there's a better suffix for {send,recv}_opt. Closes #11527
2014-04-10auto merge of #13440 : huonw/rust/strbuf, r=alexcrichtonbors-4/+5
libstd: Implement `StrBuf`, a new string buffer type like `Vec`, and port all code over to use it. Rebased & tests-fixed version of https://github.com/mozilla/rust/pull/13269
2014-04-11Fix tests. Add Vec<u8> conversion to StrBuf.Huon Wilson-1/+1
2014-04-10rustc: Disallow importing through use statementsAlex Crichton-1/+1
Resolve is currently erroneously allowing imports through private `use` statements in some circumstances, even across module boundaries. For example, this code compiles successfully today: use std::c_str; mod test { use c_str::CString; } This should not be allowed because it was explicitly decided that private `use` statements are purely bringing local names into scope, they are not participating further in name resolution. As a consequence of this patch, this code, while valid today, is now invalid: mod test { use std::c_str; unsafe fn foo() { ::test::c_str::CString::new(0 as *u8, false); } } While plausibly acceptable, I found it to be more consistent if private imports were only considered candidates to resolve the first component in a path, and no others. Closes #12612
2014-04-10Remove an unnecessary file.OGINO Masanori-0/+0
Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
2014-04-10native: remove some internal ~[].Huon Wilson-15/+15
2014-04-10std,native,green,rustuv: make readdir return `Vec`.Huon Wilson-8/+7
Replacing `~[]`. This also makes the `walk_dir` iterator use a `Vec` internally.
2014-04-10libstd: Implement `StrBuf`, a new string buffer type like `Vec`, andPatrick Walton-4/+5
port all code over to use it.
2014-04-08auto merge of #13397 : alexcrichton/rust/rollup, r=alexcrichtonbors-5/+5
2014-04-08Register new snapshotsAlex Crichton-5/+5
2014-04-07native: Try hard to not malloc on a forked childAlex Crichton-1/+31
This appears to be causing the BSD bots to lock up when looking at the core dumps I've managed to get. Dropping the `FileDesc` structure triggers the `Arc` it's contained in to get cleaned up, invoking free(). This instead just closes the file descriptor (the arc itself is never cleaned up). I'm still not entirely sure why this is a problem because the pthreads runtime should register hooks for fork() to prevent this sort of deadlock, but perhaps that's only done on linux?
2014-04-07Fix some windows rpass testsAlex Crichton-26/+55
2014-04-06auto merge of #13315 : alexcrichton/rust/libc, r=alexcrichton,mebors-40/+42
Rebasing of #12526 with a very obscure bug fixed on windows.
2014-04-04Register new snapshotsAlex Crichton-2/+0
2014-04-04Fix fallout from std::libc separationCorey Richardson-40/+42
2014-04-03Bump version to 0.11-preBrian Anderson-1/+1
This also changes some of the download links in the documentation to 'nightly'.
2014-04-03auto merge of #13286 : alexcrichton/rust/release, r=brsonbors-1/+1
Merging the 0.10 release into the master branch.
2014-04-02Fix fallout of requiring uint indicesAlex Crichton-3/+3
2014-04-01auto merge of #13115 : huonw/rust/rand-errors, r=alexcrichtonbors-70/+5
move errno -> IoError converter into std, bubble up OSRng errors Also adds a general errno -> `~str` converter to `std::os`, and makes the failure messages for the things using `OSRng` (e.g. (transitively) the task-local RNG, meaning hashmap initialisation failures aren't such a black box).
2014-04-01std: migrate the errno -> IoError converter from libnative.Huon Wilson-70/+5
This also adds a direct `errno` -> `~str` converter, rather than only being possible to get a string for the very last error.
2014-03-31native: Switch field privacy as necessaryAlex Crichton-37/+39
2014-03-31Bump version to 0.10Alex Crichton-1/+1
2014-03-30Removed deprecated functions `map` and `flat_map` for vectors and slices.Marvin Löbel-2/+4
2014-03-28Convert most code to new inner attribute syntax.Brian Anderson-9/+9
Closes #2569
2014-03-28auto merge of #13158 : alexcrichton/rust/issue-13123, r=brsonbors-0/+18
Some unix platforms will send a SIGPIPE signal instead of returning EPIPE from a syscall by default. The native runtime doesn't install a SIGPIPE handler, causing the program to die immediately in this case. This brings the behavior in line with libgreen by ignoring SIGPIPE and propagating EPIPE upwards to the application in the form of an IoError. Closes #13123
2014-03-28native: Ignore SIGPIPE by defaultAlex Crichton-0/+18
Some unix platforms will send a SIGPIPE signal instead of returning EPIPE from a syscall by default. The native runtime doesn't install a SIGPIPE handler, causing the program to die immediately in this case. This brings the behavior in line with libgreen by ignoring SIGPIPE and propagating EPIPE upwards to the application in the form of an IoError. Closes #13123
2014-03-28native: Use WNOHANG before signalingAlex Crichton-23/+58
It turns out that on linux, and possibly other platforms, child processes will continue to accept signals until they have been *reaped*. This means that once the child has exited, it will succeed to receive signals until waitpid() has been invoked on it. This is unfortunate behavior, and differs from what is seen on OSX and windows. This commit changes the behavior of Process::signal() to be the same across platforms, and updates the documentation of Process::kill() to note that when signaling a foreign process it may accept signals until reaped. Implementation-wise, this invokes waitpid() with WNOHANG before each signal to the child to ensure that if the child has exited that we will reap it. Other possibilities include installing a SIGCHLD signal handler, but at this time I believe that that's too complicated. Closes #13124
2014-03-27doc: Update the tutorial about bounds for traitsAlex Crichton-8/+8
2014-03-27Fix fallout of removing default boundsAlex Crichton-52/+53
This is all purely fallout of getting the previous commit to compile.
2014-03-25libstd: Document the following modules:Patrick Walton-2/+3
* native::io * std::char * std::fmt * std::fmt::parse * std::io * std::io::extensions * std::io::net::ip * std::io::net::udp * std::io::net::unix * std::io::pipe * std::num * std::num::f32 * std::num::f64 * std::num::strconv * std::os
2014-03-24auto merge of #12900 : alexcrichton/rust/rewrite-sync, r=brsonbors-5/+5
* Remove clone-ability from all primitives. All shared state will now come from the usage of the primitives being shared, not the primitives being inherently shareable. This allows for fewer allocations for stack-allocated primitives. * Add `Mutex<T>` and `RWLock<T>` which are stack-allocated primitives for purely wrapping a piece of data * Remove `RWArc<T>` in favor of `Arc<RWLock<T>>` * Remove `MutexArc<T>` in favor of `Arc<Mutex<T>>` * Shuffle around where things are located * The `arc` module now only contains `Arc` * A new `lock` module contains `Mutex`, `RWLock`, and `Barrier` * A new `raw` module contains the primitive implementations of `Semaphore`, `Mutex`, and `RWLock` * The Deref/DerefMut trait was implemented where appropriate * `CowArc` was removed, the functionality is now part of `Arc` and is tagged with `#[experimental]`. * The crate now has #[deny(missing_doc)] * `Arc` now supports weak pointers This is not a large-scale rewrite of the functionality contained within the `sync` crate, but rather a shuffling of who does what an a thinner hierarchy of ownership to allow for better composability.
2014-03-24auto merge of #13080 : alexcrichton/rust/possible-osx-deadlock, r=brsonbors-107/+105
The OSX bots have been deadlocking recently in the rustdoc tests. I have only been able to rarely reproduce the deadlock on my local setup. When reproduced, it looks like the child process is spinning on the malloc mutex, which I presume is locked with no other threads to unlock it. I'm not convinced that this is what's happening, because OSX should protect against this with pthread_atfork by default. Regardless, running as little code as possible in the child after fork() is normally a good idea anyway, so this commit moves all allocation to the parent process to run before the child executes. After running 6k iterations of rustdoc tests, this deadlocked twice before, and after 20k iterations afterwards, it never deadlocked. I draw the conclusion that this is either sweeping the bug under the rug, or it did indeed fix the underlying problem.
2014-03-23std: Move NativeMutex from &mut self to &selfAlex Crichton-4/+4
The proper usage of shared types is now sharing through `&self` rather than `&mut self` because the mutable version will provide stronger guarantees (no aliasing on *any* thread).