Skip to content

Commit 7df8d5c

Browse files
luqmanabrson
authored andcommitted
---
yaml --- r: 37303 b: refs/heads/try c: 0e2437b h: refs/heads/master i: 37301: 4b2ce19 37299: eb20686 37295: b241eb8 v: v3
1 parent f45e929 commit 7df8d5c

File tree

5 files changed

+82
-3
lines changed

5 files changed

+82
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 09bb07bed9166105ea961a42b5fff7739ae0d2e9
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
5-
refs/heads/try: 15777de957642ebace789bec747b4269ca9883b7
5+
refs/heads/try: 0e2437bf5d4a1f863888d4b0b5995a695f966e73
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/src/libstd/net_ip.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ use addrinfo = uv::ll::addrinfo;
1010
use uv_getaddrinfo_t = uv::ll::uv_getaddrinfo_t;
1111
use uv_ip4_addr = uv::ll::ip4_addr;
1212
use uv_ip4_name = uv::ll::ip4_name;
13+
use uv_ip4_port = uv::ll::ip4_port;
1314
use uv_ip6_addr = uv::ll::ip6_addr;
1415
use uv_ip6_name = uv::ll::ip6_name;
16+
use uv_ip6_port = uv::ll::ip6_port;
1517
use uv_getaddrinfo = uv::ll::getaddrinfo;
1618
use uv_freeaddrinfo = uv::ll::freeaddrinfo;
1719
use create_uv_getaddrinfo_t = uv::ll::getaddrinfo_t;
@@ -33,11 +35,11 @@ type ParseAddrErr = {
3335
};
3436

