diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/devpoll.cpp | 2 | ||||
-rw-r--r-- | src/devpoll.hpp | 2 | ||||
-rw-r--r-- | src/epoll.cpp | 2 | ||||
-rw-r--r-- | src/epoll.hpp | 2 | ||||
-rw-r--r-- | src/fd.hpp | 9 | ||||
-rw-r--r-- | src/io_object.cpp | 2 | ||||
-rw-r--r-- | src/io_object.hpp | 2 | ||||
-rw-r--r-- | src/io_thread.hpp | 2 | ||||
-rw-r--r-- | src/kqueue.cpp | 2 | ||||
-rw-r--r-- | src/kqueue.hpp | 2 | ||||
-rw-r--r-- | src/poll.cpp | 16 | ||||
-rw-r--r-- | src/poll.hpp | 4 | ||||
-rw-r--r-- | src/poller_base.hpp | 2 | ||||
-rw-r--r-- | src/reaper.hpp | 2 | ||||
-rw-r--r-- | src/select.cpp | 30 | ||||
-rw-r--r-- | src/select.hpp | 2 | ||||
-rw-r--r-- | src/socket_base.hpp | 2 |
17 files changed, 43 insertions, 42 deletions
diff --git a/src/devpoll.cpp b/src/devpoll.cpp index da56a7f..2d96f26 100644 --- a/src/devpoll.cpp +++ b/src/devpoll.cpp @@ -57,7 +57,7 @@ void xs::devpoll_t::devpoll_ctl (fd_t fd_, short events_) xs_assert (rc == sizeof pfd); } -xs::devpoll_t::handle_t xs::devpoll_t::add_fd (fd_t fd_, +xs::handle_t xs::devpoll_t::add_fd (fd_t fd_, i_poll_events *reactor_) { // If the file descriptor table is too small expand it. diff --git a/src/devpoll.hpp b/src/devpoll.hpp index 4f210c4..069eb4c 100644 --- a/src/devpoll.hpp +++ b/src/devpoll.hpp @@ -43,8 +43,6 @@ namespace xs { public: - typedef fd_t handle_t; - devpoll_t (); ~devpoll_t (); diff --git a/src/epoll.cpp b/src/epoll.cpp index 354ccc4..83d9b77 100644 --- a/src/epoll.cpp +++ b/src/epoll.cpp @@ -51,7 +51,7 @@ xs::epoll_t::~epoll_t () delete *it; } -xs::epoll_t::handle_t xs::epoll_t::add_fd (fd_t fd_, i_poll_events *events_) +xs::handle_t xs::epoll_t::add_fd (fd_t fd_, i_poll_events *events_) { poll_entry_t *pe = new (std::nothrow) poll_entry_t; alloc_assert (pe); diff --git a/src/epoll.hpp b/src/epoll.hpp index 7121c25..ed33254 100644 --- a/src/epoll.hpp +++ b/src/epoll.hpp @@ -45,8 +45,6 @@ namespace xs { public: - typedef void* handle_t; - epoll_t (); ~epoll_t (); @@ -30,17 +30,26 @@ namespace xs { + #ifdef XS_HAVE_WINDOWS #if defined _MSC_VER &&_MSC_VER <= 1400 typedef UINT_PTR fd_t; enum {retired_fd = (fd_t)(~0)}; + inline void *fdtoptr (fd_t fd_) {return (void*) fd_;} + inline fd_t ptrtofd (void *ptr_) {return (fd_t) ptr_;} #else typedef SOCKET fd_t; enum {retired_fd = INVALID_SOCKET}; + inline void *fdtoptr (fd_t fd_) {return (void*) fd_;} + inline fd_t ptrtofd (void *ptr_) {return (fd_t) ptr_;} #endif #else typedef int fd_t; enum {retired_fd = -1}; + inline void *fdtoptr (fd_t fd_) {return (void*) fd_;} + inline fd_t ptrtofd (void *ptr_) {return (int) ((char*) ptr_ - (char*) 0);} #endif + } + #endif diff --git a/src/io_object.cpp b/src/io_object.cpp index 0424c63..8c4f2fe 100644 --- a/src/io_object.cpp +++ b/src/io_object.cpp @@ -52,7 +52,7 @@ void xs::io_object_t::unplug () poller = NULL; } -xs::io_object_t::handle_t xs::io_object_t::add_fd (fd_t fd_) +xs::handle_t xs::io_object_t::add_fd (fd_t fd_) { return poller->add_fd (fd_, this); } diff --git a/src/io_object.hpp b/src/io_object.hpp index ef65f75..4494a34 100644 --- a/src/io_object.hpp +++ b/src/io_object.hpp @@ -51,8 +51,6 @@ namespace xs protected: - typedef poller_t::handle_t handle_t; - // Methods to access underlying poller object. handle_t add_fd (fd_t fd_); void rm_fd (handle_t handle_); diff --git a/src/io_thread.hpp b/src/io_thread.hpp index 4a53c15..0acb60d 100644 --- a/src/io_thread.hpp +++ b/src/io_thread.hpp @@ -77,7 +77,7 @@ namespace xs mailbox_t mailbox; // Handle associated with mailbox' file descriptor. - poller_t::handle_t mailbox_handle; + handle_t mailbox_handle; // I/O multiplexing is performed using a poller object. poller_t *poller; diff --git a/src/kqueue.cpp b/src/kqueue.cpp index 62b443f..54c31d8 100644 --- a/src/kqueue.cpp +++ b/src/kqueue.cpp @@ -76,7 +76,7 @@ void xs::kqueue_t::kevent_delete (fd_t fd_, short filter_) errno_assert (rc != -1); } -xs::kqueue_t::handle_t xs::kqueue_t::add_fd (fd_t fd_, +xs::handle_t xs::kqueue_t::add_fd (fd_t fd_, i_poll_events *reactor_) { poll_entry_t *pe = new (std::nothrow) poll_entry_t; diff --git a/src/kqueue.hpp b/src/kqueue.hpp index 4ec909d..71cf3e7 100644 --- a/src/kqueue.hpp +++ b/src/kqueue.hpp @@ -44,8 +44,6 @@ namespace xs { public: - typedef void* handle_t; - kqueue_t (); ~kqueue_t (); diff --git a/src/poll.cpp b/src/poll.cpp index 48a204e..7a55379 100644 --- a/src/poll.cpp +++ b/src/poll.cpp @@ -43,7 +43,7 @@ xs::poll_t::~poll_t () worker.stop (); } -xs::poll_t::handle_t xs::poll_t::add_fd (fd_t fd_, i_poll_events *events_) +xs::handle_t xs::poll_t::add_fd (fd_t fd_, i_poll_events *events_) { // If the file descriptor table is too small expand it. fd_table_t::size_type sz = fd_table.size (); @@ -65,17 +65,17 @@ xs::poll_t::handle_t xs::poll_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::poll_t::rm_fd (handle_t handle_) { - fd_t index = fd_table [handle_].index; + int index = fd_table [ptrtofd (handle_)].index; assert (index != retired_fd); // Mark the fd as unused. pollset [index].fd = retired_fd; - fd_table [handle_].index = retired_fd; + fd_table [ptrtofd (handle_)].index = retired_fd; retired = true; // Decrease the load metric of the thread. @@ -84,25 +84,25 @@ void xs::poll_t::rm_fd (handle_t handle_) void xs::poll_t::set_pollin (handle_t handle_) { - int index = fd_table [handle_].index; + int index = fd_table [ptrtofd (handle_)].index; pollset [index].events |= POLLIN; } void xs::poll_t::reset_pollin (handle_t handle_) { - int index = fd_table [handle_].index; + int index = fd_table [ptrtofd (handle_)].index; pollset [index].events &= ~((short) POLLIN); } void xs::poll_t::set_pollout (handle_t handle_) { - int index = fd_table [handle_].index; + int index = fd_table [ptrtofd (handle_)].index; pollset [index].events |= POLLOUT; } void xs::poll_t::reset_pollout (handle_t handle_) { - int index = fd_table [handle_].index; + int index = fd_table [ptrtofd (handle_)].index; pollset [index].events &= ~((short) POLLOUT); } diff --git a/src/poll.hpp b/src/poll.hpp index 3ce959f..28bb2eb 100644 --- a/src/poll.hpp +++ b/src/poll.hpp @@ -46,8 +46,6 @@ namespace xs { public: - typedef fd_t handle_t; - poll_t (); ~poll_t (); @@ -71,7 +69,7 @@ namespace xs struct fd_entry_t { - fd_t index; + int index; xs::i_poll_events *events; }; diff --git a/src/poller_base.hpp b/src/poller_base.hpp index b1a6bf9..99a77b9 100644 --- a/src/poller_base.hpp +++ b/src/poller_base.hpp @@ -31,6 +31,8 @@ namespace xs struct i_poll_events; + typedef void* handle_t; + class poller_base_t { public: diff --git a/src/reaper.hpp b/src/reaper.hpp index 0cb31a2..3310145 100644 --- a/src/reaper.hpp +++ b/src/reaper.hpp @@ -60,7 +60,7 @@ namespace xs mailbox_t mailbox; // Handle associated with mailbox' file descriptor. - poller_t::handle_t mailbox_handle; + handle_t mailbox_handle; // I/O multiplexing is performed using a poller object. poller_t *poller; 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 () diff --git a/src/select.hpp b/src/select.hpp index b60c37d..f3f6c48 100644 --- a/src/select.hpp +++ b/src/select.hpp @@ -56,8 +56,6 @@ namespace xs { public: - typedef fd_t handle_t; - select_t (); ~select_t (); diff --git a/src/socket_base.hpp b/src/socket_base.hpp index 8b2b216..614d3d0 100644 --- a/src/socket_base.hpp +++ b/src/socket_base.hpp @@ -181,7 +181,7 @@ namespace xs // Reaper's poller and handle of this socket within it. poller_t *poller; - poller_t::handle_t handle; + handle_t handle; // Timestamp of when commands were processed the last time. uint64_t last_tsc; |