You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2014/11/07 23:53:11 UTC

trafficserver git commit: TS-3719: Remove boolean operators from ats_scoped_fd.

Repository: trafficserver
Updated Branches:
  refs/heads/master e12f0d772 -> 8a980c0b9


TS-3719: Remove boolean operators from ats_scoped_fd.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/8a980c0b
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/8a980c0b
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/8a980c0b

Branch: refs/heads/master
Commit: 8a980c0b9a713426ad8f1b65d7c059e908cdf685
Parents: e12f0d7
Author: Alan M. Carroll <am...@apache.org>
Authored: Fri Nov 7 16:52:39 2014 -0600
Committer: Alan M. Carroll <am...@apache.org>
Committed: Fri Nov 7 16:52:39 2014 -0600

----------------------------------------------------------------------
 iocore/cache/Store.cc |  2 +-
 lib/ts/ink_memory.h   | 49 +++++++++++++++++++++++-----------------------
 mgmt/api/CoreAPI.cc   |  2 +-
 3 files changed, 27 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/8a980c0b/iocore/cache/Store.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/Store.cc b/iocore/cache/Store.cc
index 96b1721..debe16c 100644
--- a/iocore/cache/Store.cc
+++ b/iocore/cache/Store.cc
@@ -485,7 +485,7 @@ Span::init(const char * path, int64_t size)
   ink_device_geometry geometry;
 
   ats_scoped_fd fd(socketManager.open(path, O_RDONLY));
-  if (!fd) {
+  if (fd < 0) {
     serr = make_span_error(errno);
     Warning("unable to open '%s': %s", path, strerror(errno));
     goto fail;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/8a980c0b/lib/ts/ink_memory.h
----------------------------------------------------------------------
diff --git a/lib/ts/ink_memory.h b/lib/ts/ink_memory.h
index 5859ed3..304c7a9 100644
--- a/lib/ts/ink_memory.h
+++ b/lib/ts/ink_memory.h
@@ -227,6 +227,9 @@ ink_zero(T& t) {
     require that). We can only hope the compiler is smart enough to optimize out functions returning
     constants.
 
+    @internal For subclasses, you need to override the default constructor, value constructor, and
+    assignment operator. This will be easier with C++ eleventy.
+
 */
 
 template <
@@ -282,8 +285,11 @@ public:
     return zret;
   }
 
-  /** Place a new resource in the container.
+  /** Place a new resource @a rt in the container.
       Any resource currently contained is destroyed.
+      This object becomes the owner of @a rt.
+
+      @internal This is usually overridden in subclasses to get the return type adjusted.
   */
   self& operator = (value_type rt) {
     if (Traits::isValid(_r)) Traits::destroy(_r);
@@ -291,14 +297,21 @@ public:
     return *this;
   }
 
+  /// Equality.
   bool operator == (value_type rt) const {
     return _r == rt;
   }
 
+  /// Inequality.
   bool operator != (value_type rt) const {
     return _r != rt;
   }
 
+  /// Test if the contained resource is valid.
+  bool isValid() const {
+    return Traits::isValid(_r);
+  }
+
 protected:
   value_type _r; ///< Resource.
 private:
@@ -319,40 +332,28 @@ namespace detail {
   };
 }
 /** File descriptor as a scoped resource.
-
-    @internal This needs to be a class and not just a @c typedef because the
-    pseudo-bool operator is required to avoid ambiguity for non-pointer
-    resources, but creates ambiguity for pointer resources.
  */
 class ats_scoped_fd : public ats_scoped_resource<detail::SCOPED_FD_TRAITS>
 {
 public:
   typedef ats_scoped_resource<detail::SCOPED_FD_TRAITS> super; ///< Super type.
   typedef ats_scoped_fd self; ///< Self reference type.
-  typedef bool (self::*pseudo_bool)() const; ///< Bool operator type.
 
-  /// Default constructor (invalid file descriptor).
-  ats_scoped_fd()
-  { }
-  /// Construct with file descriptor.
-  explicit ats_scoped_fd(value_type v) : super(v)
-  { }
+  /// Default constructor - an empty container.
+  ats_scoped_fd() : super() {}
 
-  /// Assign a file descriptor @a fd.
-  self& operator = (value_type fd) {
-    super::operator=(fd);
-    return *this;
-  }
+  /// Construct with contained resource.
+  explicit ats_scoped_fd(value_type rt) : super(rt) {}
 
-  /// Enable direct validity check in an @c if statement w/o ambiguity with @c int conversion.
-  operator pseudo_bool () const {
-    return Traits::isValid(_r) ?  &self::operator! : 0;
+  /** Place a new resource @a rt in the container.
+      Any resource currently contained is destroyed.
+      This object becomes the owner of @a rt.
+  */
+  self& operator = (value_type rt) {
+    super::operator=(rt);
+    return *this;
   }
 
-  /// Not valid check.
-  bool operator ! () const {
-    return ! Traits::isValid(_r);
-  }
 };
 
 namespace detail {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/8a980c0b/mgmt/api/CoreAPI.cc
----------------------------------------------------------------------
diff --git a/mgmt/api/CoreAPI.cc b/mgmt/api/CoreAPI.cc
index 0c13b65..e0fa0c1 100644
--- a/mgmt/api/CoreAPI.cc
+++ b/mgmt/api/CoreAPI.cc
@@ -373,7 +373,7 @@ ServerBacktrace(unsigned /* options */, char ** trace)
 
     snprintf(threadname, sizeof(threadname), "/proc/%ld/comm", (long)threadid);
     fd = open(threadname, O_RDONLY);
-    if (fd) {
+    if (fd >= 0) {
       text.format("Thread %ld, ", (long)threadid);
       text.readFromFD(fd);
       text.chomp();