Skip to content

Commit 79e538d

Browse files
luqmanabrson
authored andcommitted
uv: use just getpeername for both ipv4 and ipv6.
1 parent 0e2437b commit 79e538d

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/libstd/net_tcp.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
134134
stream_handle_ptr: stream_handle_ptr,
135135
connect_req: uv::ll::connect_t(),
136136
write_req: uv::ll::write_t(),
137+
ipv6: match input_ip {
138+
ip::Ipv4(_) => { false }
139+
ip::Ipv6(_) => { true }
140+
},
137141
iotask: iotask
138142
};
139143
let socket_data_ptr = ptr::addr_of(&(*socket_data));
@@ -475,6 +479,7 @@ pub fn accept(new_conn: TcpNewConnection)
475479
stream_handle_ptr : stream_handle_ptr,
476480
connect_req : uv::ll::connect_t(),
477481
write_req : uv::ll::write_t(),
482+
ipv6: (*server_data_ptr).ipv6,
478483
iotask : iotask
479484
};
480485
let client_socket_data_ptr = ptr::addr_of(&(*client_socket_data));
@@ -590,6 +595,10 @@ fn listen_common(host_ip: ip::IpAddr, port: uint, backlog: uint,
590595
kill_ch: kill_ch,
591596
on_connect_cb: move on_connect_cb,
592597
iotask: iotask,
598+
ipv6: match host_ip {
599+
ip::Ipv4(_) => { false }
600+
ip::Ipv6(_) => { true }
601+
},
593602
mut active: true
594603
};
595604
let server_data_ptr = ptr::addr_of(&server_data);
@@ -748,18 +757,17 @@ impl TcpSocket {
748757
}
749758
pub fn getpeername() -> ip::IpAddr {
750759
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)
760+
if self.socket_data.ipv6 {
761+
let addr = uv::ll::ip6_addr("", 0);
762+
uv::ll::tcp_getpeername6(self.socket_data.stream_handle_ptr,
763+
ptr::addr_of(&addr));
764+
ip::Ipv6(move addr)
765+
} else {
766+
let addr = uv::ll::ip4_addr("", 0);
767+
uv::ll::tcp_getpeername(self.socket_data.stream_handle_ptr,
768+
ptr::addr_of(&addr));
769+
ip::Ipv4(move addr)
770+
}
763771
}
764772
}
765773
}
@@ -1019,6 +1027,7 @@ type TcpListenFcData = {
10191027
kill_ch: comm::Chan<Option<TcpErrData>>,
10201028
on_connect_cb: fn~(*uv::ll::uv_tcp_t),
10211029
iotask: IoTask,
1030+
ipv6: bool,
10221031
mut active: bool
10231032
};
10241033

@@ -1217,6 +1226,7 @@ type TcpSocketData = {
12171226
stream_handle_ptr: *uv::ll::uv_tcp_t,
12181227
connect_req: uv::ll::uv_connect_t,
12191228
write_req: uv::ll::uv_write_t,
1229+
ipv6: bool,
12201230
iotask: IoTask
12211231
};
12221232

0 commit comments

Comments
 (0)