Skip to content

Commit b0fdad0

Browse files
committed
---
yaml --- r: 67302 b: refs/heads/master c: 61e741c h: refs/heads/master v: v3
1 parent a8fb18f commit b0fdad0

File tree

15 files changed

+242
-321
lines changed

15 files changed

+242
-321
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 7cc8f4bae0ed20aad04e03e5f3812fb7b8288f78
2+
refs/heads/master: 61e741cf714020107c6cda12793351fa5b8c7782
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/libstd/option.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ impl<T> Option<T> {
118118
}
119119
}
120120

121-
/// Returns true if the option equals `None`
121+
/// Returns true if the option equals `none`
122122
#[inline]
123123
pub fn is_none(&self) -> bool {
124124
match *self { None => true, Some(_) => false }
125125
}
126126

127-
/// Returns true if the option contains a `Some` value
127+
/// Returns true if the option contains some value
128128
#[inline]
129129
pub fn is_some(&self) -> bool { !self.is_none() }
130130

@@ -158,17 +158,6 @@ impl<T> Option<T> {
158158
}
159159
}
160160

161-
/// Update an optional value by optionally running its content by mut reference
162-
/// through a function that returns an option.
163-
#[inline]
164-
pub fn chain_mut_ref<'a, U>(&'a mut self, f: &fn(x: &'a mut T) -> Option<U>)
165-
-> Option<U> {
166-
match *self {
167-
Some(ref mut x) => f(x),
168-
None => None
169-
}
170-
}
171-
172161
/// Filters an optional value using given function.
173162
#[inline(always)]
174163
pub fn filtered(self, f: &fn(t: &T) -> bool) -> Option<T> {
@@ -178,19 +167,19 @@ impl<T> Option<T> {
178167
}
179168
}
180169

181-
/// Maps a `Some` value from one type to another by reference
170+
/// Maps a `some` value from one type to another by reference
182171
#[inline]
183172
pub fn map<'a, U>(&'a self, f: &fn(&'a T) -> U) -> Option<U> {
184173
match *self { Some(ref x) => Some(f(x)), None => None }
185174
}
186175

187-
/// Maps a `Some` value from one type to another by a mutable reference
176+
/// Maps a `some` value from one type to another by a mutable reference
188177
#[inline]
189178
pub fn map_mut<'a, U>(&'a mut self, f: &fn(&'a mut T) -> U) -> Option<U> {
190179
match *self { Some(ref mut x) => Some(f(x)), None => None }
191180
}
192181

193-
/// Maps a `Some` value from one type to another by a mutable reference,
182+
/// Maps a `some` value from one type to another by a mutable reference,
194183
/// or returns a default value.
195184
#[inline]
196185
pub fn map_mut_default<'a, U>(&'a mut self, def: U, f: &fn(&'a mut T) -> U) -> U {
@@ -271,7 +260,7 @@ impl<T> Option<T> {
271260
pub fn get_ref<'a>(&'a self) -> &'a T {
272261
match *self {
273262
Some(ref x) => x,
274-
None => fail!("option::get_ref None")
263+
None => fail!("option::get_ref none")
275264
}
276265
}
277266

@@ -293,7 +282,7 @@ impl<T> Option<T> {
293282
pub fn get_mut_ref<'a>(&'a mut self) -> &'a mut T {
294283
match *self {
295284
Some(ref mut x) => x,
296-
None => fail!("option::get_mut_ref None")
285+
None => fail!("option::get_mut_ref none")
297286
}
298287
}
299288

@@ -317,7 +306,7 @@ impl<T> Option<T> {
317306
*/
318307
match self {
319308
Some(x) => x,
320-
None => fail!("option::unwrap None")
309+
None => fail!("option::unwrap none")
321310
}
322311
}
323312

