Commit 52b95149 authored by Dominik Charousset's avatar Dominik Charousset

Cleanup defines and move sys header to .cpp file

parent 16dd62fc
...@@ -18,11 +18,10 @@ ...@@ -18,11 +18,10 @@
#pragma once #pragma once
#include <cstdint>
#include <string>
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <string>
#include <cstdint>
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/extend.hpp" #include "caf/extend.hpp"
...@@ -51,43 +50,48 @@ ...@@ -51,43 +50,48 @@
#include "caf/logger.hpp" #include "caf/logger.hpp"
// poll xs epoll backend // Forward declaration of C types.
#if !defined(CAF_LINUX) || defined(CAF_POLL_IMPL) // poll() multiplexer extern "C" {
# define CAF_POLL_MULTIPLEXER
# ifndef CAF_WINDOWS
# include <poll.h>
# endif
#else
# define CAF_EPOLL_MULTIPLEXER
# include <sys/epoll.h>
#endif
// Forward declaration for Windows.
struct pollfd; struct pollfd;
struct epoll_event;
} // extern "C"
// Pick a backend for the multiplexer, depending on the settings in config.hpp.
#if !defined(CAF_LINUX) || defined(CAF_POLL_IMPL)
#define CAF_POLL_MULTIPLEXER
#else
#define CAF_EPOLL_MULTIPLEXER
#endif
namespace caf { namespace caf {
namespace io { namespace io {
namespace network { namespace network {
// poll vs epoll backend // Define type aliases based on backend type.
#if !defined(CAF_LINUX) || defined(CAF_POLL_IMPL) // poll() multiplexer #ifdef CAF_POLL_MULTIPLEXER
extern const short input_mask;
extern const short error_mask; using event_mask_type = short;
extern const short output_mask; using multiplexer_data = pollfd;
class event_handler; using multiplexer_poll_shadow_data = std::vector<event_handler*>;
using multiplexer_data = pollfd;
using multiplexer_poll_shadow_data = std::vector<event_handler*>; #else // CAF_POLL_MULTIPLEXER
#else
# define CAF_EPOLL_MULTIPLEXER using event_mask_type = int;
extern const int input_mask; using multiplexer_data = epoll_event;
extern const int error_mask; using multiplexer_poll_shadow_data = native_socket;
extern const int output_mask;
using multiplexer_data = epoll_event; #endif // CAF_POLL_MULTIPLEXER
using multiplexer_poll_shadow_data = native_socket;
#endif /// Defines the bitmask for input (read) socket events.
extern const event_mask_type input_mask;
/// Defines the bitmask for output (write) socket events.
extern const event_mask_type output_mask;
/// Platform-specific native acceptor socket type. /// Defines the bitmask for error socket events.
using native_socket_acceptor = native_socket; extern const event_mask_type error_mask;
class default_multiplexer : public multiplexer { class default_multiplexer : public multiplexer {
public: public:
...@@ -189,7 +193,7 @@ private: ...@@ -189,7 +193,7 @@ private:
auto bf = i->mask; auto bf = i->mask;
i->mask = fun(op, bf); i->mask = fun(op, bf);
if (i->mask == bf) { if (i->mask == bf) {
// didn't do a thing // didn'""t do a thing
CAF_LOG_DEBUG("squashing did not change the event"); CAF_LOG_DEBUG("squashing did not change the event");
} else if (i->mask == old_bf) { } else if (i->mask == old_bf) {
// just turned into a nop // just turned into a nop
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "caf/io/network/default_multiplexer.hpp" #include "caf/io/network/default_multiplexer.hpp"
#include <utility>
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/defaults.hpp" #include "caf/defaults.hpp"
#include "caf/optional.hpp" #include "caf/optional.hpp"
...@@ -67,7 +69,14 @@ ...@@ -67,7 +69,14 @@
# include <netinet/tcp.h> # include <netinet/tcp.h>
# include <sys/socket.h> # include <sys/socket.h>
# include <sys/types.h> # include <sys/types.h>
# include <utility> #ifdef CAF_POLL_MULTIPLEXER
# include <poll.h>
#elif defined(CAF_EPOLL_MULTIPLEXER)
# include <sys/epoll.h>
#else
# error "neither CAF_POLL_MULTIPLEXER nor CAF_EPOLL_MULTIPLEXER defined"
#endif
#endif #endif
using std::string; using std::string;
...@@ -109,7 +118,7 @@ namespace io { ...@@ -109,7 +118,7 @@ namespace io {
namespace network { namespace network {
// poll vs epoll backend // poll vs epoll backend
#if !defined(CAF_LINUX) || defined(CAF_POLL_IMPL) // poll() multiplexer #ifdef CAF_POLL_MULTIPLEXER
# ifndef POLLRDHUP # ifndef POLLRDHUP
# define POLLRDHUP POLLHUP # define POLLRDHUP POLLHUP
# endif # endif
...@@ -119,17 +128,16 @@ namespace network { ...@@ -119,17 +128,16 @@ namespace network {
# ifdef CAF_WINDOWS # ifdef CAF_WINDOWS
// From the MSDN: If the POLLPRI flag is set on a socket for the Microsoft // From the MSDN: If the POLLPRI flag is set on a socket for the Microsoft
// Winsock provider, the WSAPoll function will fail. // Winsock provider, the WSAPoll function will fail.
const short input_mask = POLLIN; const event_mask_type input_mask = POLLIN;
# else # else
const short input_mask = POLLIN | POLLPRI; const event_mask_type input_mask = POLLIN | POLLPRI;
# endif # endif
const short error_mask = POLLRDHUP | POLLERR | POLLHUP | POLLNVAL; const event_mask_type error_mask = POLLRDHUP | POLLERR | POLLHUP | POLLNVAL;
const short output_mask = POLLOUT; const event_mask_type output_mask = POLLOUT;
#else #else
# define CAF_EPOLL_MULTIPLEXER const event_mask_type input_mask = EPOLLIN;
const int input_mask = EPOLLIN; const event_mask_type error_mask = EPOLLRDHUP | EPOLLERR | EPOLLHUP;
const int error_mask = EPOLLRDHUP | EPOLLERR | EPOLLHUP; const event_mask_type output_mask = EPOLLOUT;
const int output_mask = EPOLLOUT;
#endif #endif
// -- Platform-dependent abstraction over epoll() or poll() -------------------- // -- Platform-dependent abstraction over epoll() or poll() --------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment