Skip to content

Commit a1fd8be

Browse files
authored
Merge pull request #232 from thombles/tk-local-addr-async
Provide an implementation of local_addr for Async servers
2 parents cbe7112 + 327544a commit a1fd8be

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/server/async.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use futures;
44
use futures::{Future, Stream};
55
use server::upgrade::async::{IntoWs, Upgrade};
66
use server::InvalidConnection;
7-
use server::{NoTlsAcceptor, WsServer};
7+
use server::{NoTlsAcceptor, OptionalTlsAcceptor, WsServer};
88
use std;
99
use std::io;
1010
use std::net::SocketAddr;
@@ -29,6 +29,16 @@ pub type Server<S> = WsServer<S, TcpListener>;
2929
pub type Incoming<S> =
3030
Box<Stream<Item = (Upgrade<S>, SocketAddr), Error = InvalidConnection<S, BytesMut>> + Send>;
3131

32+
impl<S> WsServer<S, TcpListener>
33+
where
34+
S: OptionalTlsAcceptor,
35+
{
36+
/// Get the socket address of this server
37+
pub fn local_addr(&self) -> io::Result<SocketAddr> {
38+
self.listener.local_addr()
39+
}
40+
}
41+
3242
/// Asynchronous methods for creating an async server and accepting incoming connections.
3343
impl WsServer<NoTlsAcceptor, TcpListener> {
3444
/// Bind a websocket server to an address.

0 commit comments

Comments
 (0)