diff --git a/src/event/BackendEvents.hxx b/src/event/BackendEvents.hxx new file mode 100644 index 000000000..eeacb6d43 --- /dev/null +++ b/src/event/BackendEvents.hxx @@ -0,0 +1,42 @@ +/* + * Copyright 2003-2020 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef EVENT_BACKEND_EVENTS_HXX +#define EVENT_BACKEND_EVENTS_HXX + +#include "event/Features.h" + +#ifdef _WIN32 + +#include "WinSelectEvents.hxx" +using PollBackendEvents = WinSelectEvents; + +#elif defined(USE_EPOLL) + +#include "EpollEvents.hxx" +using PollBackendEvents = EpollEvents; + +#else + +#include "PollEvents.hxx" +using PollBackendEvents = PollEvents; + +#endif + +#endif diff --git a/src/event/EpollEvents.hxx b/src/event/EpollEvents.hxx new file mode 100644 index 000000000..47d63c418 --- /dev/null +++ b/src/event/EpollEvents.hxx @@ -0,0 +1,32 @@ +/* + * Copyright 2003-2020 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef EVENT_EPOLL_EVENTS_HXX +#define EVENT_EPOLL_EVENTS_HXX + +#include + +struct EpollEvents { + static constexpr unsigned READ = EPOLLIN; + static constexpr unsigned WRITE = EPOLLOUT; + static constexpr unsigned ERROR = EPOLLERR; + static constexpr unsigned HANGUP = EPOLLHUP; +}; + +#endif diff --git a/src/event/PollEvents.hxx b/src/event/PollEvents.hxx new file mode 100644 index 000000000..3868fd36d --- /dev/null +++ b/src/event/PollEvents.hxx @@ -0,0 +1,32 @@ +/* + * Copyright 2003-2020 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef EVENT_POLL_EVENTS_HXX +#define EVENT_POLL_EVENTS_HXX + +#include + +struct PollEvents { + static constexpr unsigned READ = POLLIN; + static constexpr unsigned WRITE = POLLOUT; + static constexpr unsigned ERROR = POLLERR; + static constexpr unsigned HANGUP = POLLHUP; +}; + +#endif diff --git a/src/event/PollGroupEpoll.hxx b/src/event/PollGroupEpoll.hxx index 35fa504f4..48e53fd0f 100644 --- a/src/event/PollGroupEpoll.hxx +++ b/src/event/PollGroupEpoll.hxx @@ -54,11 +54,6 @@ class PollGroupEpoll PollGroupEpoll(PollGroupEpoll &) = delete; PollGroupEpoll &operator=(PollGroupEpoll &) = delete; public: - static constexpr unsigned READ = EPOLLIN; - static constexpr unsigned WRITE = EPOLLOUT; - static constexpr unsigned ERROR = EPOLLERR; - static constexpr unsigned HANGUP = EPOLLHUP; - PollGroupEpoll() = default; auto ReadEvents(int timeout_ms) noexcept { diff --git a/src/event/PollGroupPoll.hxx b/src/event/PollGroupPoll.hxx index 19987778c..da31dc82a 100644 --- a/src/event/PollGroupPoll.hxx +++ b/src/event/PollGroupPoll.hxx @@ -42,11 +42,6 @@ class PollGroupPoll PollGroupPoll(PollGroupPoll &) = delete; PollGroupPoll &operator=(PollGroupPoll &) = delete; public: - static constexpr unsigned READ = POLLIN; - static constexpr unsigned WRITE = POLLOUT; - static constexpr unsigned ERROR = POLLERR; - static constexpr unsigned HANGUP = POLLHUP; - PollGroupPoll() noexcept; ~PollGroupPoll() noexcept; diff --git a/src/event/PollGroupWinSelect.cxx b/src/event/PollGroupWinSelect.cxx index 7a490b257..1a2b4365d 100644 --- a/src/event/PollGroupWinSelect.cxx +++ b/src/event/PollGroupWinSelect.cxx @@ -18,6 +18,7 @@ */ #include "PollGroupWinSelect.hxx" +#include "WinSelectEvents.hxx" static constexpr int EVENT_READ = 0; static constexpr int EVENT_WRITE = 1; @@ -147,13 +148,13 @@ PollGroupWinSelect::ReadEvents(int timeout_ms) noexcept return result; for (const auto i : read_set) - items[i].events |= READ; + items[i].events |= WinSelectEvents::READ; for (const auto i : write_set) - items[i].events |= WRITE; + items[i].events |= WinSelectEvents::WRITE; for (const auto i : except_set) - items[i].events |= WRITE; + items[i].events |= WinSelectEvents::WRITE; for (auto &i : items) if (i.second.events != 0) { diff --git a/src/event/PollGroupWinSelect.hxx b/src/event/PollGroupWinSelect.hxx index a3a7b2174..b89fabe34 100644 --- a/src/event/PollGroupWinSelect.hxx +++ b/src/event/PollGroupWinSelect.hxx @@ -26,15 +26,8 @@ #include #include -#include #include -/* ERROR is a WIN32 macro that poisons our namespace; this is a kludge - to allow us to use it anyway */ -#ifdef ERROR -#undef ERROR -#endif - class SocketSet { fd_set set; @@ -114,11 +107,6 @@ class PollGroupWinSelect PollGroupWinSelect(PollGroupWinSelect &) = delete; PollGroupWinSelect &operator=(PollGroupWinSelect &) = delete; public: - static constexpr unsigned READ = 1; - static constexpr unsigned WRITE = 2; - static constexpr unsigned ERROR = 0; - static constexpr unsigned HANGUP = 0; - PollGroupWinSelect() noexcept; ~PollGroupWinSelect() noexcept; diff --git a/src/event/SocketEvent.hxx b/src/event/SocketEvent.hxx index 66bc5fe18..39d1c331c 100644 --- a/src/event/SocketEvent.hxx +++ b/src/event/SocketEvent.hxx @@ -20,7 +20,7 @@ #ifndef MPD_SOCKET_EVENT_HXX #define MPD_SOCKET_EVENT_HXX -#include "PollGroup.hxx" +#include "BackendEvents.hxx" #include "net/SocketDescriptor.hxx" #include "util/BindMethod.hxx" #include "util/IntrusiveList.hxx" @@ -44,7 +44,7 @@ class EventLoop; * thread that runs the #EventLoop, except where explicitly documented * as thread-safe. */ -class SocketEvent final : IntrusiveListHook { +class SocketEvent final : IntrusiveListHook, public PollBackendEvents { friend class EventLoop; friend class IntrusiveList; @@ -69,11 +69,6 @@ class SocketEvent final : IntrusiveListHook { unsigned ready_flags = 0; public: - static constexpr unsigned READ = PollGroup::READ; - static constexpr unsigned WRITE = PollGroup::WRITE; - static constexpr unsigned ERROR = PollGroup::ERROR; - static constexpr unsigned HANGUP = PollGroup::HANGUP; - /** * These flags are always reported by epoll_wait() and don't * need to be registered with epoll_ctl(). diff --git a/src/event/WinSelectEvents.hxx b/src/event/WinSelectEvents.hxx new file mode 100644 index 000000000..eda2a0262 --- /dev/null +++ b/src/event/WinSelectEvents.hxx @@ -0,0 +1,38 @@ +/* + * Copyright 2003-2020 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef EVENT_WINSELECT_EVENTS_HXX +#define EVENT_WINSELECT_EVENTS_HXX + +#include + +/* ERROR is a WIN32 macro that poisons our namespace; this is a kludge + to allow us to use it anyway */ +#ifdef ERROR +#undef ERROR +#endif + +struct WinSelectEvents { + static constexpr unsigned READ = 1; + static constexpr unsigned WRITE = 2; + static constexpr unsigned ERROR = 0; + static constexpr unsigned HANGUP = 0; +}; + +#endif