You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2018/05/02 01:38:30 UTC

[30/31] mesos git commit: Fixed `mesos-tcp-connect` to use `net::socket`.

Fixed `mesos-tcp-connect` to use `net::socket`.

Use the stout wrapper instead of `::socket` so we have built-in error
checking (and don't have to worry about types).

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


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

Branch: refs/heads/master
Commit: 2dcbdeb0d89f425338717b156c48f839e89758e3
Parents: d489588
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Thu Apr 26 10:06:26 2018 -0700
Committer: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Committed: Tue May 1 18:36:04 2018 -0700

----------------------------------------------------------------------
 src/checks/tcp_connect.cpp | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/2dcbdeb0/src/checks/tcp_connect.cpp
----------------------------------------------------------------------
diff --git a/src/checks/tcp_connect.cpp b/src/checks/tcp_connect.cpp
index f5df732..2e9262e 100644
--- a/src/checks/tcp_connect.cpp
+++ b/src/checks/tcp_connect.cpp
@@ -37,6 +37,7 @@
 #include <stout/option.hpp>
 #include <stout/path.hpp>
 
+#include <stout/os/close.hpp>
 #include <stout/os/socket.hpp>
 
 using std::cerr;
@@ -87,9 +88,9 @@ int testTCPConnect(const string& ip, int port)
   }
 
   // Create a TCP socket.
-  int_fd socket = ::socket(parse->family(), SOCK_STREAM, 0);
-  if (socket < 0) {
-    cerr << "Failed to create socket: " << strerror(errno) << endl;
+  Try<int_fd> socket = net::socket(parse->family(), SOCK_STREAM, 0);
+  if (socket.isError()) {
+    cerr << "Failed to create socket: " << socket.error() << endl;
     return EXIT_FAILURE;
   }
 
@@ -97,19 +98,19 @@ int testTCPConnect(const string& ip, int port)
   // zero is returned, indicating the remote port is open.
   cout << "Connecting to " << ip << ":" << port << endl;
   Try<Nothing, SocketError> connect = process::network::connect(
-      socket,
+      socket.get(),
       process::network::inet::Address(parse.get(), port));
 
   if (connect.isError()) {
     cerr << connect.error().message << endl;
-    close(socket);
+    os::close(socket.get());
     return EXIT_FAILURE;
   }
 
   cout << "Successfully established TCP connection" << endl;
 
-  shutdown(socket, SHUT_RDWR);
-  close(socket);
+  shutdown(socket.get(), SHUT_RDWR);
+  os::close(socket.get());
 
   return EXIT_SUCCESS;
 }