From 4374867afe6dea191dbdfd6e7b051f182cba8425 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Thu, 16 Jun 2016 19:31:01 +0100 Subject: [PATCH] Pull in latest Dasynq, which means a massive amount of renaming. --- src/Makefile | 2 +- src/control.cc | 28 ++-- src/control.h | 30 ++--- src/dasync/dasync-flags.h | 13 -- .../dasynq-childproc.h} | 2 +- .../dasync-epoll.h => dasynq/dasynq-epoll.h} | 24 ++-- src/dasynq/dasynq-flags.h | 13 ++ .../dasynq-kqueue.h} | 15 ++- .../dmutex.h => dasynq/dasynq-mutex.h} | 2 +- src/{dasync/dasync.h => dasynq/dasynq.h} | 123 +++++++++--------- src/dinit-log.cc | 10 +- src/dinit.cc | 14 +- src/service.cc | 2 +- src/service.h | 8 +- 14 files changed, 143 insertions(+), 143 deletions(-) delete mode 100644 src/dasync/dasync-flags.h rename src/{dasync/dasync-childproc.h => dasynq/dasynq-childproc.h} (99%) rename src/{dasync/dasync-epoll.h => dasynq/dasynq-epoll.h} (94%) create mode 100644 src/dasynq/dasynq-flags.h rename src/{dasync/dasync-kqueue.h => dasynq/dasynq-kqueue.h} (96%) rename src/{dasync/dmutex.h => dasynq/dasynq-mutex.h} (98%) rename src/{dasync/dasync.h => dasynq/dasynq.h} (92%) diff --git a/src/Makefile b/src/Makefile index 2159cdc..b671fd5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -21,7 +21,7 @@ dinit-reboot: dinit-reboot.o $(CXX) -o dinit-reboot dinit-reboot.o $(objects): %.o: %.cc service.h dinit-log.h control.h control-cmds.h cpbuffer.h - $(CXX) $(CXXOPTS) -Idasync -c $< -o $@ + $(CXX) $(CXXOPTS) -Idasynq -c $< -o $@ #install: all diff --git a/src/control.cc b/src/control.cc index f716f39..20478cf 100644 --- a/src/control.cc +++ b/src/control.cc @@ -51,7 +51,7 @@ bool ControlConn::processPacket() char outbuf[] = { DINIT_RP_BADREQ }; if (! queuePacket(outbuf, 1)) return false; bad_conn_close = true; - iob.setWatchFlags(out_events); + iob.setWatchFlags(OUT_EVENTS); } return true; } @@ -75,7 +75,7 @@ bool ControlConn::processFindLoad(int pktType) char badreqRep[] = { DINIT_RP_BADREQ }; if (! queuePacket(badreqRep, 1)) return false; bad_conn_close = true; - iob.setWatchFlags(out_events); + iob.setWatchFlags(OUT_EVENTS); return true; } @@ -151,7 +151,7 @@ bool ControlConn::processStartStop(int pktType) char badreqRep[] = { DINIT_RP_BADREQ }; if (! queuePacket(badreqRep, 1)) return false; bad_conn_close = true; - iob.setWatchFlags(out_events); + iob.setWatchFlags(OUT_EVENTS); return true; } else { @@ -225,7 +225,7 @@ bool ControlConn::processUnpinService() char badreqRep[] = { DINIT_RP_BADREQ }; if (! queuePacket(badreqRep, 1)) return false; bad_conn_close = true; - iob.setWatchFlags(out_events); + iob.setWatchFlags(OUT_EVENTS); return true; } else { @@ -268,7 +268,7 @@ ControlConn::handle_t ControlConn::allocateServiceHandle(ServiceRecord *record) bool ControlConn::queuePacket(const char *pkt, unsigned size) noexcept { - int in_flag = bad_conn_close ? 0 : in_events; + int in_flag = bad_conn_close ? 0 : IN_EVENTS; bool was_empty = outbuf.empty(); // If the queue is empty, we can try to write the packet out now rather than queueing it. @@ -299,7 +299,7 @@ bool ControlConn::queuePacket(const char *pkt, unsigned size) noexcept // Create a vector out of the (remaining part of the) packet: try { outbuf.emplace_back(pkt, pkt + size); - iob.setWatchFlags(in_flag | out_events); + iob.setWatchFlags(in_flag | OUT_EVENTS); return true; } catch (std::bad_alloc &baexc) { @@ -313,7 +313,7 @@ bool ControlConn::queuePacket(const char *pkt, unsigned size) noexcept return false; } else { - iob.setWatchFlags(out_events); + iob.setWatchFlags(OUT_EVENTS); return true; } } @@ -323,7 +323,7 @@ bool ControlConn::queuePacket(const char *pkt, unsigned size) noexcept // make them extraordinary difficult to combine into a single method. bool ControlConn::queuePacket(std::vector &&pkt) noexcept { - int in_flag = bad_conn_close ? 0 : in_events; + int in_flag = bad_conn_close ? 0 : IN_EVENTS; bool was_empty = outbuf.empty(); if (was_empty) { @@ -352,7 +352,7 @@ bool ControlConn::queuePacket(std::vector &&pkt) noexcept try { outbuf.emplace_back(pkt); - iob.setWatchFlags(in_flag | out_events); + iob.setWatchFlags(in_flag | OUT_EVENTS); return true; } catch (std::bad_alloc &baexc) { @@ -366,7 +366,7 @@ bool ControlConn::queuePacket(std::vector &&pkt) noexcept return false; } else { - iob.setWatchFlags(out_events); + iob.setWatchFlags(OUT_EVENTS); return true; } } @@ -412,11 +412,11 @@ bool ControlConn::dataReady() noexcept // TODO log error? // TODO error response? bad_conn_close = true; - iob.setWatchFlags(out_events); + iob.setWatchFlags(OUT_EVENTS); } else { - int out_flags = (bad_conn_close || !outbuf.empty()) ? out_events : 0; - iob.setWatchFlags(in_events | out_flags); + int out_flags = (bad_conn_close || !outbuf.empty()) ? OUT_EVENTS : 0; + iob.setWatchFlags(IN_EVENTS | out_flags); } return false; @@ -458,7 +458,7 @@ bool ControlConn::sendData() noexcept outpkt_index = 0; if (outbuf.empty() && ! oom_close) { if (! bad_conn_close) { - iob.setWatchFlags(in_events); + iob.setWatchFlags(IN_EVENTS); } else { return true; diff --git a/src/control.h b/src/control.h index 5f420b2..f76ee28 100644 --- a/src/control.h +++ b/src/control.h @@ -9,7 +9,7 @@ #include -#include "dasync.h" +#include "dasynq.h" #include "dinit-log.h" #include "control-cmds.h" @@ -18,14 +18,14 @@ // Control connection for dinit -using namespace dasync; +using namespace dasynq; using EventLoop_t = EventLoop; class ControlConn; class ControlConnWatcher; // forward-declaration of callback: -static dasync::Rearm control_conn_cb(EventLoop_t *loop, ControlConnWatcher *watcher, int revents); +static Rearm control_conn_cb(EventLoop_t *loop, ControlConnWatcher *watcher, int revents); // Pointer to the control connection that is listening for rollback completion extern ControlConn * rollback_handler_conn; @@ -47,18 +47,18 @@ extern int active_control_conns; class ServiceSet; class ServiceRecord; -class ControlConnWatcher : public PosixBidiFdWatcher +class ControlConnWatcher : public BidiFdWatcher { inline Rearm receiveEvent(EventLoop_t * loop, int fd, int flags) noexcept; Rearm readReady(EventLoop_t * loop, int fd) noexcept override { - return receiveEvent(loop, fd, in_events); + return receiveEvent(loop, fd, IN_EVENTS); } Rearm writeReady(EventLoop_t * loop, int fd) noexcept override { - return receiveEvent(loop, fd, out_events); + return receiveEvent(loop, fd, OUT_EVENTS); } public: @@ -67,14 +67,14 @@ class ControlConnWatcher : public PosixBidiFdWatcher void setWatchFlags(int flags) { - PosixBidiFdWatcher::setWatchFlags(eventLoop, flags); + BidiFdWatcher::setWatchFlags(eventLoop, flags); } void registerWith(EventLoop_t *loop, int fd, int flags) { this->fd = fd; this->eventLoop = loop; - PosixBidiFdWatcher::registerWith(loop, fd, flags); + BidiFdWatcher::registerWith(loop, fd, flags); } }; @@ -86,7 +86,7 @@ inline Rearm ControlConnWatcher::receiveEvent(EventLoop_t * loop, int fd, int fl class ControlConn : private ServiceListener { - friend dasync::Rearm control_conn_cb(EventLoop_t *loop, ControlConnWatcher *watcher, int revents); + friend Rearm control_conn_cb(EventLoop_t *loop, ControlConnWatcher *watcher, int revents); ControlConnWatcher iob; EventLoop_t *loop; @@ -169,7 +169,7 @@ class ControlConn : private ServiceListener { bad_conn_close = true; oom_close = true; - iob.setWatchFlags(out_events); + iob.setWatchFlags(OUT_EVENTS); } // Process service event broadcast. @@ -206,7 +206,7 @@ class ControlConn : private ServiceListener public: ControlConn(EventLoop_t * loop, ServiceSet * service_set, int fd) : loop(loop), service_set(service_set), chklen(0) { - iob.registerWith(loop, fd, in_events); + iob.registerWith(loop, fd, IN_EVENTS); active_control_conns++; } @@ -216,19 +216,17 @@ class ControlConn : private ServiceListener }; -static dasync::Rearm control_conn_cb(EventLoop_t * loop, ControlConnWatcher * watcher, int revents) +static Rearm control_conn_cb(EventLoop_t * loop, ControlConnWatcher * watcher, int revents) { - using Rearm = dasync::Rearm; - char * cc_addr = (reinterpret_cast(watcher)) - offsetof(ControlConn, iob); ControlConn *conn = reinterpret_cast(cc_addr); - if (revents & in_events) { + if (revents & IN_EVENTS) { if (conn->dataReady()) { delete conn; return Rearm::REMOVED; } } - if (revents & out_events) { + if (revents & OUT_EVENTS) { if (conn->sendData()) { delete conn; return Rearm::REMOVED; diff --git a/src/dasync/dasync-flags.h b/src/dasync/dasync-flags.h deleted file mode 100644 index 441c34a..0000000 --- a/src/dasync/dasync-flags.h +++ /dev/null @@ -1,13 +0,0 @@ -namespace dasync { - -// Event type bits -constexpr unsigned int in_events = 1; -constexpr unsigned int out_events = 2; -constexpr unsigned int err_events = 4; - -constexpr unsigned int one_shot = 8; - -// Masks: -constexpr unsigned int IO_EVENTS = in_events | out_events; - -} diff --git a/src/dasync/dasync-childproc.h b/src/dasynq/dasynq-childproc.h similarity index 99% rename from src/dasync/dasync-childproc.h rename to src/dasynq/dasynq-childproc.h index 990fbb1..e364613 100644 --- a/src/dasync/dasync-childproc.h +++ b/src/dasynq/dasynq-childproc.h @@ -1,4 +1,4 @@ -namespace dasync { +namespace dasynq { // Map of pid_t to void *, with possibility of reserving entries so that mappings can // be later added with no danger of allocator exhaustion (bad_alloc). diff --git a/src/dasync/dasync-epoll.h b/src/dasynq/dasynq-epoll.h similarity index 94% rename from src/dasync/dasync-epoll.h rename to src/dasynq/dasynq-epoll.h index 05cf5aa..1ffbc56 100644 --- a/src/dasync/dasync-epoll.h +++ b/src/dasynq/dasynq-epoll.h @@ -12,7 +12,7 @@ #include #include -namespace dasync { +namespace dasynq { template class EpollLoop; @@ -110,10 +110,10 @@ template class EpollLoop : public Base } else { int flags = 0; - (events[i].events & EPOLLIN) && (flags |= in_events); - (events[i].events & EPOLLHUP) && (flags |= in_events); - (events[i].events & EPOLLOUT) && (flags |= out_events); - (events[i].events & EPOLLERR) && (flags |= err_events); + (events[i].events & EPOLLIN) && (flags |= IN_EVENTS); + (events[i].events & EPOLLHUP) && (flags |= IN_EVENTS); + (events[i].events & EPOLLOUT) && (flags |= OUT_EVENTS); + (events[i].events & EPOLLERR) && (flags |= IN_EVENTS | OUT_EVENTS | ERR_EVENTS); Base::receiveFdEvent(*this, FD_r(), ptr, flags); } } @@ -144,7 +144,7 @@ template class EpollLoop : public Base } } - // flags: in_events | out_events + // flags: IN_EVENTS | OUT_EVENTS void addFdWatch(int fd, void *userdata, int flags) { struct epoll_event epevent; @@ -152,13 +152,13 @@ template class EpollLoop : public Base epevent.data.ptr = userdata; epevent.events = 0; - if (flags & one_shot) { + if (flags & ONE_SHOT) { epevent.events = EPOLLONESHOT; } - if (flags & in_events) { + if (flags & IN_EVENTS) { epevent.events |= EPOLLIN; } - if (flags & out_events) { + if (flags & OUT_EVENTS) { epevent.events |= EPOLLOUT; } @@ -186,13 +186,13 @@ template class EpollLoop : public Base epevent.data.ptr = userdata; epevent.events = 0; - if (flags & one_shot) { + if (flags & ONE_SHOT) { epevent.events = EPOLLONESHOT; } - if (flags & in_events) { + if (flags & IN_EVENTS) { epevent.events |= EPOLLIN; } - if (flags & out_events) { + if (flags & OUT_EVENTS) { epevent.events |= EPOLLOUT; } diff --git a/src/dasynq/dasynq-flags.h b/src/dasynq/dasynq-flags.h new file mode 100644 index 0000000..4b0813b --- /dev/null +++ b/src/dasynq/dasynq-flags.h @@ -0,0 +1,13 @@ +namespace dasynq { + +// Event type bits +constexpr unsigned int IN_EVENTS = 1; +constexpr unsigned int OUT_EVENTS = 2; +constexpr unsigned int ERR_EVENTS = 4; + +constexpr unsigned int ONE_SHOT = 8; + +// Masks: +constexpr unsigned int IO_EVENTS = IN_EVENTS | OUT_EVENTS; + +} diff --git a/src/dasync/dasync-kqueue.h b/src/dasynq/dasynq-kqueue.h similarity index 96% rename from src/dasync/dasync-kqueue.h rename to src/dasynq/dasynq-kqueue.h index fb6d9da..64a3828 100644 --- a/src/dasync/dasync-kqueue.h +++ b/src/dasynq/dasynq-kqueue.h @@ -20,7 +20,7 @@ extern "C" { #include #include -namespace dasync { +namespace dasynq { template class KqueueLoop; @@ -69,6 +69,7 @@ class KqueueTraits } }; + const static bool has_bidi_fd_watch = false; const static bool has_separate_rw_fd_watches = true; }; @@ -143,7 +144,7 @@ template class KqueueLoop : public Base } } else if (events[i].filter == EVFILT_READ || events[i].filter == EVFILT_WRITE) { - int flags = events[i].filter == EVFILT_READ ? in_events : out_events; + int flags = events[i].filter == EVFILT_READ ? IN_EVENTS : OUT_EVENTS; Base::receiveFdEvent(*this, FD_r(events[i].ident), events[i].udata, flags); events[i].flags = EV_DISABLE | EV_CLEAR; // we use EV_CLEAR to clear the EOF status of fifos/pipes (and wait for @@ -194,12 +195,12 @@ template class KqueueLoop : public Base kevent(kqfd, &kev, 1, nullptr, 0, nullptr); } - // flags: in_events | out_events + // flags: IN_EVENTS | OUT_EVENTS void addFdWatch(int fd, void *userdata, int flags) { // TODO kqueue doesn't support EVFILE_WRITE on file fd's :/ - short filter = (flags & in_events) ? EVFILT_READ : EVFILT_WRITE; + short filter = (flags & IN_EVENTS) ? EVFILT_READ : EVFILT_WRITE; struct kevent kev; EV_SET(&kev, fd, filter, EV_ADD, 0, 0, userdata); @@ -210,7 +211,7 @@ template class KqueueLoop : public Base void removeFdWatch(int fd, int flags) { - removeFilter((flags & in_events) ? EVFILT_READ : EVFILT_WRITE, fd); + removeFilter((flags & IN_EVENTS) ? EVFILT_READ : EVFILT_WRITE, fd); } void removeFdWatch_nolock(int fd, int flags) @@ -220,7 +221,7 @@ template class KqueueLoop : public Base void enableFdWatch(int fd, void *userdata, int flags) { - setFilterEnabled((flags & in_events) ? EVFILT_READ : EVFILT_WRITE, fd, true); + setFilterEnabled((flags & IN_EVENTS) ? EVFILT_READ : EVFILT_WRITE, fd, true); } void enableFdWatch_nolock(int fd, void *userdata, int flags) @@ -230,7 +231,7 @@ template class KqueueLoop : public Base void disableFdWatch(int fd, int flags) { - setFilterEnabled((flags & in_events) ? EVFILT_READ : EVFILT_WRITE, fd, false); + setFilterEnabled((flags & IN_EVENTS) ? EVFILT_READ : EVFILT_WRITE, fd, false); } void disableFdWatch_nolock(int fd, int flags) diff --git a/src/dasync/dmutex.h b/src/dasynq/dasynq-mutex.h similarity index 98% rename from src/dasync/dmutex.h rename to src/dasynq/dasynq-mutex.h index b219621..a46c229 100644 --- a/src/dasync/dmutex.h +++ b/src/dasynq/dasynq-mutex.h @@ -4,7 +4,7 @@ //#include #include -namespace dasync { +namespace dasynq { // Simple non-recursive mutex, with priority inheritance to avoid priority inversion. /* diff --git a/src/dasync/dasync.h b/src/dasynq/dasynq.h similarity index 92% rename from src/dasync/dasync.h rename to src/dasynq/dasynq.h index 3602f01..93ded31 100644 --- a/src/dasync/dasync.h +++ b/src/dasynq/dasynq.h @@ -9,19 +9,19 @@ #define HAVE_EPOLL 1 #endif -#include "dasync-flags.h" +#include "dasynq-flags.h" #if defined(HAVE_KQUEUE) -#include "dasync-kqueue.h" -#include "dasync-childproc.h" -namespace dasync { +#include "dasynq-kqueue.h" +#include "dasynq-childproc.h" +namespace dasynq { template using Loop = KqueueLoop; using LoopTraits = KqueueTraits; } #elif defined(HAVE_EPOLL) -#include "dasync-epoll.h" -#include "dasync-childproc.h" -namespace dasync { +#include "dasynq-epoll.h" +#include "dasynq-childproc.h" +namespace dasynq { template using Loop = EpollLoop; using LoopTraits = EpollTraits; } @@ -31,7 +31,7 @@ namespace dasync { #include #include -#include "dmutex.h" +#include "dasynq-mutex.h" @@ -53,7 +53,7 @@ namespace dasync { #endif */ -namespace dasync { +namespace dasynq { /** @@ -77,10 +77,10 @@ enum class Rearm // Forward declarations: template class EventLoop; -template class PosixFdWatcher; -template class PosixBidiFdWatcher; -template class PosixSignalWatcher; -template class PosixChildWatcher; +template class FdWatcher; +template class BidiFdWatcher; +template class SignalWatcher; +template class ChildProcWatcher; // Information about a received signal. // This is essentially a wrapper for the POSIX siginfo_t; its existence allows for mechanisms that receive @@ -109,7 +109,7 @@ namespace dprivate { class BaseWatcher { template friend class EventDispatch; - template friend class dasync::EventLoop; + template friend class dasynq::EventLoop; protected: WatchType watchType; @@ -150,7 +150,7 @@ namespace dprivate { class BaseSignalWatcher : public BaseWatcher { template friend class EventDispatch; - friend class dasync::EventLoop; + friend class dasynq::EventLoop; protected: SigInfo siginfo; @@ -166,7 +166,7 @@ namespace dprivate { class BaseFdWatcher : public BaseWatcher { template friend class EventDispatch; - friend class dasync::EventLoop; + friend class dasynq::EventLoop; protected: int watch_fd; @@ -183,7 +183,7 @@ namespace dprivate { class BaseBidiFdWatcher : public BaseFdWatcher { template friend class EventDispatch; - friend class dasync::EventLoop; + friend class dasynq::EventLoop; // This should never actually get called: Rearm gotEvent(EventLoop * eloop, int fd, int flags) final @@ -209,7 +209,7 @@ namespace dprivate { class BaseChildWatcher : public BaseWatcher { template friend class EventDispatch; - friend class dasync::EventLoop; + friend class dasynq::EventLoop; protected: pid_t watch_pid; @@ -317,10 +317,10 @@ namespace dprivate { // queue data structure/pointer BaseWatcher * first; - using BaseSignalWatcher = dasync::dprivate::BaseSignalWatcher; - using BaseFdWatcher = dasync::dprivate::BaseFdWatcher; - using BaseBidiFdWatcher = dasync::dprivate::BaseBidiFdWatcher; - using BaseChildWatcher = dasync::dprivate::BaseChildWatcher; + using BaseSignalWatcher = dasynq::dprivate::BaseSignalWatcher; + using BaseFdWatcher = dasynq::dprivate::BaseFdWatcher; + using BaseBidiFdWatcher = dasynq::dprivate::BaseBidiFdWatcher; + using BaseChildWatcher = dasynq::dprivate::BaseChildWatcher; void queueWatcher(BaseWatcher *bwatcher) { @@ -381,11 +381,11 @@ namespace dprivate { bool is_multi_watch = bfdw->watch_flags & multi_watch; if (is_multi_watch) { BaseBidiFdWatcher *bbdw = static_cast(bwatcher); - if (flags & in_events && flags & out_events) { + if (flags & IN_EVENTS && flags & OUT_EVENTS) { // Queue the secondary watcher first: queueWatcher(&bbdw->outWatcher); } - else if (flags & out_events) { + else if (flags & OUT_EVENTS) { // Use the secondary watcher for queueing: bwatcher = &(bbdw->outWatcher); } @@ -397,11 +397,11 @@ namespace dprivate { // If this is a bidirectional fd-watch, it has been disabled in *both* directions // as the event was delivered. However, the other direction should not be disabled // yet, so we need to re-enable: - int in_out_mask = in_events | out_events; + int in_out_mask = IN_EVENTS | OUT_EVENTS; if (is_multi_watch && bfdw->event_flags != (bfdw->watch_flags & in_out_mask)) { // We need to re-enable the other channel now: loop_mech.enableFdWatch_nolock(bfdw->watch_fd, userdata, - (bfdw->watch_flags & ~(bfdw->event_flags)) | one_shot); + (bfdw->watch_flags & ~(bfdw->event_flags)) | ONE_SHOT); } } } @@ -491,10 +491,10 @@ namespace dprivate { template class EventLoop { - friend class PosixFdWatcher; - friend class PosixBidiFdWatcher; - friend class PosixSignalWatcher; - friend class PosixChildWatcher; + friend class FdWatcher; + friend class BidiFdWatcher; + friend class SignalWatcher; + friend class ChildProcWatcher; template using EventDispatch = dprivate::EventDispatch; template using waitqueue = dprivate::waitqueue; @@ -581,7 +581,7 @@ template class EventLoop void registerFd(BaseFdWatcher *callback, int fd, int eventmask) { - loop_mech.addFdWatch(fd, callback, eventmask | one_shot); + loop_mech.addFdWatch(fd, callback, eventmask | ONE_SHOT); } void registerFd(BaseBidiFdWatcher *callback, int fd, int eventmask) @@ -590,14 +590,14 @@ template class EventLoop // TODO } else { - loop_mech.addFdWatch(fd, callback, eventmask | one_shot); + loop_mech.addFdWatch(fd, callback, eventmask | ONE_SHOT); } } void setFdEnabled(BaseWatcher *watcher, int fd, int watch_flags, bool enabled) { if (enabled) { - loop_mech.enableFdWatch(fd, watcher, watch_flags | one_shot); + loop_mech.enableFdWatch(fd, watcher, watch_flags | ONE_SHOT); } else { loop_mech.disableFdWatch(fd, watch_flags); @@ -607,7 +607,7 @@ template class EventLoop void setFdEnabled_nolock(BaseWatcher *watcher, int fd, int watch_flags, bool enabled) { if (enabled) { - loop_mech.enableFdWatch_nolock(fd, watcher, watch_flags | one_shot); + loop_mech.enableFdWatch_nolock(fd, watcher, watch_flags | ONE_SHOT); } else { loop_mech.disableFdWatch_nolock(fd, watch_flags); @@ -735,7 +735,7 @@ template class EventLoop if (rearmType == Rearm::REMOVE) { bdfw->read_removed = 1; - bdfw->watch_flags &= ~in_events; + bdfw->watch_flags &= ~IN_EVENTS; if (! LoopTraits::has_separate_rw_fd_watches) { if (! bdfw->write_removed) { @@ -757,16 +757,16 @@ template class EventLoop // Nothing more to do } else if (rearmType == Rearm::REARM) { - bdfw->watch_flags |= in_events; + bdfw->watch_flags |= IN_EVENTS; if (! LoopTraits::has_separate_rw_fd_watches) { loop_mech.enableFdWatch_nolock(bdfw->watch_fd, static_cast(bdfw), - (bdfw->watch_flags & (in_events | out_events)) | one_shot); + (bdfw->watch_flags & (IN_EVENTS | OUT_EVENTS)) | ONE_SHOT); } else { loop_mech.enableFdWatch_nolock(bdfw->watch_fd, static_cast(bdfw), - in_events | one_shot); + IN_EVENTS | ONE_SHOT); } } return rearmType; @@ -774,7 +774,7 @@ template class EventLoop else { if (rearmType == Rearm::REARM) { loop_mech.enableFdWatch_nolock(bfw->watch_fd, bfw, - (bfw->watch_flags & (in_events | out_events)) | one_shot); + (bfw->watch_flags & (IN_EVENTS | OUT_EVENTS)) | ONE_SHOT); } else if (rearmType == Rearm::REMOVE) { loop_mech.removeFdWatch_nolock(bfw->watch_fd, bfw->watch_flags); @@ -788,7 +788,7 @@ template class EventLoop // Called with lock held if (rearmType == Rearm::REMOVE) { bdfw->write_removed = 1; - bdfw->watch_flags &= ~out_events; + bdfw->watch_flags &= ~OUT_EVENTS; if (LoopTraits::has_separate_rw_fd_watches) { // TODO this will need flags for such a loop, since it can't @@ -811,16 +811,16 @@ template class EventLoop // Nothing more to do } else if (rearmType == Rearm::REARM) { - bdfw->watch_flags |= out_events; + bdfw->watch_flags |= OUT_EVENTS; if (! LoopTraits::has_separate_rw_fd_watches) { loop_mech.enableFdWatch_nolock(bdfw->watch_fd, static_cast(bdfw), - (bdfw->watch_flags & (in_events | out_events)) | one_shot); + (bdfw->watch_flags & (IN_EVENTS | OUT_EVENTS)) | ONE_SHOT); } else { loop_mech.enableFdWatch_nolock(bdfw->watch_fd, static_cast(bdfw), - out_events | one_shot); + OUT_EVENTS | ONE_SHOT); } } return rearmType; @@ -855,7 +855,7 @@ template class EventLoop is_multi_watch = bfw->watch_flags & dprivate::multi_watch; if (! LoopTraits::has_separate_rw_fd_watches && is_multi_watch) { // Clear the input watch flags to avoid enabling read watcher while active: - bfw->watch_flags &= ~in_events; + bfw->watch_flags &= ~IN_EVENTS; } } else if (pqueue->watchType == WatchType::SECONDARYFD) { @@ -864,7 +864,7 @@ template class EventLoop rp -= offsetof(BaseBidiFdWatcher, outWatcher); bbfw = (BaseBidiFdWatcher *)rp; if (! LoopTraits::has_separate_rw_fd_watches) { - bbfw->watch_flags &= ~out_events; + bbfw->watch_flags &= ~OUT_EVENTS; } } @@ -976,7 +976,7 @@ TEventLoop & getSystemLoop(); // Posix signal event watcher template -class PosixSignalWatcher : private dprivate::BaseSignalWatcher +class SignalWatcher : private dprivate::BaseSignalWatcher { using BaseWatcher = dprivate::BaseWatcher; @@ -1003,7 +1003,7 @@ public: // Posix file descriptor event watcher template -class PosixFdWatcher : private dprivate::BaseFdWatcher +class FdWatcher : private dprivate::BaseFdWatcher { using BaseWatcher = dprivate::BaseWatcher; @@ -1021,9 +1021,10 @@ class PosixFdWatcher : private dprivate::BaseFdWatcher public: // Register a file descriptor watcher with an event loop. Flags - // can be any combination of dasync::in_events / dasync::out_events. - // Exactly one of in_events/out_events must be specified if the event - // loop does not support bi-directional fd watchers. + // can be any combination of dasynq::IN_EVENTS / dasynq::OUT_EVENTS. + // Exactly one of IN_EVENTS/OUT_EVENTS must be specified if the event + // loop does not support bi-directional fd watchers (i.e. if + // ! LoopTraits::has_bidi_fd_watch). // // Mechanisms supporting dual watchers allow for two watchers for a // single file descriptor (one watching read status and the other @@ -1070,13 +1071,13 @@ class PosixFdWatcher : private dprivate::BaseFdWatcher // This watcher type has two event notification methods which can both potentially be // active at the same time. template -class PosixBidiFdWatcher : private dprivate::BaseBidiFdWatcher +class BidiFdWatcher : private dprivate::BaseBidiFdWatcher { using BaseWatcher = dprivate::BaseWatcher; void setWatchEnabled(EventLoop *eloop, bool in, bool b) { - int events = in ? in_events : out_events; + int events = in ? IN_EVENTS : OUT_EVENTS; if (b) { this->watch_flags |= events; @@ -1086,15 +1087,15 @@ class PosixBidiFdWatcher : private dprivate::BaseBidiFdWatcher } if (LoopTraits::has_separate_rw_fd_watches) { dprivate::BaseWatcher * watcher = in ? this : &this->outWatcher; - eloop->setFdEnabled_nolock(watcher, this->watch_fd, events | one_shot, b); + eloop->setFdEnabled_nolock(watcher, this->watch_fd, events | ONE_SHOT, b); if (! b) { eloop->dequeueWatcher(watcher); } } else { eloop->setFdEnabled_nolock(this, this->watch_fd, - (this->watch_flags & (in_events | out_events)) | one_shot, - (this->watch_flags & (in_events | out_events)) != 0); + (this->watch_flags & (IN_EVENTS | OUT_EVENTS)) | ONE_SHOT, + (this->watch_flags & (IN_EVENTS | OUT_EVENTS)) != 0); if (! b) { dprivate::BaseWatcher * watcher = in ? this : &this->outWatcher; eloop->dequeueWatcher(watcher); @@ -1131,8 +1132,8 @@ class PosixBidiFdWatcher : private dprivate::BaseBidiFdWatcher { std::lock_guard guard(eloop->getBaseLock()); if (LoopTraits::has_separate_rw_fd_watches) { - setWatchEnabled(eloop, true, (newFlags & in_events) != 0); - setWatchEnabled(eloop, false, (newFlags & out_events) != 0); + setWatchEnabled(eloop, true, (newFlags & IN_EVENTS) != 0); + setWatchEnabled(eloop, false, (newFlags & OUT_EVENTS) != 0); } else { this->watch_flags = (this->watch_flags & ~IO_EVENTS) | newFlags; @@ -1143,7 +1144,7 @@ class PosixBidiFdWatcher : private dprivate::BaseBidiFdWatcher public: // Register a bi-direction file descriptor watcher with an event loop. Flags - // can be any combination of dasync::in_events / dasync::out_events. + // can be any combination of dasynq::IN_EVENTS / dasynq::OUT_EVENTS. // // Can fail with std::bad_alloc or std::system_error. void registerWith(EventLoop *eloop, int fd, int flags) @@ -1173,9 +1174,9 @@ class PosixBidiFdWatcher : private dprivate::BaseBidiFdWatcher // Rearm writeReady(EventLoop * eloop, int fd) noexcept }; -// Posix child process event watcher +// Child process event watcher template -class PosixChildWatcher : private dprivate::BaseChildWatcher +class ChildProcWatcher : private dprivate::BaseChildWatcher { using BaseWatcher = dprivate::BaseWatcher; @@ -1208,6 +1209,6 @@ class PosixChildWatcher : private dprivate::BaseChildWatcher // virtual void gotTermStat(EventLoop *, pid_t child, int status) = 0; }; -} // namespace dasync +} // namespace dasynq #endif diff --git a/src/dinit-log.cc b/src/dinit-log.cc index 826a1ac..07cfed8 100644 --- a/src/dinit-log.cc +++ b/src/dinit-log.cc @@ -6,7 +6,7 @@ #include #include -#include "dasync.h" +#include "dasynq.h" #include "service.h" #include "dinit-log.h" @@ -20,7 +20,7 @@ LogLevel log_level[2] = { LogLevel::WARN, LogLevel::WARN }; static ServiceSet *service_set = nullptr; // Reference to service set namespace { -class BufferedLogStream : public PosixFdWatcher +class BufferedLogStream : public FdWatcher { private: @@ -106,7 +106,7 @@ void BufferedLogStream::flushForRelease() // Try to flush any messages that are currently buffered. (Console is non-blocking // so it will fail gracefully). - if (gotEvent(&eventLoop, fd, out_events) == Rearm::DISARM) { + if (gotEvent(&eventLoop, fd, OUT_EVENTS) == Rearm::DISARM) { // Console has already been released at this point. setEnabled(&eventLoop, false); } @@ -223,7 +223,7 @@ Rearm BufferedLogStream::gotEvent(EventLoop_t *loop, int fd, int flags) noexcept void init_log(ServiceSet *sset) { service_set = sset; - log_stream[DLOG_CONS].registerWith(&eventLoop, STDOUT_FILENO, out_events); // TODO register in disabled state + log_stream[DLOG_CONS].registerWith(&eventLoop, STDOUT_FILENO, OUT_EVENTS); // TODO register in disabled state enable_console_log(true); } @@ -232,7 +232,7 @@ void init_log(ServiceSet *sset) void setup_main_log(int fd) { log_stream[DLOG_MAIN].init(fd); - log_stream[DLOG_MAIN].registerWith(&eventLoop, fd, out_events); + log_stream[DLOG_MAIN].registerWith(&eventLoop, fd, OUT_EVENTS); } bool is_log_flushed() noexcept diff --git a/src/dinit.cc b/src/dinit.cc index daaa0a0..a87b4f7 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -13,7 +13,7 @@ #include #include -#include "dasync.h" +#include "dasynq.h" #include "service.h" #include "control.h" #include "dinit-log.h" @@ -60,7 +60,7 @@ */ -using namespace dasync; +using namespace dasynq; using EventLoop_t = EventLoop; EventLoop_t eventLoop = EventLoop_t(); @@ -73,7 +73,7 @@ static void close_control_socket(EventLoop_t *loop) noexcept; static void control_socket_cb(EventLoop_t *loop, int fd); -class ControlSocketWatcher : public PosixFdWatcher +class ControlSocketWatcher : public FdWatcher { Rearm gotEvent(EventLoop_t * loop, int fd, int flags) { @@ -88,7 +88,7 @@ class ControlSocketWatcher : public PosixFdWatcher void registerWith(EventLoop_t * loop, int fd, int flags) { this->fd = fd; - PosixFdWatcher::registerWith(loop, fd, flags); + FdWatcher::registerWith(loop, fd, flags); } }; @@ -133,7 +133,7 @@ const char * get_user_home() namespace { - class CallbackSignalHandler : public PosixSignalWatcher + class CallbackSignalHandler : public SignalWatcher { public: typedef void (*cb_func_t)(EventLoop_t *); @@ -157,7 +157,7 @@ namespace { } }; - class ControlSocketWatcher : public PosixFdWatcher + class ControlSocketWatcher : public FdWatcher { Rearm gotEvent(EventLoop_t * loop, int fd, int flags) { @@ -505,7 +505,7 @@ static void open_control_socket(EventLoop_t *loop) noexcept } control_socket_open = true; - control_socket_io.registerWith(&eventLoop, sockfd, in_events); + control_socket_io.registerWith(&eventLoop, sockfd, IN_EVENTS); } } diff --git a/src/service.cc b/src/service.cc index 746a3b6..92328a2 100644 --- a/src/service.cc +++ b/src/service.cc @@ -726,7 +726,7 @@ bool ServiceRecord::start_ps_process(const std::vector &cmd, bool // Listen for status // TODO should set this up earlier so we can handle failure case (exception) - child_status_listener.registerWith(&eventLoop, pipefd[0], in_events); + child_status_listener.registerWith(&eventLoop, pipefd[0], IN_EVENTS); // Add a process listener so we can detect when the // service stops diff --git a/src/service.h b/src/service.h index 7c4ca90..f796581 100644 --- a/src/service.h +++ b/src/service.h @@ -7,7 +7,7 @@ #include #include -#include "dasync.h" +#include "dasynq.h" #include "control.h" #include "service-listener.h" @@ -180,7 +180,7 @@ static std::vector separate_args(std::string &s, std::list +class ServiceChildWatcher : public ChildProcWatcher { public: // TODO resolve clunkiness of storing this field @@ -190,7 +190,7 @@ class ServiceChildWatcher : public PosixChildWatcher ServiceChildWatcher(ServiceRecord * sr) noexcept : service(sr) { } }; -class ServiceIoWatcher : public PosixFdWatcher +class ServiceIoWatcher : public FdWatcher { public: // TODO resolve clunkiness of storing these fields @@ -203,7 +203,7 @@ class ServiceIoWatcher : public PosixFdWatcher void registerWith(EventLoop_t *loop, int fd, int flags) { this->fd = fd; - PosixFdWatcher::registerWith(loop, fd, flags); + FdWatcher::registerWith(loop, fd, flags); } }; -- 2.25.1