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 @@
#pragma once
#include <cstdint>
#include <string>
#include <thread>
#include <vector>
#include <string>
#include <cstdint>
#include "caf/config.hpp"
#include "caf/extend.hpp"
......@@ -51,43 +50,48 @@
#include "caf/logger.hpp"
// poll xs epoll backend
#if !defined(CAF_LINUX) || defined(CAF_POLL_IMPL) // poll() multiplexer
# define CAF_POLL_MULTIPLEXER
# ifndef CAF_WINDOWS
# include <poll.h>
# endif
#else
# define CAF_EPOLL_MULTIPLEXER
# include <sys/epoll.h>
#endif
// Forward declaration of C types.
extern "C" {
// Forward declaration for Windows.
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 io {
namespace network {
// poll vs epoll backend
#if !defined(CAF_LINUX) || defined(CAF_POLL_IMPL) // poll() multiplexer
extern const short input_mask;
extern const short error_mask;
extern const short output_mask;
class event_handler;
using multiplexer_data = pollfd;
using multiplexer_poll_shadow_data = std::vector<event_handler*>;
#else
# define CAF_EPOLL_MULTIPLEXER
extern const int input_mask;
extern const int error_mask;
extern const int output_mask;
using multiplexer_data = epoll_event;
using multiplexer_poll_shadow_data = native_socket;
#endif
// Define type aliases based on backend type.
#ifdef CAF_POLL_MULTIPLEXER
using event_mask_type = short;
using multiplexer_data = pollfd;
using multiplexer_poll_shadow_data = std::vector<event_handler*>;
#else // CAF_POLL_MULTIPLEXER
using event_mask_type = int;
using multiplexer_data = epoll_event;
using multiplexer_poll_shadow_data = native_socket;
#endif // CAF_POLL_MULTIPLEXER
/// 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.
using native_socket_acceptor = native_socket;
/// Defines the bitmask for error socket events.
extern const event_mask_type error_mask;
class default_multiplexer : public multiplexer {
public:
......@@ -189,7 +193,7 @@ private:
auto bf = i->mask;
i->mask = fun(op, bf);
if (i->mask == bf) {
// didn't do a thing
// didn'""t do a thing
CAF_LOG_DEBUG("squashing did not change the event");
} else if (i->mask == old_bf) {
// just turned into a nop
......
......@@ -18,6 +18,8 @@
#include "caf/io/network/default_multiplexer.hpp"
#include <utility>
#include "caf/config.hpp"
#include "caf/defaults.hpp"
#include "caf/optional.hpp"
......@@ -67,7 +69,14 @@
# include <netinet/tcp.h>
# include <sys/socket.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
using std::string;
......@@ -109,7 +118,7 @@ namespace io {
namespace network {
// poll vs epoll backend
#if !defined(CAF_LINUX) || defined(CAF_POLL_IMPL) // poll() multiplexer
#ifdef CAF_POLL_MULTIPLEXER
# ifndef POLLRDHUP
# define POLLRDHUP POLLHUP
# endif
......@@ -119,17 +128,16 @@ namespace network {
# ifdef CAF_WINDOWS
// From the MSDN: If the POLLPRI flag is set on a socket for the Microsoft
// Winsock provider, the WSAPoll function will fail.
const short input_mask = POLLIN;
const event_mask_type input_mask = POLLIN;
# else
const short input_mask = POLLIN | POLLPRI;
const event_mask_type input_mask = POLLIN | POLLPRI;
# endif
const short error_mask = POLLRDHUP | POLLERR | POLLHUP | POLLNVAL;
const short output_mask = POLLOUT;
const event_mask_type error_mask = POLLRDHUP | POLLERR | POLLHUP | POLLNVAL;
const event_mask_type output_mask = POLLOUT;
#else
# define CAF_EPOLL_MULTIPLEXER
const int input_mask = EPOLLIN;
const int error_mask = EPOLLRDHUP | EPOLLERR | EPOLLHUP;
const int output_mask = EPOLLOUT;
const event_mask_type input_mask = EPOLLIN;
const event_mask_type error_mask = EPOLLRDHUP | EPOLLERR | EPOLLHUP;
const event_mask_type output_mask = EPOLLOUT;
#endif
// -- 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