Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78667 - in trunk/boost/asio/detail: . impl
From: chris_at_[hidden]
Date: 2012-05-26 18:28:34


Author: chris_kohlhoff
Date: 2012-05-26 18:28:34 EDT (Sat, 26 May 2012)
New Revision: 78667
URL: http://svn.boost.org/trac/boost/changeset/78667

Log:
Added lazy registration for EPOLLOUT.
Text files modified:
   trunk/boost/asio/detail/epoll_reactor.hpp | 2 ++
   trunk/boost/asio/detail/impl/epoll_reactor.ipp | 37 ++++++++++++++++++++++++++++++++-----
   2 files changed, 34 insertions(+), 5 deletions(-)

Modified: trunk/boost/asio/detail/epoll_reactor.hpp
==============================================================================
--- trunk/boost/asio/detail/epoll_reactor.hpp (original)
+++ trunk/boost/asio/detail/epoll_reactor.hpp 2012-05-26 18:28:34 EDT (Sat, 26 May 2012)
@@ -19,6 +19,7 @@
 
 #if defined(BOOST_ASIO_HAS_EPOLL)
 
+#include <boost/cstdint.hpp>
 #include <boost/limits.hpp>
 #include <boost/asio/io_service.hpp>
 #include <boost/asio/detail/atomic_count.hpp>
@@ -59,6 +60,7 @@
     mutex mutex_;
     epoll_reactor* reactor_;
     int descriptor_;
+ boost::uint32_t registered_events_;
     op_queue<reactor_op> op_queue_[max_ops];
     bool shutdown_;
 

Modified: trunk/boost/asio/detail/impl/epoll_reactor.ipp
==============================================================================
--- trunk/boost/asio/detail/impl/epoll_reactor.ipp (original)
+++ trunk/boost/asio/detail/impl/epoll_reactor.ipp 2012-05-26 18:28:34 EDT (Sat, 26 May 2012)
@@ -127,7 +127,7 @@
     for (descriptor_state* state = registered_descriptors_.first();
         state != 0; state = state->next_)
     {
- ev.events = EPOLLIN | EPOLLERR | EPOLLHUP | EPOLLOUT | EPOLLPRI | EPOLLET;
+ ev.events = state->registered_events_;
       ev.data.ptr = state;
       int result = epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, state->descriptor_, &ev);
       if (result != 0)
@@ -159,7 +159,8 @@
   }
 
   epoll_event ev = { 0, { 0 } };
- ev.events = EPOLLIN | EPOLLERR | EPOLLHUP | EPOLLOUT | EPOLLPRI | EPOLLET;
+ ev.events = EPOLLIN | EPOLLERR | EPOLLHUP | EPOLLPRI | EPOLLET;
+ descriptor_data->registered_events_ = ev.events;
   ev.data.ptr = descriptor_data;
   int result = epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, descriptor, &ev);
   if (result != 0)
@@ -184,7 +185,8 @@
   }
 
   epoll_event ev = { 0, { 0 } };
- ev.events = EPOLLIN | EPOLLERR | EPOLLHUP | EPOLLOUT | EPOLLPRI | EPOLLET;
+ ev.events = EPOLLIN | EPOLLERR | EPOLLHUP | EPOLLPRI | EPOLLET;
+ descriptor_data->registered_events_ = ev.events;
   ev.data.ptr = descriptor_data;
   int result = epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, descriptor, &ev);
   if (result != 0)
@@ -232,12 +234,37 @@
         io_service_.post_immediate_completion(op);
         return;
       }
+
+ if (op_type == write_op)
+ {
+ if ((descriptor_data->registered_events_ & EPOLLOUT) == 0)
+ {
+ epoll_event ev = { 0, { 0 } };
+ ev.events = descriptor_data->registered_events_ | EPOLLOUT;
+ ev.data.ptr = descriptor_data;
+ if (epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev) == 0)
+ {
+ descriptor_data->registered_events_ |= ev.events;
+ }
+ else
+ {
+ op->ec_ = boost::system::error_code(errno,
+ boost::asio::error::get_system_category());
+ io_service_.post_immediate_completion(op);
+ return;
+ }
+ }
+ }
     }
     else
     {
+ if (op_type == write_op)
+ {
+ descriptor_data->registered_events_ |= EPOLLOUT;
+ }
+
       epoll_event ev = { 0, { 0 } };
- ev.events = EPOLLIN | EPOLLERR | EPOLLHUP
- | EPOLLOUT | EPOLLPRI | EPOLLET;
+ ev.events = descriptor_data->registered_events_;
       ev.data.ptr = descriptor_data;
       epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev);
     }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk