From 965066b814ee973df61409c711ceae0e49b13249 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Fri, 24 Jun 2016 13:39:13 +0100 Subject: [PATCH] Use getWatchFd() from dasynq::FdWatcher rather than storing the fd in a separate member variable, in various places. Squashes some TODOs. --- src/control.cc | 12 ++++++------ src/control.h | 2 -- src/dinit.cc | 12 +----------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/control.cc b/src/control.cc index 0a0462c..54a6722 100644 --- a/src/control.cc +++ b/src/control.cc @@ -318,7 +318,7 @@ bool ControlConn::queuePacket(const char *pkt, unsigned size) noexcept // If the queue is empty, we can try to write the packet out now rather than queueing it. // If the write is unsuccessful or partial, we queue the remainder. if (was_empty) { - int wr = write(iob.fd, pkt, size); + int wr = write(iob.getWatchedFd(), pkt, size); if (wr == -1) { if (errno == EPIPE) { return false; @@ -373,7 +373,7 @@ bool ControlConn::queuePacket(std::vector &&pkt) noexcept if (was_empty) { outpkt_index = 0; // We can try sending the packet immediately: - int wr = write(iob.fd, pkt.data(), pkt.size()); + int wr = write(iob.getWatchedFd(), pkt.data(), pkt.size()); if (wr == -1) { if (errno == EPIPE) { return false; @@ -424,7 +424,7 @@ bool ControlConn::rollbackComplete() noexcept bool ControlConn::dataReady() noexcept { - int fd = iob.fd; + int fd = iob.getWatchedFd(); int r = rbuf.fill(fd); @@ -471,14 +471,14 @@ bool ControlConn::sendData() noexcept if (oom_close) { // Send oom response char oomBuf[] = { DINIT_RP_OOM }; - write(iob.fd, oomBuf, 1); + write(iob.getWatchedFd(), oomBuf, 1); } return true; } vector & pkt = outbuf.front(); char *data = pkt.data(); - int written = write(iob.fd, data + outpkt_index, pkt.size() - outpkt_index); + int written = write(iob.getWatchedFd(), data + outpkt_index, pkt.size() - outpkt_index); if (written == -1) { if (errno == EPIPE) { // read end closed @@ -514,7 +514,7 @@ bool ControlConn::sendData() noexcept ControlConn::~ControlConn() noexcept { - close(iob.fd); + close(iob.getWatchedFd()); iob.deregister(*loop); // Clear service listeners diff --git a/src/control.h b/src/control.h index 7a472de..6bfd790 100644 --- a/src/control.h +++ b/src/control.h @@ -62,7 +62,6 @@ class ControlConnWatcher : public EventLoop_t::BidiFdWatcher } public: - int fd; // TODO this is already stored, find a better way to access it. EventLoop_t * eventLoop; void setWatches(int flags) @@ -72,7 +71,6 @@ class ControlConnWatcher : public EventLoop_t::BidiFdWatcher void registerWith(EventLoop_t &loop, int fd, int flags) { - this->fd = fd; this->eventLoop = &loop; BidiFdWatcher::addWatch(loop, fd, flags); } diff --git a/src/dinit.cc b/src/dinit.cc index 3ee5a62..96df79e 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -59,16 +59,6 @@ class ControlSocketWatcher : public EventLoop_t::FdWatcher control_socket_cb(&loop, fd); return Rearm::REARM; } - - public: - // TODO the fd is already stored, must we really store it again... - int fd; - - void addWatch(EventLoop_t &loop, int fd, int flags) - { - this->fd = fd; - EventLoop_t::FdWatcher::addWatch(loop, fd, flags); - } }; ControlSocketWatcher control_socket_io; @@ -502,7 +492,7 @@ void open_control_socket(bool report_ro_failure) noexcept static void close_control_socket() noexcept { if (control_socket_open) { - int fd = control_socket_io.fd; + int fd = control_socket_io.getWatchedFd(); control_socket_io.deregister(eventLoop); close(fd); -- 2.25.1