summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikael Helbo Kjaer <mhk@designtech.dk>2010-11-01 12:54:58 +0100
committerMartin Sustrik <sustrik@250bpm.com>2010-11-01 12:54:58 +0100
commit0ad71f88fe5531011c0354f22eeb070b1f729c7d (patch)
tree24ac8904724e00aac97eb0b0e75cdacec63da05c /src
parent085b709021c44673d9bf65a5d639e3c2e99703af (diff)
select now uses Erase-Remove idiom for retired fds
Signed-off-by: Mikael Helbo Kjaer <mhk@designtech.dk>
Diffstat (limited to 'src')
-rw-r--r--src/select.cpp17
-rw-r--r--src/select.hpp3
2 files changed, 11 insertions, 9 deletions
diff --git a/src/select.cpp b/src/select.cpp
index 9d0970a..78d3afd 100644
--- a/src/select.cpp
+++ b/src/select.cpp
@@ -191,15 +191,8 @@ void zmq::select_t::loop ()
// Destroy retired event sources.
if (retired) {
- fd_set_t::iterator it = fds.begin();
- while (it != fds.end()) {
- if (it->fd == retired_fd) {
- it = fds.erase(it);
- }
- else {
- it++;
- }
- }
+ fds.erase (std::remove_if (fds.begin (), fds.end (),
+ zmq::select_t::is_retired_fd), fds.end ());
retired = false;
}
}
@@ -209,3 +202,9 @@ void zmq::select_t::worker_routine (void *arg_)
{
((select_t*) arg_)->loop ();
}
+
+bool zmq::select_t::is_retired_fd (const fd_entry_t &entry)
+{
+ return (entry.fd == retired_fd);
+}
+
diff --git a/src/select.hpp b/src/select.hpp
index d4fff81..916b87b 100644
--- a/src/select.hpp
+++ b/src/select.hpp
@@ -77,6 +77,9 @@ namespace zmq
struct i_poll_events *events;
};
+ // Checks if an fd_entry_t is retired.
+ static bool is_retired_fd (const fd_entry_t &entry);
+
// Set of file descriptors that are used to retreive
// information for fd_set.
typedef std::vector <fd_entry_t> fd_set_t;