From 35797d6c69032fc9eaa472c501b7fbba8e388026 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Thu, 16 Feb 2012 10:04:30 +0900 Subject: Polling handle is a fixed type now. Polling handle type was previously dependent on polling mechanism used. Now it is void* in all cases. This patch is a first step in the long way to separate the transports from the core library. Signed-off-by: Martin Sustrik --- src/select.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/select.cpp') diff --git a/src/select.cpp b/src/select.cpp index 634e358..7f05817 100644 --- a/src/select.cpp +++ b/src/select.cpp @@ -59,7 +59,7 @@ xs::select_t::~select_t () worker.stop (); } -xs::select_t::handle_t xs::select_t::add_fd (fd_t fd_, i_poll_events *events_) +xs::handle_t xs::select_t::add_fd (fd_t fd_, i_poll_events *events_) { // Store the file descriptor. fd_entry_t entry = {fd_, events_}; @@ -79,33 +79,35 @@ xs::select_t::handle_t xs::select_t::add_fd (fd_t fd_, i_poll_events *events_) // Increase the load metric of the thread. adjust_load (1); - return fd_; + return fdtoptr (fd_); } void xs::select_t::rm_fd (handle_t handle_) { + int fd = ptrtofd (handle_); + // Mark the descriptor as retired. fd_set_t::iterator it; for (it = fds.begin (); it != fds.end (); ++it) - if (it->fd == handle_) + if (it->fd == fd) break; xs_assert (it != fds.end ()); it->fd = retired_fd; retired = true; // Stop polling on the descriptor. - FD_CLR (handle_, &source_set_in); - FD_CLR (handle_, &source_set_out); - FD_CLR (handle_, &source_set_err); + FD_CLR (fd, &source_set_in); + FD_CLR (fd, &source_set_out); + FD_CLR (fd, &source_set_err); // Discard all events generated on this file descriptor. - FD_CLR (handle_, &readfds); - FD_CLR (handle_, &writefds); - FD_CLR (handle_, &exceptfds); + FD_CLR (fd, &readfds); + FD_CLR (fd, &writefds); + FD_CLR (fd, &exceptfds); // Adjust the maxfd attribute if we have removed the // highest-numbered file descriptor. - if (handle_ == maxfd) { + if (fd == maxfd) { maxfd = retired_fd; for (fd_set_t::iterator it = fds.begin (); it != fds.end (); ++it) if (it->fd > maxfd) @@ -118,22 +120,22 @@ void xs::select_t::rm_fd (handle_t handle_) void xs::select_t::set_pollin (handle_t handle_) { - FD_SET (handle_, &source_set_in); + FD_SET (ptrtofd (handle_), &source_set_in); } void xs::select_t::reset_pollin (handle_t handle_) { - FD_CLR (handle_, &source_set_in); + FD_CLR (ptrtofd (handle_), &source_set_in); } void xs::select_t::set_pollout (handle_t handle_) { - FD_SET (handle_, &source_set_out); + FD_SET (ptrtofd (handle_), &source_set_out); } void xs::select_t::reset_pollout (handle_t handle_) { - FD_CLR (handle_, &source_set_out); + FD_CLR (ptrtofd (handle_), &source_set_out); } void xs::select_t::start () -- cgit v1.2.3