@@ -331,7 +320,7 @@ impl<T> Option<T> {
331320
*/
332321
#[inline]
333322
pub fn take_unwrap(&mut self) -> T {
334-
if self.is_none() { fail!("option::take_unwrap None") }
323+
if self.is_none() { fail!("option::take_unwrap none") }
335324
self.take().unwrap()
336325
}
337326

@@ -341,7 +330,7 @@ impl<T> Option<T> {
341330
*
342331
* # Failure
343332
*
344-
* Fails if the value equals `None`
333+
* Fails if the value equals `none`
345334
*/
346335
#[inline]
347336
pub fn expect(self, reason: &str) -> T {
@@ -369,7 +358,7 @@ impl<T> Option<T> {
369358
pub fn get(self) -> T {
370359
match self {
371360
Some(x) => return x,
372-
None => fail!("option::get None")
361+
None => fail!("option::get none")
373362
}
374363
}
375364

@@ -379,7 +368,7 @@ impl<T> Option<T> {
379368
match self { Some(x) => x, None => def }
380369
}
381370

382-
/// Applies a function zero or more times until the result is None.
371+
/// Applies a function zero or more times until the result is none.
383372
#[inline]
384373
pub fn while_some(self, blk: &fn(v: T) -> Option<T>) {
385374
let mut opt = self;

trunk/src/libstd/rt/io/net/tcp.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ use rt::io::net::ip::IpAddr;
1414
use rt::io::{Reader, Writer, Listener};
1515
use rt::io::{io_error, read_error, EndOfFile};
1616
use rt::rtio::{IoFactory, IoFactoryObject,
17-
RtioTcpListener, RtioTcpListenerObject,
18-
RtioTcpStream, RtioTcpStreamObject};
17+
RtioSocket, RtioTcpListener,
18+
RtioTcpListenerObject, RtioTcpStream,
19+
RtioTcpStreamObject};
1920
use rt::local::Local;
2021

2122
pub struct TcpStream(~RtioTcpStreamObject);
@@ -42,6 +43,28 @@ impl TcpStream {
4243
}
4344
}
4445
}
46+
47+
pub fn peer_name(&mut self) -> Option<IpAddr> {
48+
match (***self).peer_name() {
49+
Ok(pn) => Some(pn),
50+
Err(ioerr) => {
51+
rtdebug!("failed to get peer name: %?", ioerr);
52+
io_error::cond.raise(ioerr);
53+
None
54+
}
55+
}
56+
}
57+
58+
pub fn socket_name(&mut self) -> Option<IpAddr> {
59+
match (***self).socket_name() {
60+
Ok(sn) => Some(sn),
61+
Err(ioerr) => {
62+
rtdebug!("failed to get socket name: %?", ioerr);
63+
io_error::cond.raise(ioerr);
64+
None
65+
}
66+
}
67+
}
4568
}
4669

4770
impl Reader for TcpStream {
@@ -90,6 +113,17 @@ impl TcpListener {
90113
}
91114
}
92115
}
116+
117+
pub fn socket_name(&mut self) -> Option<IpAddr> {
118+
match (***self).socket_name() {
119+
Ok(sn) => Some(sn),
120+
Err(ioerr) => {
121+
rtdebug!("failed to get socket name: %?", ioerr);
122+
io_error::cond.raise(ioerr);
123+
None
124+
}
125+
}
126+
}
93127
}
94128