3537
/**
36-
* Convert a `ip_addr` to a str
38+
* Convert a `IpAddr` to a str
3739
*
3840
* # Arguments
3941
*
40-
* * ip - a `std::net::ip::ip_addr`
42+
* * ip - a `std::net::ip::IpAddr`
4143
*/
4244
pub fn format_addr(ip: &IpAddr) -> ~str {
4345
match *ip {
@@ -58,6 +60,23 @@ pub fn format_addr(ip: &IpAddr) -> ~str {
5860
}
5961
}
6062

63+
/**
64+
* Get the associated port
65+
*
66+
* # Arguments
67+
* * ip - a `std::net::ip::IpAddr`
68+
*/
69+
pub fn get_port(ip: &IpAddr) -> uint {
70+
match *ip {
71+
Ipv4(ref addr) => unsafe {
72+
uv_ip4_port(addr)
73+
},
74+
Ipv6(ref addr) => unsafe {
75+
uv_ip6_port(addr)
76+
}
77+
}
78+
}
79+
6180
/// Represents errors returned from `net::ip::get_addr()`
6281
enum IpGetAddrErr {
6382
GetAddrUnknownError

branches/try/src/libstd/net_tcp.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,22 @@ impl TcpSocket {
746746
-> future::Future<result::Result<(), TcpErrData>> {
747747
write_future(&self, raw_write_data)
748748
}
749+
pub fn getpeername() -> ip::IpAddr {
750+
unsafe {
751+
let addr = uv::ll::ip4_addr("", 0);
752+
uv::ll::tcp_getpeername(self.socket_data.stream_handle_ptr,
753+
ptr::addr_of(&addr));
754+
ip::Ipv4(move addr)
755+
}
756+
}
757+
pub fn getpeername6() -> ip::IpAddr {
758+
unsafe {
759+
let addr = uv::ll::ip6_addr("", 0);
760+
uv::ll::tcp_getpeername6(self.socket_data.stream_handle_ptr,
761+
ptr::addr_of(&addr));
762+
ip::Ipv6(move addr)
763+
}
764+
}
749765
}
750766

751767
/// Implementation of `io::reader` trait for a buffered `net::tcp::tcp_socket`

branches/try/src/libstd/uv_ll.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@ extern mod rustrt {
590590
-> libc::c_int;
591591
fn rust_uv_ip6_name(src: *sockaddr_in6, dst: *u8, size: libc::size_t)
592592
-> libc::c_int;
593+
fn rust_uv_ip4_port(src: *sockaddr_in) -> libc::c_uint;
594+
fn rust_uv_ip6_port(src: *sockaddr_in6) -> libc::c_uint;
593595
// FIXME ref #2064
594596
fn rust_uv_tcp_connect(connect_ptr: *uv_connect_t,
595597
tcp_handle_ptr: *uv_tcp_t,
@@ -606,6 +608,10 @@ extern mod rustrt {
606608
// FIXME ref #2064
607609
fn rust_uv_tcp_bind6(tcp_server: *uv_tcp_t,
608610
++addr: *sockaddr_in6) -> libc::c_int;
611+
fn rust_uv_tcp_getpeername(tcp_handle_ptr: *uv_tcp_t,
612+
++name: *sockaddr_in) -> libc::c_int;
613+
fn rust_uv_tcp_getpeername6(tcp_handle_ptr: *uv_tcp_t,
614+
++name: *sockaddr_in6) ->libc::c_int;
609615
fn rust_uv_listen(stream: *libc::c_void, backlog: libc::c_int,
610616
cb: *u8) -> libc::c_int;
611617
fn rust_uv_accept(server: *libc::c_void, client: *libc::c_void)
@@ -736,6 +742,16 @@ pub unsafe fn tcp_bind6(tcp_server_ptr: *uv_tcp_t,
736742
addr_ptr);
737743
}
738744

745+
pub unsafe fn tcp_getpeername(tcp_handle_ptr: *uv_tcp_t,
746+
name: *sockaddr_in) -> libc::c_int {
747+
return rustrt::rust_uv_tcp_getpeername(tcp_handle_ptr, name);
748+
}
749+
750+
pub unsafe fn tcp_getpeername6(tcp_handle_ptr: *uv_tcp_t,
751+
name: *sockaddr_in6) ->libc::c_int {
752+
return rustrt::rust_uv_tcp_getpeername6(tcp_handle_ptr, name);
753+
}
754+
739755
pub unsafe fn listen<T>(stream: *T, backlog: libc::c_int,
740756
cb: *u8) -> libc::c_int {
741757
return rustrt::rust_uv_listen(stream as *libc::c_void, backlog, cb);
@@ -857,6 +873,12 @@ pub unsafe fn ip6_name(src: &sockaddr_in6) -> ~str {
857873
}
858874
}
859875
}
876+
pub unsafe fn ip4_port(src: &sockaddr_in) -> uint {
877+
rustrt::rust_uv_ip4_port(to_unsafe_ptr(src)) as uint
878+
}
879+
pub unsafe fn ip6_port(src: &sockaddr_in6) -> uint {
880+
rustrt::rust_uv_ip6_port(to_unsafe_ptr(src)) as uint
881+
}
860882

861883
pub unsafe fn timer_init(loop_ptr: *libc::c_void,
862884
timer_ptr: *uv_timer_t) -> libc::c_int {

branches/try/src/rt/rust_uv.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,20 @@ rust_uv_tcp_bind6
269269
return uv_tcp_bind6(tcp_server, addr);
270270
}
271271

272+
extern "C" int
273+
rust_uv_tcp_getpeername
274+
(uv_tcp_t* handle, sockaddr_in* name) {
275+
int namelen = sizeof(sockaddr_in);
276+
return uv_tcp_getpeername(handle, (sockaddr*)name, &namelen);
277+
}
278+
279+
extern "C" int
280+
rust_uv_tcp_getpeername6
281+
(uv_tcp_t* handle, sockaddr_in6* name) {
282+
int namelen = sizeof(sockaddr_in6);
283+
return uv_tcp_getpeername(handle, (sockaddr*)name, &namelen);
284+
}
285+
272286
extern "C" int
273287
rust_uv_listen(uv_stream_t* stream, int backlog,
274288
uv_connection_cb cb) {
@@ -480,6 +494,14 @@ rust_uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size) {
480494
int result = uv_ip6_name(src, dst, size);
481495
return result;
482496
}
497+
extern "C" unsigned int
498+
rust_uv_ip4_port(struct sockaddr_in* src) {
499+
return ntohs(src->sin_port);
500+
}
501+
extern "C" unsigned int
502+
rust_uv_ip6_port(struct sockaddr_in6* src) {
503+
return ntohs(src->sin6_port);
504+
}
483505

484506
extern "C" uintptr_t*
485507
rust_uv_get_kernel_global_chan_ptr() {

0 commit comments

Comments
 (0)