Add getPeerAddress/getLocalAddress folly::SocketAddress() function
authorJiaJie Ye <geniusye@fb.com>
Thu, 16 Mar 2017 06:03:20 +0000 (23:03 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 16 Mar 2017 06:05:21 +0000 (23:05 -0700)
Summary: Add getPeerAddress/getLocalAddress folly::SocketAddress() function

Reviewed By: yfeldblum

Differential Revision: D4706693

fbshipit-source-id: 534e862f4168bc9e7bb02e41eac8e2ced6a02c59

folly/io/async/AsyncTransport.h

index 8af868f7b79e586bedf18a3d706e67eac2658363..6505c287fcaa3faa277d8274f4d05ba1c057914b 100644 (file)
@@ -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.
    */