Skip to content

Commit d9566e1

Browse files
committed
auto merge of #13919 : thomaslee/rust/thomaslee_proposed_tcpstream_open, r=alexcrichton
Been meaning to try my hand at something like this for a while, and noticed something similar mentioned as part of #13537. The suggestion on the original ticket is to use `TcpStream::open(&str)` to pass in a host + port string, but seems a little cleaner to pass in host and port separately -- so a signature like `TcpStream::open(&str, u16)`. Also means we can use std::io::net::addrinfo directly instead of using e.g. liburl to parse the host+port pair from a string. One outstanding issue in this PR that I'm not entirely sure how to address: in open_timeout, the timeout_ms will apply for every A record we find associated with a hostname -- probably not the intended behavior, but I didn't want to waste my time on elaborate alternatives until the general idea was a-OKed. :) Anyway, perhaps there are other reasons for us to prefer the original proposed syntax, but thought I'd get some thoughts on this. Maybe there are some solid reasons to prefer using liburl to do this stuff.
2 parents 20356e4 + 48b0296 commit d9566e1

File tree

5 files changed

+275
-107
lines changed

5 files changed

+275
-107
lines changed

src/compiletest/runtest.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use util;
1919

2020
use std::io::File;
2121
use std::io::fs;
22-
use std::io::net::ip::{Ipv4Addr, SocketAddr};
2322
use std::io::net::tcp;
2423
use std::io::process::ProcessExit;
2524
use std::io::process;
@@ -316,10 +315,7 @@ fn run_debuginfo_gdb_test(config: &config, props: &TestProps, testfile: &Path) {
316315
//waiting 1 second for gdbserver start
317316
timer::sleep(1000);
318317
let result = task::try(proc() {
319-
tcp::TcpStream::connect(SocketAddr {
320-
ip: Ipv4Addr(127, 0, 0, 1),
321-
port: 5039,
322-
}).unwrap();
318+
tcp::TcpStream::connect("127.0.0.1", 5039).unwrap();
323319
});
324320
if result.is_err() {
325321
continue;

src/libstd/io/mod.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,9 @@ Some examples of obvious things you might want to do
8383
8484
```rust,should_fail
8585
# #![allow(unused_must_use)]
86-
use std::io::net::ip::SocketAddr;
8786
use std::io::net::tcp::TcpStream;
8887
89-
let addr = from_str::<SocketAddr>("127.0.0.1:8080").unwrap();
90-
let mut socket = TcpStream::connect(addr).unwrap();
88+
let mut socket = TcpStream::connect("127.0.0.1", 8080).unwrap();
9189
socket.write(bytes!("GET / HTTP/1.0\n\n"));
9290
let response = socket.read_to_end();
9391
```
@@ -99,11 +97,9 @@ Some examples of obvious things you might want to do
9997
# fn foo() {
10098
# #![allow(dead_code)]
10199
use std::io::{TcpListener, TcpStream};
102-
use std::io::net::ip::{Ipv4Addr, SocketAddr};
103100
use std::io::{Acceptor, Listener};
104101
105-
let addr = SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 80 };
106-
let listener = TcpListener::bind(addr);
102+
let listener = TcpListener::bind("127.0.0.1", 80);
107103
108104
// bind the listener to the specified address
109105
let mut acceptor = listener.listen();

0 commit comments

Comments
 (0)