Commit 812e7562 authored by Luca Boccassi's avatar Luca Boccassi Committed by GitHub

Merge pull request #2809 from sigiesec/optimize-select-win

Optimize select on Windows; reduce code duplication in select_t
parents 2b75a9ef f9d7eea6
This diff is collapsed.
...@@ -53,16 +53,14 @@ ...@@ -53,16 +53,14 @@
namespace zmq namespace zmq
{ {
struct i_poll_events;
struct i_poll_events; // Implements socket polling mechanism using POSIX.1-2001 select()
// function.
// Implements socket polling mechanism using POSIX.1-2001 select() class select_t : public poller_base_t
// function. {
class select_t : public poller_base_t
{
public: public:
typedef fd_t handle_t; typedef fd_t handle_t;
select_t (const ctx_t &ctx_); select_t (const ctx_t &ctx_);
...@@ -81,7 +79,6 @@ namespace zmq ...@@ -81,7 +79,6 @@ namespace zmq
static int max_fds (); static int max_fds ();
private: private:
// Main worker thread routine. // Main worker thread routine.
static void worker_routine (void *arg_); static void worker_routine (void *arg_);
...@@ -95,10 +92,10 @@ namespace zmq ...@@ -95,10 +92,10 @@ namespace zmq
struct fds_set_t struct fds_set_t
{ {
fds_set_t (); fds_set_t ();
fds_set_t (const fds_set_t& other_); fds_set_t (const fds_set_t &other_);
fds_set_t& operator=(const fds_set_t& other_); fds_set_t &operator= (const fds_set_t &other_);
// Convinient method to descriptor from all sets. // Convenience method to descriptor from all sets.
void remove_fd (const fd_t& fd_); void remove_fd (const fd_t &fd_);
fd_set read; fd_set read;
fd_set write; fd_set write;
...@@ -108,11 +105,14 @@ namespace zmq ...@@ -108,11 +105,14 @@ namespace zmq
struct fd_entry_t struct fd_entry_t
{ {
fd_t fd; fd_t fd;
zmq::i_poll_events* events; zmq::i_poll_events *events;
}; };
typedef std::vector<fd_entry_t> fd_entries_t; typedef std::vector<fd_entry_t> fd_entries_t;
#if defined ZMQ_HAVE_WINDOWS void trigger_events (const fd_entries_t &fd_entries_,
const fds_set_t &local_fds_set_,
int event_count_);
struct family_entry_t struct family_entry_t
{ {
family_entry_t (); family_entry_t ();
...@@ -121,6 +121,13 @@ namespace zmq ...@@ -121,6 +121,13 @@ namespace zmq
fds_set_t fds_set; fds_set_t fds_set;
bool retired; bool retired;
}; };
void select_family_entry (family_entry_t &family_entry_,
int max_fd_,
bool use_timeout_,
struct timeval &tv_);
#if defined ZMQ_HAVE_WINDOWS
typedef std::map<u_short, family_entry_t> family_entries_t; typedef std::map<u_short, family_entry_t> family_entries_t;
struct wsa_events_t struct wsa_events_t
...@@ -131,26 +138,28 @@ namespace zmq ...@@ -131,26 +138,28 @@ namespace zmq
// read, write, error and readwrite // read, write, error and readwrite
WSAEVENT events [4]; WSAEVENT events [4];
}; };
#endif
#if defined ZMQ_HAVE_WINDOWS
family_entries_t family_entries; family_entries_t family_entries;
// See loop for details. // See loop for details.
family_entries_t::iterator current_family_entry_it; family_entries_t::iterator current_family_entry_it;
bool try_remove_fd_entry (family_entries_t::iterator family_entry_it, bool try_remove_fd_entry (family_entries_t::iterator family_entry_it,
zmq::fd_t &handle_); zmq::fd_t &handle_);
static const size_t fd_family_cache_size = 8;
std::pair<fd_t, u_short> fd_family_cache [fd_family_cache_size];
u_short get_fd_family (fd_t fd_);
// Socket's family or AF_UNSPEC on error.
static u_short determine_fd_family (fd_t fd_);
#else #else
fd_entries_t fd_entries; // on non-Windows, we can treat all fds as one family
fds_set_t fds_set; family_entry_t family_entry;
fd_t maxfd; fd_t maxfd;
bool retired; bool retired;
#endif #endif
#if defined ZMQ_HAVE_WINDOWS
// Socket's family or AF_UNSPEC on error.
static u_short get_fd_family (fd_t fd_);
#endif
// Checks if an fd_entry_t is retired. // Checks if an fd_entry_t is retired.
static bool is_retired_fd (const fd_entry_t &entry); static bool is_retired_fd (const fd_entry_t &entry);
...@@ -163,12 +172,11 @@ namespace zmq ...@@ -163,12 +172,11 @@ namespace zmq
// Handle of the physical thread doing the I/O work. // Handle of the physical thread doing the I/O work.
thread_t worker; thread_t worker;
select_t (const select_t&); select_t (const select_t &);
const select_t &operator = (const select_t&); const select_t &operator= (const select_t &);
}; };
typedef select_t poller_t;
typedef select_t poller_t;
} }
#endif #endif
......
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