You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2015/06/16 00:40:00 UTC
[1/2] mesos git commit: Added the ability to get the peer address of
a connected or accepted Socket.
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 <be...@gmail.com>
Authored: Fri Jun 12 15:37:16 2015 -0700
Committer: Benjamin Mahler <be...@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);
[2/2] mesos git commit: Fixed http::Request::client to be set
correctly.
Posted by bm...@apache.org.
Fixed http::Request::client to be set correctly.
Review: https://reviews.apache.org/r/35404
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c0536dbd
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c0536dbd
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c0536dbd
Branch: refs/heads/master
Commit: c0536dbd9c1b4cf2d66af531b81567192e6af460
Parents: 77e2855
Author: Benjamin Mahler <be...@gmail.com>
Authored: Fri Jun 12 15:38:35 2015 -0700
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Mon Jun 15 15:36:08 2015 -0700
----------------------------------------------------------------------
3rdparty/libprocess/src/process.cpp | 33 +++++++++++++++--------
3rdparty/libprocess/src/tests/http_tests.cpp | 4 +--
2 files changed, 24 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/c0536dbd/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index f919b99..a67a3af 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -570,22 +570,33 @@ void decode_recv(
// Decode as much of the data as possible into HTTP requests.
const deque<Request*> requests = decoder->decode(data, length.get());
+ if (requests.empty() && decoder->failed()) {
+ VLOG(1) << "Decoder error while receiving";
+ socket_manager->close(*socket);
+ delete[] data;
+ delete decoder;
+ delete socket;
+ return;
+ }
+
if (!requests.empty()) {
+ // Get the peer address to augment the requests.
+ Try<Address> address = socket->peer();
+
+ if (address.isError()) {
+ VLOG(1) << "Failed to get peer address while receiving: "
+ << address.error();
+ socket_manager->close(*socket);
+ delete[] data;
+ delete decoder;
+ delete socket;
+ return;
+ }
+
foreach (Request* request, requests) {
- // Augment each Request with the client's address. This should
- // never fail since there remains a reference to this Socket!
- Try<Address> address = socket->address();
- CHECK_SOME(address);
request->client = address.get();
process_manager->handle(decoder->socket(), request);
}
- } else if (requests.empty() && decoder->failed()) {
- VLOG(1) << "Decoder error while receiving";
- socket_manager->close(*socket);
- delete[] data;
- delete decoder;
- delete socket;
- return;
}
socket->recv(data, size)
http://git-wip-us.apache.org/repos/asf/mesos/blob/c0536dbd/3rdparty/libprocess/src/tests/http_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/http_tests.cpp b/3rdparty/libprocess/src/tests/http_tests.cpp
index 8444b9c..86b2c7d 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -369,7 +369,7 @@ TEST(HTTP, PathParse)
http::Response validateGetWithoutQuery(const http::Request& request)
{
- EXPECT_NE(network::Address(), request.client);
+ EXPECT_NE(process::address(), request.client);
EXPECT_EQ("GET", request.method);
EXPECT_THAT(request.path, EndsWith("get"));
EXPECT_EQ("", request.body);
@@ -382,7 +382,7 @@ http::Response validateGetWithoutQuery(const http::Request& request)
http::Response validateGetWithQuery(const http::Request& request)
{
- EXPECT_NE(network::Address(), request.client);
+ EXPECT_NE(process::address(), request.client);
EXPECT_EQ("GET", request.method);
EXPECT_THAT(request.path, EndsWith("get"));
EXPECT_EQ("", request.body);