Repository: trafficserver Updated Branches: refs/heads/master 457a0b80e -> 3d1017fe1
TS-2951: Remove xfd. Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/3d1017fe Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/3d1017fe Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/3d1017fe Branch: refs/heads/master Commit: 3d1017fe1052dda9c1fa1a3e5d08e4db036fdbcc Parents: 457a0b8 Author: Alan M. Carroll <[email protected]> Authored: Tue Jul 22 15:13:54 2014 -0500 Committer: Alan M. Carroll <[email protected]> Committed: Tue Jul 22 15:14:52 2014 -0500 ---------------------------------------------------------------------- iocore/cache/Store.cc | 6 ++-- iocore/eventsystem/I_SocketManager.h | 46 ------------------------------- iocore/hostdb/MultiCache.cc | 6 ++-- lib/ts/ink_memory.h | 9 +++++- proxy/logging/LogSock.cc | 4 +-- 5 files changed, 16 insertions(+), 55 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d1017fe/iocore/cache/Store.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/Store.cc b/iocore/cache/Store.cc index 9e3b990..70acf48 100644 --- a/iocore/cache/Store.cc +++ b/iocore/cache/Store.cc @@ -510,7 +510,7 @@ Span::init(char *an, int64_t size) return "error stat of file"; } - xfd fd(socketManager.open(n, O_RDONLY)); + ats_scoped_fd fd(socketManager.open(n, O_RDONLY)); if (!fd) { Warning("unable to open '%s': %s", n, strerror(errno)); return "unable to open"; @@ -601,7 +601,7 @@ Span::init(char *filename, int64_t size) // is_mmapable_internal = true; - xfd fd(socketManager.open(filename, O_RDONLY)); + ats_scoped_fd fd(socketManager.open(filename, O_RDONLY)); if (!fd) { Warning("unable to open '%s': %s", filename, strerror(errno)); return "unable to open"; @@ -686,7 +686,7 @@ Span::init(char *filename, int64_t size) int devnum = 0, arg = 0; int ret = 0, is_disk = 0; u_int64_t heads, sectors, cylinders, adjusted_sec; - xfd fd; + ats_scoped_fd fd; /* Fetch file type */ struct stat stat_buf; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d1017fe/iocore/eventsystem/I_SocketManager.h ---------------------------------------------------------------------- diff --git a/iocore/eventsystem/I_SocketManager.h b/iocore/eventsystem/I_SocketManager.h index e7003c2..d294a5c 100644 --- a/iocore/eventsystem/I_SocketManager.h +++ b/iocore/eventsystem/I_SocketManager.h @@ -134,50 +134,4 @@ private: extern SocketManager socketManager; -struct xfd { - - xfd() : m_fd(-1) { - } - - explicit xfd(int _fd) : m_fd(_fd) { - } - - ~xfd() { - if (this->m_fd != -1) { - socketManager.close(this->m_fd); - } - } - - /// Auto convert to a raw file descriptor. - operator int() const { return m_fd; } - - /// Boolean operator. Returns true if we have a valid file descriptor. - operator bool() const { return m_fd != -1; } - - xfd& operator=(int fd) { - if (this->m_fd != -1) { - socketManager.close(this->m_fd); - } - - this->m_fd = fd; - return *this; - } - - int release() { - int tmp = this->m_fd; - this->m_fd = -1; - return tmp; - } - - private: - int m_fd; - - xfd(xfd const&); // disabled - xfd& operator=(xfd const&); // disabled -}; - -// Add these to reduce ambiguity testing the fd. -inline bool operator < (xfd const& lhs, int rhs) { return static_cast<int>(lhs) < rhs; } -inline bool operator < (int lhs, xfd const& rhs) { return lhs < static_cast<int>(rhs); } - #endif /*_SocketManager_h_*/ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d1017fe/iocore/hostdb/MultiCache.cc ---------------------------------------------------------------------- diff --git a/iocore/hostdb/MultiCache.cc b/iocore/hostdb/MultiCache.cc index 3d7ce02..f54fc20 100644 --- a/iocore/hostdb/MultiCache.cc +++ b/iocore/hostdb/MultiCache.cc @@ -296,7 +296,7 @@ MultiCacheBase::unmap_data() int MultiCacheBase::mmap_data(bool private_flag, bool zero_fill) { - xfd fd; + ats_scoped_fd fd; int fds[MULTI_CACHE_MAX_FILES] = { 0 }; int n_fds = 0; size_t total_mapped = 0; // total mapped memory from storage. @@ -507,7 +507,7 @@ MultiCacheBase::read_config(const char *config_filename, Store & s, char *fn, in Layout::relative_to(p, sizeof(p), rundir, config_filename); - xfd fd(::open(p, O_RDONLY)); + ats_scoped_fd fd(::open(p, O_RDONLY)); if (fd < 0) return 0; @@ -797,7 +797,7 @@ MultiCacheBase::rebuild(MultiCacheBase & old, int kind) // map in a chunk of space to use as scratch (check) // or to copy the database to. - xfd fd(socketManager.open("/dev/zero", O_RDONLY)); + ats_scoped_fd fd(socketManager.open("/dev/zero", O_RDONLY)); if (fd < 0) { Warning("unable to open /dev/zero: %d, %s", errno, strerror(errno)); return -1; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d1017fe/lib/ts/ink_memory.h ---------------------------------------------------------------------- diff --git a/lib/ts/ink_memory.h b/lib/ts/ink_memory.h index e0b3291..c9ad09e 100644 --- a/lib/ts/ink_memory.h +++ b/lib/ts/ink_memory.h @@ -435,8 +435,15 @@ public: 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) + { } + /// Assign a file descriptor @a fd. - self& operator = (int fd) { + self& operator = (value_type fd) { super::operator=(fd); return *this; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d1017fe/proxy/logging/LogSock.cc ---------------------------------------------------------------------- diff --git a/proxy/logging/LogSock.cc b/proxy/logging/LogSock.cc index fbcce06..b25bfb7 100644 --- a/proxy/logging/LogSock.cc +++ b/proxy/logging/LogSock.cc @@ -87,7 +87,7 @@ LogSock::listen(int accept_port, int family) int size = sizeof(bind_addr); char this_host[MAXDNAME]; int ret; - xfd accept_sd; + ats_scoped_fd accept_sd; Debug("log-sock", "Listening ..."); @@ -230,7 +230,7 @@ int LogSock::connect(sockaddr const* ip) { int cid, ret; - xfd connect_sd; + ats_scoped_fd connect_sd; uint16_t port; if (!ats_is_ip(ip)) {