95129
impl Listener<TcpStream> for TcpListener {

trunk/src/libstd/rt/io/net/udp.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use result::{Ok, Err};
1313
use rt::io::net::ip::IpAddr;
1414
use rt::io::{Reader, Writer};
1515
use rt::io::{io_error, read_error, EndOfFile};
16-
use rt::rtio::{RtioUdpSocketObject, RtioUdpSocket, IoFactory, IoFactoryObject};
16+
use rt::rtio::{RtioSocket, RtioUdpSocketObject, RtioUdpSocket, IoFactory, IoFactoryObject};
1717
use rt::local::Local;
1818

1919
pub struct UdpSocket(~RtioUdpSocketObject);
@@ -53,6 +53,17 @@ impl UdpSocket {
5353
pub fn connect(self, other: IpAddr) -> UdpStream {
5454
UdpStream { socket: self, connectedTo: other }
5555
}
56+
57+
pub fn socket_name(&mut self) -> Option<IpAddr> {
58+
match (***self).socket_name() {
59+
Ok(sn) => Some(sn),
60+
Err(ioerr) => {
61+
rtdebug!("failed to get socket name: %?", ioerr);
62+
io_error::cond.raise(ioerr);
63+
None
64+
}
65+
}
66+
}
5667
}
5768

5869
pub struct UdpStream {

trunk/src/libstd/rt/rtio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ pub trait RtioTcpListener : RtioSocket {
5959
pub trait RtioTcpStream : RtioSocket {
6060
fn read(&mut self, buf: &mut [u8]) -> Result<uint, IoError>;
6161
fn write(&mut self, buf: &[u8]) -> Result<(), IoError>;
62-
fn peer_name(&mut self) -> IpAddr;
62+
fn peer_name(&mut self) -> Result<IpAddr, IoError>;
6363
fn control_congestion(&mut self);
6464
fn nodelay(&mut self);
6565
fn keepalive(&mut self, delay_in_seconds: uint);
6666
fn letdie(&mut self);
6767
}
6868

6969
pub trait RtioSocket {
70-
fn socket_name(&mut self) -> IpAddr;
70+
fn socket_name(&mut self) -> Result<IpAddr, IoError>;
7171
}
7272

7373
pub trait RtioUdpSocket : RtioSocket {

trunk/src/libstd/rt/uv/async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl AsyncWatcher {
3434

3535
extern fn async_cb(handle: *uvll::uv_async_t, status: c_int) {
3636
let mut watcher: AsyncWatcher = NativeHandle::from_native_handle(handle);
37-
let status = status_to_maybe_uv_error(watcher.native_handle(), status);
37+
let status = status_to_maybe_uv_error(watcher, status);
3838
let data = watcher.get_watcher_data();
3939
let cb = data.async_cb.get_ref();
4040
(*cb)(watcher, status);

trunk/src/libstd/rt/uv/idle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl IdleWatcher {
4343
let mut idle_watcher: IdleWatcher = NativeHandle::from_native_handle(handle);
4444
let data = idle_watcher.get_watcher_data();
4545
let cb: &IdleCallback = data.idle_cb.get_ref();
46-
let status = status_to_maybe_uv_error(handle, status);
46+
let status = status_to_maybe_uv_error(idle_watcher, status);
4747
(*cb)(idle_watcher, status);
4848
}
4949
}

trunk/src/libstd/rt/uv/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
282282
}
283283
284284
/// Given a uv handle, convert a callback status to a UvError
285-
// XXX: Follow the pattern below by parameterizing over T: Watcher, not T
286-
pub fn status_to_maybe_uv_error<T>(handle: *T, status: c_int) -> Option<UvError> {
285+
pub fn status_to_maybe_uv_error<T, U: Watcher + NativeHandle<*T>>(handle: U,
286+
status: c_int) -> Option<UvError> {
287287
if status != -1 {
288288
None
289289
} else {
290290
unsafe {
291291
rtdebug!("handle: %x", handle as uint);
292-
let loop_ = uvll::get_loop_for_uv_handle(handle);
292+
let loop_ = uvll::get_loop_for_uv_handle(handle.native_handle());
293293
rtdebug!("loop: %x", loop_ as uint);
294294
let err = uvll::last_error(loop_);
295295
Some(UvError(err))

trunk/src/libstd/rt/uv/net.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use str;
2222
use from_str::{FromStr};
2323
use num;
2424

25-
enum UvIpAddr {
25+
pub enum UvIpAddr {
2626
UvIpv4(*sockaddr_in),
2727
UvIpv6(*sockaddr_in6),
2828
}
@@ -32,8 +32,8 @@ fn sockaddr_to_UvIpAddr(addr: *uvll::sockaddr) -> UvIpAddr {
3232
assert!((is_ip4_addr(addr) || is_ip6_addr(addr)));
3333
assert!(!(is_ip4_addr(addr) && is_ip6_addr(addr)));
3434
match addr {
35-
_ if is_ip4_addr(addr) => UvIpv4(as_sockaddr_in(addr)),
36-
_ if is_ip6_addr(addr) => UvIpv6(as_sockaddr_in6(addr)),
35+
_ if is_ip4_addr(addr) => UvIpv4(addr as *uvll::sockaddr_in),
36+
_ if is_ip6_addr(addr) => UvIpv6(addr as *uvll::sockaddr_in6),
3737
_ => fail!(),
3838
}
3939
}
@@ -133,7 +133,7 @@ fn uv_ip_as_ip<T>(addr: UvIpAddr, f: &fn(IpAddr) -> T) -> T {
133133
f(ip)
134134
}
135135

136-
fn uv_ip_to_ip(addr: UvIpAddr) -> IpAddr {
136+
pub fn uv_ip_to_ip(addr: UvIpAddr) -> IpAddr {
137137
use util;
138138
uv_ip_as_ip(addr, util::id)
139139
}
@@ -154,7 +154,7 @@ fn test_ip6_conversion() {
154154
assert_eq!(ip6, ip_as_uv_ip(ip6, uv_ip_to_ip));
155155
}
156156

157-
// uv_stream t is the parent class of uv_tcp_t, uv_pipe_t, uv_tty_t
157+
// uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t, uv_tty_t
158158
// and uv_file_t
159159
pub struct StreamWatcher(*uvll::uv_stream_t);
160160
impl Watcher for StreamWatcher { }
@@ -180,7 +180,7 @@ impl StreamWatcher {
180180
rtdebug!("buf len: %d", buf.len as int);
181181
let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(stream);
182182
let cb = stream_watcher.get_watcher_data().read_cb.get_ref();
183-
let status = status_to_maybe_uv_error(stream, nread as c_int);
183+
let status = status_to_maybe_uv_error(stream_watcher, nread as c_int);
184184
(*cb)(stream_watcher, nread as int, buf, status);
185185
}
186186
}
@@ -210,7 +210,7 @@ impl StreamWatcher {
210210
let mut stream_watcher = write_request.stream();
211211
write_request.delete();
212212
let cb = stream_watcher.get_watcher_data().write_cb.take_unwrap();
213-
let status = status_to_maybe_uv_error(stream_watcher.native_handle(), status);
213+
let status = status_to_maybe_uv_error(stream_watcher, status);
214214
cb(stream_watcher, status);
215215
}
216216
}
@@ -302,7 +302,7 @@ impl TcpWatcher {
302302
let mut stream_watcher = connect_request.stream();
303303
connect_request.delete();
304304
let cb = stream_watcher.get_watcher_data().connect_cb.take_unwrap();
305-
let status = status_to_maybe_uv_error(stream_watcher.native_handle(), status);
305+
let status = status_to_maybe_uv_error(stream_watcher, status);
306306
cb(stream_watcher, status);
307307
}
308308
}
@@ -325,7 +325,7 @@ impl TcpWatcher {
325325
rtdebug!("connection_cb");
326326
let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(handle);
327327
let cb = stream_watcher.get_watcher_data().connect_cb.get_ref();
328-
let status = status_to_maybe_uv_error(handle, status);
328+
let status = status_to_maybe_uv_error(stream_watcher, status);
329329
(*cb)(stream_watcher, status);
330330
}
331331
}
@@ -402,7 +402,7 @@ impl UdpWatcher {
402402
rtdebug!("buf len: %d", buf.len as int);
403403
let mut udp_watcher: UdpWatcher = NativeHandle::from_native_handle(handle);
404404
let cb = udp_watcher.get_watcher_data().udp_recv_cb.get_ref();
405-
let status = status_to_maybe_uv_error(handle, nread as c_int);
405+
let status = status_to_maybe_uv_error(udp_watcher, nread as c_int);
406406
let addr = uv_ip_to_ip(sockaddr_to_UvIpAddr(addr));
407407
(*cb)(udp_watcher, nread as int, buf, addr, flags as uint, status);
408408
}
@@ -437,7 +437,7 @@ impl UdpWatcher {
437437
let mut udp_watcher = send_request.handle();
438438
send_request.delete();
439439
let cb = udp_watcher.get_watcher_data().udp_send_cb.take_unwrap();
440-
let status = status_to_maybe_uv_error(udp_watcher.native_handle(), status);
440+
let status = status_to_maybe_uv_error(udp_watcher, status);
441441
cb(udp_watcher, status);
442442
}
443443
}

trunk/src/libstd/rt/uv/timer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl TimerWatcher {
4343
let mut watcher: TimerWatcher = NativeHandle::from_native_handle(handle);
4444
let data = watcher.get_watcher_data();
4545
let cb = data.timer_cb.get_ref();
46-
let status = status_to_maybe_uv_error(handle, status);
46+
let status = status_to_maybe_uv_error(watcher, status);
4747
(*cb)(watcher, status);
4848
}
4949
}

0 commit comments

Comments
 (0)