Merge pull request #1919 from mpajkowski/to_socket_addrs

THRIFT-4995 Use `ToSocketAddrs` for expressing network addresses
This commit is contained in:
Allen George 2019-12-14 09:52:36 -05:00 committed by GitHub
commit 6e443789e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
use std::net::{TcpListener, TcpStream};
use std::net::{TcpListener, TcpStream, ToSocketAddrs};
use std::sync::Arc;
use threadpool::ThreadPool;
@ -162,14 +162,13 @@ where
/// Listen for incoming connections on `listen_address`.
///
/// `listen_address` should be in the form `host:port`,
/// for example: `127.0.0.1:8080`.
/// `listen_address` should implement `ToSocketAddrs` trait.
///
/// Return `()` if successful.
///
/// Return `Err` when the server cannot bind to `listen_address` or there
/// is an unrecoverable error.
pub fn listen(&mut self, listen_address: &str) -> ::Result<()> {
pub fn listen<A: ToSocketAddrs>(&mut self, listen_address: A) -> ::Result<()> {
let listener = TcpListener::bind(listen_address)?;
for stream in listener.incoming() {
match stream {

View File

@ -18,7 +18,7 @@
use std::convert::From;
use std::io;
use std::io::{ErrorKind, Read, Write};
use std::net::{Shutdown, TcpStream};
use std::net::{Shutdown, TcpStream, ToSocketAddrs};
use super::{ReadHalf, TIoChannel, WriteHalf};
use {new_transport_error, TransportErrorKind};
@ -81,8 +81,8 @@ impl TTcpChannel {
}
}
/// Connect to `remote_address`, which should have the form `host:port`.
pub fn open(&mut self, remote_address: &str) -> ::Result<()> {
/// Connect to `remote_address`, which should implement `ToSocketAddrs` trait.
pub fn open<A: ToSocketAddrs>(&mut self, remote_address: A) -> ::Result<()> {
if self.stream.is_some() {
Err(new_transport_error(
TransportErrorKind::AlreadyOpen,