mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bmah...@apache.org
Subject [1/2] mesos git commit: Added the ability to get the peer address of a connected or accepted Socket.
Date Mon, 15 Jun 2015 22:40:00 GMT
Repository: mesos
Updated Branches:
  refs/heads/master cdc60912f -> c0536dbd9


Added the ability to get the peer address of a connected or accepted Socket.

Review: https://reviews.apache.org/r/35403


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/77e28559
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/77e28559
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/77e28559

Branch: refs/heads/master
Commit: 77e2855980114001cf6646642b58d6466ca52574
Parents: cdc6091
Author: Benjamin Mahler <benjamin.mahler@gmail.com>
Authored: Fri Jun 12 15:37:16 2015 -0700
Committer: Benjamin Mahler <benjamin.mahler@gmail.com>
Committed: Mon Jun 15 15:36:06 2015 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/network.hpp | 20 ++++++++++++++++++--
 3rdparty/libprocess/include/process/socket.hpp  |  6 ++++++
 3rdparty/libprocess/src/socket.cpp              |  8 ++++++++
 3 files changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/77e28559/3rdparty/libprocess/include/process/network.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/network.hpp b/3rdparty/libprocess/include/process/network.hpp
index 6d949c0..f3f9955 100644
--- a/3rdparty/libprocess/include/process/network.hpp
+++ b/3rdparty/libprocess/include/process/network.hpp
@@ -78,8 +78,8 @@ inline Try<int> connect(int s, const Address& address)
 
 
 // Returns the Address with the assigned ip and assigned port.
-// Returns an error if the getsockname system call fails or the family
-// type is not supported.
+// Returns an error if the getsockname system call fails or the
+// family type is not supported.
 inline Try<Address> address(int s)
 {
   struct sockaddr_storage storage;
@@ -92,6 +92,22 @@ inline Try<Address> address(int s)
   return Address::create(storage);
 }
 
+
+// Returns the peer's Address for the accepted or connected socket.
+// Returns an error if the getpeername system call fails or the
+// family type is not supported.
+inline Try<Address> peer(int s)
+{
+  struct sockaddr_storage storage;
+  socklen_t storagelen = sizeof(storage);
+
+  if(::getpeername(s, (struct sockaddr*) &storage, &storagelen) < 0) {
+    return ErrnoError("Failed to getpeername");
+  }
+
+  return Address::create(storage);
+}
+
 } // namespace network {
 } // namespace process {
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/77e28559/3rdparty/libprocess/include/process/socket.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/socket.hpp b/3rdparty/libprocess/include/process/socket.hpp
index 2cf3c10..96dd6f7 100644
--- a/3rdparty/libprocess/include/process/socket.hpp
+++ b/3rdparty/libprocess/include/process/socket.hpp
@@ -62,6 +62,7 @@ public:
 
     // Interface functions implemented by this base class.
     Try<Address> address() const;
+    Try<Address> peer() const;
     Try<Address> bind(const Address& address);
 
     // Socket::Impl interface.
@@ -155,6 +156,11 @@ public:
     return impl->address();
   }
 
+  Try<Address> peer() const
+  {
+    return impl->peer();
+  }
+
   int get() const
   {
     return impl->get();

http://git-wip-us.apache.org/repos/asf/mesos/blob/77e28559/3rdparty/libprocess/src/socket.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/socket.cpp b/3rdparty/libprocess/src/socket.cpp
index b2a27b5..143b6ad 100644
--- a/3rdparty/libprocess/src/socket.cpp
+++ b/3rdparty/libprocess/src/socket.cpp
@@ -97,6 +97,14 @@ Try<Address> Socket::Impl::address() const
 }
 
 
+Try<Address> Socket::Impl::peer() const
+{
+  // TODO(benh): Cache this result so that we don't have to make
+  // unnecessary system calls each time.
+  return network::peer(get());
+}
+
+
 Try<Address> Socket::Impl::bind(const Address& address)
 {
   Try<int> bind = network::bind(get(), address);


Mime
View raw message