From 3442c11dabbc3f43e2f6cb4c66dd1dd55c45bb1c Mon Sep 17 00:00:00 2001 From: JiaJie Ye Date: Wed, 15 Mar 2017 23:03:20 -0700 Subject: [PATCH] Add getPeerAddress/getLocalAddress folly::SocketAddress() function Summary: Add getPeerAddress/getLocalAddress folly::SocketAddress() function Reviewed By: yfeldblum Differential Revision: D4706693 fbshipit-source-id: 534e862f4168bc9e7bb02e41eac8e2ced6a02c59 --- folly/io/async/AsyncTransport.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/folly/io/async/AsyncTransport.h b/folly/io/async/AsyncTransport.h index 8af868f7..6505c287 100644 --- a/folly/io/async/AsyncTransport.h +++ b/folly/io/async/AsyncTransport.h @@ -322,6 +322,20 @@ class AsyncTransport : public DelayedDestruction, public AsyncSocketBase { */ virtual void getLocalAddress(SocketAddress* address) const = 0; + /** + * Get the address of the remote endpoint to which this transport is + * connected. + * + * This function may throw AsyncSocketException on error. + * + * @return Return the local address + */ + SocketAddress getLocalAddress() const { + SocketAddress addr; + getLocalAddress(&addr); + return addr; + } + virtual void getAddress(SocketAddress* address) const { getLocalAddress(address); } @@ -337,6 +351,20 @@ class AsyncTransport : public DelayedDestruction, public AsyncSocketBase { */ virtual void getPeerAddress(SocketAddress* address) const = 0; + /** + * Get the address of the remote endpoint to which this transport is + * connected. + * + * This function may throw AsyncSocketException on error. + * + * @return Return the remote endpoint's address + */ + SocketAddress getPeerAddress() const { + SocketAddress addr; + getPeerAddress(&addr); + return addr; + } + /** * Get the certificate used to authenticate the peer. */ -- 2.34.1