You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2016/04/05 20:37:06 UTC
[1/5] mesos git commit: Removed unnecessary constructors in `Try`.
Repository: mesos
Updated Branches:
refs/heads/master d7c80c02d -> b499a1be2
Removed unnecessary constructors in `Try`.
Correctly constrained the templated constructor.
Review: https://reviews.apache.org/r/45310/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9cd3b1c9
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9cd3b1c9
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9cd3b1c9
Branch: refs/heads/master
Commit: 9cd3b1c938e3e0d64ce6a25e38d2b38d54d4c29f
Parents: d7c80c0
Author: Michael Park <mp...@apache.org>
Authored: Tue Apr 5 11:08:28 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Tue Apr 5 11:08:28 2016 -0700
----------------------------------------------------------------------
.../libprocess/3rdparty/stout/include/stout/try.hpp | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/9cd3b1c9/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
index c444c01..2625cd1 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
@@ -47,21 +47,15 @@ public:
Try(const T& t)
: data(Some(t)) {}
- template <typename U>
- Try(const U& u)
- : data(Some(u)) {}
+ template <
+ typename U,
+ typename = typename std::enable_if<
+ std::is_constructible<T, const U&>::value>::type>
+ Try(const U& u) : data(Some(u)) {}
Try(const Error& error)
: message(error.message) {}
- Try(const ErrnoError& error)
- : message(error.message) {}
-
-#ifdef __WINDOWS__
- Try(const WindowsError& error)
- : message(error.message) {}
-#endif // __WINDOWS__
-
// TODO(bmahler): Add move constructor.
// We don't need to implement these because we are leveraging
[4/5] mesos git commit: Introduced `WindowsSocketError` and
refactored out `WindowsErrorBase`.
Posted by mp...@apache.org.
Introduced `WindowsSocketError` and refactored out `WindowsErrorBase`.
Review: https://reviews.apache.org/r/45313/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/390c0545
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/390c0545
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/390c0545
Branch: refs/heads/master
Commit: 390c0545930fbb731bda0f02920d7aa5c6e4e4c1
Parents: 88b544d
Author: Michael Park <mp...@apache.org>
Authored: Tue Apr 5 11:08:40 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Tue Apr 5 11:08:40 2016 -0700
----------------------------------------------------------------------
.../stout/include/stout/windows/error.hpp | 33 ++++++++++++++------
1 file changed, 24 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/390c0545/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp
index bf21fac..d634491 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp
@@ -24,23 +24,20 @@
// A useful type that can be used to represent a Try that has failed. This is a
// lot like `ErrnoError`, except instead of wrapping an error coming from the C
// standard libraries, it wraps an error coming from the Windows APIs.
-class WindowsError : public Error
+class WindowsErrorBase : public Error
{
public:
- WindowsError()
- : Error(get_last_error_as_string()), code(::GetLastError()) {}
+ WindowsErrorBase(DWORD _code)
+ : Error(get_last_error_as_string(_code)), code(_code) {}
- WindowsError(const std::string& message)
- : Error(message + ": " + get_last_error_as_string()),
- code(::GetLastError()) {}
+ WindowsErrorBase(DWORD _code, const std::string& message)
+ : Error(message + ": " + get_last_error_as_string(_code)), code(_code) {}
const DWORD code;
private:
- static std::string get_last_error_as_string()
+ static std::string get_last_error_as_string(DWORD errorCode)
{
- DWORD errorCode = ::GetLastError();
-
// Default if no error.
if (errorCode == 0) {
return std::string();
@@ -103,4 +100,22 @@ private:
}
};
+
+class WindowsError : public WindowsErrorBase {
+public:
+ WindowsError() : WindowsErrorBase(::GetLastError()) {}
+
+ WindowsError(const std::string& message)
+ : WindowsErrorBase(::GetLastError(), message) {}
+};
+
+
+class WindowsSocketError : public WindowsErrorBase {
+public:
+ WindowsSocketError() : WindowsErrorBase(::WSAGetLastError()) {}
+
+ WindowsSocketError(const std::string& message)
+ : WindowsErrorBase(::WSAGetLastError(), message) {}
+};
+
#endif // __STOUT_WINDOWS_ERROR_HPP__
[2/5] mesos git commit: Added an additional template parameter to
'Try' for typed error.
Posted by mp...@apache.org.
Added an additional template parameter to 'Try' for typed error.
Review: https://reviews.apache.org/r/45311/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f43fd166
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f43fd166
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f43fd166
Branch: refs/heads/master
Commit: f43fd166715554c92730eaab865829633264b0f8
Parents: 9cd3b1c
Author: Michael Park <mp...@apache.org>
Authored: Tue Apr 5 11:08:33 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Tue Apr 5 11:08:33 2016 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/try.hpp | 43 ++++++++++++--------
1 file changed, 27 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/f43fd166/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
index 2625cd1..89dedec 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
@@ -30,19 +30,16 @@
// case calling 'get' will return a constant reference to the T
// stored. Calling 'isError' will return true if it stores an error,
// in which case calling 'error' will return the error string.
-template <typename T>
+template <typename T, typename E = Error>
class Try
{
public:
- static Try<T> some(const T& t)
- {
- return Try<T>(t);
- }
+ static_assert(
+ std::is_base_of<Error, E>::value,
+ "An error type must be, or be inherited from 'Error'.");
- static Try<T> error(const std::string& message)
- {
- return Try<T>(Error(message));
- }
+ static Try some(const T& t) { return Try(t); }
+ static Try error(const E& e) { return Try(e); }
Try(const T& t)
: data(Some(t)) {}
@@ -53,16 +50,15 @@ public:
std::is_constructible<T, const U&>::value>::type>
Try(const U& u) : data(Some(u)) {}
- Try(const Error& error)
- : message(error.message) {}
+ Try(const E& error) : error_(error) {}
// TODO(bmahler): Add move constructor.
// We don't need to implement these because we are leveraging
// Option<T>.
- Try(const Try<T>& that) = default;
+ Try(const Try& that) = default;
~Try() = default;
- Try<T>& operator=(const Try<T>& that) = default;
+ Try& operator=(const Try& that) = default;
// 'isSome' and 'isError' are mutually exclusive. They correspond
// to the underlying state of the Option.
@@ -72,7 +68,8 @@ public:
const T& get() const
{
if (!data.isSome()) {
- ABORT("Try::get() but state == ERROR: " + message);
+ assert(error_.isSome());
+ ABORT("Try::get() but state == ERROR: " + error_.get().message);
}
return data.get();
}
@@ -85,9 +82,23 @@ public:
const T* operator->() const { return &get(); }
T* operator->() { return &get(); }
- const std::string& error() const { assert(data.isNone()); return message; }
+ // NOTE: This function is intended to return the error of type `E`.
+ // However, we return a `std::string` if `E` == `Error` since that's what it
+ // used to return, and it's the only data that `Error` holds anyway.
+ const typename std::conditional<
+ std::is_same<E, Error>::value, std::string, E>::type& error() const
+ {
+ assert(data.isNone());
+ assert(error_.isSome());
+ return error_impl(error_.get());
+ }
private:
+ static const std::string& error_impl(const Error& err) { return err.message; }
+
+ template <typename Err>
+ static const Err& error_impl(const Err& err) { return err; }
+
// We leverage Option<T> to avoid dynamic allocation of T. This
// means that the storage for T will be included in this object
// (Try<T>). Since Option<T> keeps track of whether a value is
@@ -96,7 +107,7 @@ private:
// Option<T> is that it takes care of all the manual construction
// and destruction. This makes the code for Try<T> really simple!
Option<T> data;
- std::string message;
+ Option<E> error_;
};
[5/5] mesos git commit: Updated `network::connect` to use the typed
error state of `Try`.
Posted by mp...@apache.org.
Updated `network::connect` to use the typed error state of `Try`.
Review: https://reviews.apache.org/r/45314/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b499a1be
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b499a1be
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b499a1be
Branch: refs/heads/master
Commit: b499a1be249ac901493b058e7e8d293e9ad5ec32
Parents: 390c054
Author: Michael Park <mp...@apache.org>
Authored: Tue Apr 5 11:08:43 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Tue Apr 5 11:08:50 2016 -0700
----------------------------------------------------------------------
3rdparty/libprocess/include/process/network.hpp | 13 +++++++++++--
3rdparty/libprocess/src/poll_socket.cpp | 4 ++--
2 files changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/b499a1be/3rdparty/libprocess/include/process/network.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/network.hpp b/3rdparty/libprocess/include/process/network.hpp
index 9976257..2bc940f 100644
--- a/3rdparty/libprocess/include/process/network.hpp
+++ b/3rdparty/libprocess/include/process/network.hpp
@@ -26,6 +26,15 @@ namespace network {
using net::socket;
+
+using SocketError =
+#ifndef __WINDOWS__
+ ErrnoError;
+#else
+ WindowsSocketError;
+#endif
+
+
// TODO(benh): Remove and defer to Socket::accept.
inline Try<int> accept(int s)
{
@@ -57,14 +66,14 @@ inline Try<int> bind(int s, const Address& address)
// TODO(benh): Remove and defer to Socket::connect.
-inline Try<int> connect(int s, const Address& address)
+inline Try<int, SocketError> connect(int s, const Address& address)
{
struct sockaddr_storage storage =
net::createSockaddrStorage(address.ip, address.port);
int error = ::connect(s, (struct sockaddr*) &storage, address.size());
if (error < 0) {
- return ErrnoError("Failed to connect to " + stringify(address));
+ return SocketError("Failed to connect to " + stringify(address));
}
return error;
http://git-wip-us.apache.org/repos/asf/mesos/blob/b499a1be/3rdparty/libprocess/src/poll_socket.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/poll_socket.cpp b/3rdparty/libprocess/src/poll_socket.cpp
index 6e6634b..cb28785 100644
--- a/3rdparty/libprocess/src/poll_socket.cpp
+++ b/3rdparty/libprocess/src/poll_socket.cpp
@@ -119,9 +119,9 @@ Future<Nothing> connect(const Socket& socket)
Future<Nothing> PollSocketImpl::connect(const Address& address)
{
- Try<int> connect = network::connect(get(), address);
+ Try<int, SocketError> connect = network::connect(get(), address);
if (connect.isError()) {
- if (errno == EINPROGRESS) {
+ if (connect.error().code == EINPROGRESS) {
return io::poll(get(), io::WRITE)
.then(lambda::bind(&internal::connect, socket()));
}
[3/5] mesos git commit: Captured the error code in `ErrnoError` and
`WindowsError`.
Posted by mp...@apache.org.
Captured the error code in `ErrnoError` and `WindowsError`.
Review: https://reviews.apache.org/r/45312/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/88b544d8
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/88b544d8
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/88b544d8
Branch: refs/heads/master
Commit: 88b544d8ae0b780643841f2f48caa786c1524165
Parents: f43fd16
Author: Michael Park <mp...@apache.org>
Authored: Tue Apr 5 11:08:37 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Tue Apr 5 11:08:37 2016 -0700
----------------------------------------------------------------------
.../libprocess/3rdparty/stout/include/stout/errorbase.hpp | 6 ++++--
.../libprocess/3rdparty/stout/include/stout/windows/error.hpp | 7 +++++--
2 files changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/88b544d8/3rdparty/libprocess/3rdparty/stout/include/stout/errorbase.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/errorbase.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/errorbase.hpp
index 1e9db7e..96d395d 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/errorbase.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/errorbase.hpp
@@ -44,10 +44,12 @@ public:
class ErrnoError : public Error
{
public:
- ErrnoError() : Error(os::strerror(errno)) {}
+ ErrnoError() : Error(os::strerror(errno)), code(errno) {}
ErrnoError(const std::string& message)
- : Error(message + ": " + os::strerror(errno)) {}
+ : Error(message + ": " + os::strerror(errno)), code(errno) {}
+
+ const int code;
};
#endif // __STOUT_ERROR_BASE_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/88b544d8/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp
index 64102e1..bf21fac 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp
@@ -28,10 +28,13 @@ class WindowsError : public Error
{
public:
WindowsError()
- : Error(get_last_error_as_string()) {}
+ : Error(get_last_error_as_string()), code(::GetLastError()) {}
WindowsError(const std::string& message)
- : Error(message + ": " + get_last_error_as_string()) {}
+ : Error(message + ": " + get_last_error_as_string()),
+ code(::GetLastError()) {}
+
+ const DWORD code;
private:
static std::string get_last_error_as_string()