mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-06 18:35:19 +00:00
Merge pull request #1919 from mpajkowski/to_socket_addrs
THRIFT-4995 Use `ToSocketAddrs` for expressing network addresses
This commit is contained in:
commit
6e443789e9
@ -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 {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user