epoll_reactor.ipp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. //
  2. // detail/impl/epoll_reactor.ipp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_DETAIL_IMPL_EPOLL_REACTOR_IPP
  11. #define BOOST_ASIO_DETAIL_IMPL_EPOLL_REACTOR_IPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_HAS_EPOLL)
  17. #include <cstddef>
  18. #include <sys/epoll.h>
  19. #include <boost/asio/detail/epoll_reactor.hpp>
  20. #include <boost/asio/detail/throw_error.hpp>
  21. #include <boost/asio/error.hpp>
  22. #if defined(BOOST_ASIO_HAS_TIMERFD)
  23. # include <sys/timerfd.h>
  24. #endif // defined(BOOST_ASIO_HAS_TIMERFD)
  25. #include <boost/asio/detail/push_options.hpp>
  26. namespace boost {
  27. namespace asio {
  28. namespace detail {
  29. epoll_reactor::epoll_reactor(boost::asio::io_service& io_service)
  30. : boost::asio::detail::service_base<epoll_reactor>(io_service),
  31. io_service_(use_service<io_service_impl>(io_service)),
  32. mutex_(),
  33. interrupter_(),
  34. epoll_fd_(do_epoll_create()),
  35. timer_fd_(do_timerfd_create()),
  36. shutdown_(false)
  37. {
  38. // Add the interrupter's descriptor to epoll.
  39. epoll_event ev = { 0, { 0 } };
  40. ev.events = EPOLLIN | EPOLLERR | EPOLLET;
  41. ev.data.ptr = &interrupter_;
  42. epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, interrupter_.read_descriptor(), &ev);
  43. interrupter_.interrupt();
  44. // Add the timer descriptor to epoll.
  45. if (timer_fd_ != -1)
  46. {
  47. ev.events = EPOLLIN | EPOLLERR;
  48. ev.data.ptr = &timer_fd_;
  49. epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, timer_fd_, &ev);
  50. }
  51. }
  52. epoll_reactor::~epoll_reactor()
  53. {
  54. if (epoll_fd_ != -1)
  55. close(epoll_fd_);
  56. if (timer_fd_ != -1)
  57. close(timer_fd_);
  58. }
  59. void epoll_reactor::shutdown_service()
  60. {
  61. mutex::scoped_lock lock(mutex_);
  62. shutdown_ = true;
  63. lock.unlock();
  64. op_queue<operation> ops;
  65. while (descriptor_state* state = registered_descriptors_.first())
  66. {
  67. for (int i = 0; i < max_ops; ++i)
  68. ops.push(state->op_queue_[i]);
  69. state->shutdown_ = true;
  70. registered_descriptors_.free(state);
  71. }
  72. timer_queues_.get_all_timers(ops);
  73. io_service_.abandon_operations(ops);
  74. }
  75. void epoll_reactor::fork_service(boost::asio::io_service::fork_event fork_ev)
  76. {
  77. if (fork_ev == boost::asio::io_service::fork_child)
  78. {
  79. if (epoll_fd_ != -1)
  80. ::close(epoll_fd_);
  81. epoll_fd_ = -1;
  82. epoll_fd_ = do_epoll_create();
  83. if (timer_fd_ != -1)
  84. ::close(timer_fd_);
  85. timer_fd_ = -1;
  86. timer_fd_ = do_timerfd_create();
  87. interrupter_.recreate();
  88. // Add the interrupter's descriptor to epoll.
  89. epoll_event ev = { 0, { 0 } };
  90. ev.events = EPOLLIN | EPOLLERR | EPOLLET;
  91. ev.data.ptr = &interrupter_;
  92. epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, interrupter_.read_descriptor(), &ev);
  93. interrupter_.interrupt();
  94. // Add the timer descriptor to epoll.
  95. if (timer_fd_ != -1)
  96. {
  97. ev.events = EPOLLIN | EPOLLERR;
  98. ev.data.ptr = &timer_fd_;
  99. epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, timer_fd_, &ev);
  100. }
  101. update_timeout();
  102. // Re-register all descriptors with epoll.
  103. mutex::scoped_lock descriptors_lock(registered_descriptors_mutex_);
  104. for (descriptor_state* state = registered_descriptors_.first();
  105. state != 0; state = state->next_)
  106. {
  107. ev.events = state->registered_events_;
  108. ev.data.ptr = state;
  109. int result = epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, state->descriptor_, &ev);
  110. if (result != 0)
  111. {
  112. boost::system::error_code ec(errno,
  113. boost::asio::error::get_system_category());
  114. boost::asio::detail::throw_error(ec, "epoll re-registration");
  115. }
  116. }
  117. }
  118. }
  119. void epoll_reactor::init_task()
  120. {
  121. io_service_.init_task();
  122. }
  123. int epoll_reactor::register_descriptor(socket_type descriptor,
  124. epoll_reactor::per_descriptor_data& descriptor_data)
  125. {
  126. descriptor_data = allocate_descriptor_state();
  127. {
  128. mutex::scoped_lock descriptor_lock(descriptor_data->mutex_);
  129. descriptor_data->reactor_ = this;
  130. descriptor_data->descriptor_ = descriptor;
  131. descriptor_data->shutdown_ = false;
  132. }
  133. epoll_event ev = { 0, { 0 } };
  134. ev.events = EPOLLIN | EPOLLERR | EPOLLHUP | EPOLLPRI | EPOLLET;
  135. descriptor_data->registered_events_ = ev.events;
  136. ev.data.ptr = descriptor_data;
  137. int result = epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, descriptor, &ev);
  138. if (result != 0)
  139. return errno;
  140. return 0;
  141. }
  142. int epoll_reactor::register_internal_descriptor(
  143. int op_type, socket_type descriptor,
  144. epoll_reactor::per_descriptor_data& descriptor_data, reactor_op* op)
  145. {
  146. descriptor_data = allocate_descriptor_state();
  147. {
  148. mutex::scoped_lock descriptor_lock(descriptor_data->mutex_);
  149. descriptor_data->reactor_ = this;
  150. descriptor_data->descriptor_ = descriptor;
  151. descriptor_data->shutdown_ = false;
  152. descriptor_data->op_queue_[op_type].push(op);
  153. }
  154. epoll_event ev = { 0, { 0 } };
  155. ev.events = EPOLLIN | EPOLLERR | EPOLLHUP | EPOLLPRI | EPOLLET;
  156. descriptor_data->registered_events_ = ev.events;
  157. ev.data.ptr = descriptor_data;
  158. int result = epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, descriptor, &ev);
  159. if (result != 0)
  160. return errno;
  161. return 0;
  162. }
  163. void epoll_reactor::move_descriptor(socket_type,
  164. epoll_reactor::per_descriptor_data& target_descriptor_data,
  165. epoll_reactor::per_descriptor_data& source_descriptor_data)
  166. {
  167. target_descriptor_data = source_descriptor_data;
  168. source_descriptor_data = 0;
  169. }
  170. void epoll_reactor::start_op(int op_type, socket_type descriptor,
  171. epoll_reactor::per_descriptor_data& descriptor_data, reactor_op* op,
  172. bool is_continuation, bool allow_speculative)
  173. {
  174. if (!descriptor_data)
  175. {
  176. op->ec_ = boost::asio::error::bad_descriptor;
  177. post_immediate_completion(op, is_continuation);
  178. return;
  179. }
  180. mutex::scoped_lock descriptor_lock(descriptor_data->mutex_);
  181. if (descriptor_data->shutdown_)
  182. {
  183. post_immediate_completion(op, is_continuation);
  184. return;
  185. }
  186. if (descriptor_data->op_queue_[op_type].empty())
  187. {
  188. if (allow_speculative
  189. && (op_type != read_op
  190. || descriptor_data->op_queue_[except_op].empty()))
  191. {
  192. if (op->perform())
  193. {
  194. descriptor_lock.unlock();
  195. io_service_.post_immediate_completion(op, is_continuation);
  196. return;
  197. }
  198. if (op_type == write_op)
  199. {
  200. if ((descriptor_data->registered_events_ & EPOLLOUT) == 0)
  201. {
  202. epoll_event ev = { 0, { 0 } };
  203. ev.events = descriptor_data->registered_events_ | EPOLLOUT;
  204. ev.data.ptr = descriptor_data;
  205. if (epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev) == 0)
  206. {
  207. descriptor_data->registered_events_ |= ev.events;
  208. }
  209. else
  210. {
  211. op->ec_ = boost::system::error_code(errno,
  212. boost::asio::error::get_system_category());
  213. io_service_.post_immediate_completion(op, is_continuation);
  214. return;
  215. }
  216. }
  217. }
  218. }
  219. else
  220. {
  221. if (op_type == write_op)
  222. {
  223. descriptor_data->registered_events_ |= EPOLLOUT;
  224. }
  225. epoll_event ev = { 0, { 0 } };
  226. ev.events = descriptor_data->registered_events_;
  227. ev.data.ptr = descriptor_data;
  228. epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev);
  229. }
  230. }
  231. descriptor_data->op_queue_[op_type].push(op);
  232. io_service_.work_started();
  233. }
  234. void epoll_reactor::cancel_ops(socket_type,
  235. epoll_reactor::per_descriptor_data& descriptor_data)
  236. {
  237. if (!descriptor_data)
  238. return;
  239. mutex::scoped_lock descriptor_lock(descriptor_data->mutex_);
  240. op_queue<operation> ops;
  241. for (int i = 0; i < max_ops; ++i)
  242. {
  243. while (reactor_op* op = descriptor_data->op_queue_[i].front())
  244. {
  245. op->ec_ = boost::asio::error::operation_aborted;
  246. descriptor_data->op_queue_[i].pop();
  247. ops.push(op);
  248. }
  249. }
  250. descriptor_lock.unlock();
  251. io_service_.post_deferred_completions(ops);
  252. }
  253. void epoll_reactor::deregister_descriptor(socket_type descriptor,
  254. epoll_reactor::per_descriptor_data& descriptor_data, bool closing)
  255. {
  256. if (!descriptor_data)
  257. return;
  258. mutex::scoped_lock descriptor_lock(descriptor_data->mutex_);
  259. if (!descriptor_data->shutdown_)
  260. {
  261. if (closing)
  262. {
  263. // The descriptor will be automatically removed from the epoll set when
  264. // it is closed.
  265. }
  266. else
  267. {
  268. epoll_event ev = { 0, { 0 } };
  269. epoll_ctl(epoll_fd_, EPOLL_CTL_DEL, descriptor, &ev);
  270. }
  271. op_queue<operation> ops;
  272. for (int i = 0; i < max_ops; ++i)
  273. {
  274. while (reactor_op* op = descriptor_data->op_queue_[i].front())
  275. {
  276. op->ec_ = boost::asio::error::operation_aborted;
  277. descriptor_data->op_queue_[i].pop();
  278. ops.push(op);
  279. }
  280. }
  281. descriptor_data->descriptor_ = -1;
  282. descriptor_data->shutdown_ = true;
  283. descriptor_lock.unlock();
  284. free_descriptor_state(descriptor_data);
  285. descriptor_data = 0;
  286. io_service_.post_deferred_completions(ops);
  287. }
  288. }
  289. void epoll_reactor::deregister_internal_descriptor(socket_type descriptor,
  290. epoll_reactor::per_descriptor_data& descriptor_data)
  291. {
  292. if (!descriptor_data)
  293. return;
  294. mutex::scoped_lock descriptor_lock(descriptor_data->mutex_);
  295. if (!descriptor_data->shutdown_)
  296. {
  297. epoll_event ev = { 0, { 0 } };
  298. epoll_ctl(epoll_fd_, EPOLL_CTL_DEL, descriptor, &ev);
  299. op_queue<operation> ops;
  300. for (int i = 0; i < max_ops; ++i)
  301. ops.push(descriptor_data->op_queue_[i]);
  302. descriptor_data->descriptor_ = -1;
  303. descriptor_data->shutdown_ = true;
  304. descriptor_lock.unlock();
  305. free_descriptor_state(descriptor_data);
  306. descriptor_data = 0;
  307. }
  308. }
  309. void epoll_reactor::run(bool block, op_queue<operation>& ops)
  310. {
  311. // This code relies on the fact that the task_io_service queues the reactor
  312. // task behind all descriptor operations generated by this function. This
  313. // means, that by the time we reach this point, any previously returned
  314. // descriptor operations have already been dequeued. Therefore it is now safe
  315. // for us to reuse and return them for the task_io_service to queue again.
  316. // Calculate a timeout only if timerfd is not used.
  317. int timeout;
  318. if (timer_fd_ != -1)
  319. timeout = block ? -1 : 0;
  320. else
  321. {
  322. mutex::scoped_lock lock(mutex_);
  323. timeout = block ? get_timeout() : 0;
  324. }
  325. // Block on the epoll descriptor.
  326. epoll_event events[128];
  327. int num_events = epoll_wait(epoll_fd_, events, 128, timeout);
  328. #if defined(BOOST_ASIO_HAS_TIMERFD)
  329. bool check_timers = (timer_fd_ == -1);
  330. #else // defined(BOOST_ASIO_HAS_TIMERFD)
  331. bool check_timers = true;
  332. #endif // defined(BOOST_ASIO_HAS_TIMERFD)
  333. // Dispatch the waiting events.
  334. for (int i = 0; i < num_events; ++i)
  335. {
  336. void* ptr = events[i].data.ptr;
  337. if (ptr == &interrupter_)
  338. {
  339. // No need to reset the interrupter since we're leaving the descriptor
  340. // in a ready-to-read state and relying on edge-triggered notifications
  341. // to make it so that we only get woken up when the descriptor's epoll
  342. // registration is updated.
  343. #if defined(BOOST_ASIO_HAS_TIMERFD)
  344. if (timer_fd_ == -1)
  345. check_timers = true;
  346. #else // defined(BOOST_ASIO_HAS_TIMERFD)
  347. check_timers = true;
  348. #endif // defined(BOOST_ASIO_HAS_TIMERFD)
  349. }
  350. #if defined(BOOST_ASIO_HAS_TIMERFD)
  351. else if (ptr == &timer_fd_)
  352. {
  353. check_timers = true;
  354. }
  355. #endif // defined(BOOST_ASIO_HAS_TIMERFD)
  356. else
  357. {
  358. // The descriptor operation doesn't count as work in and of itself, so we
  359. // don't call work_started() here. This still allows the io_service to
  360. // stop if the only remaining operations are descriptor operations.
  361. descriptor_state* descriptor_data = static_cast<descriptor_state*>(ptr);
  362. descriptor_data->set_ready_events(events[i].events);
  363. ops.push(descriptor_data);
  364. }
  365. }
  366. if (check_timers)
  367. {
  368. mutex::scoped_lock common_lock(mutex_);
  369. timer_queues_.get_ready_timers(ops);
  370. #if defined(BOOST_ASIO_HAS_TIMERFD)
  371. if (timer_fd_ != -1)
  372. {
  373. itimerspec new_timeout;
  374. itimerspec old_timeout;
  375. int flags = get_timeout(new_timeout);
  376. timerfd_settime(timer_fd_, flags, &new_timeout, &old_timeout);
  377. }
  378. #endif // defined(BOOST_ASIO_HAS_TIMERFD)
  379. }
  380. }
  381. void epoll_reactor::interrupt()
  382. {
  383. epoll_event ev = { 0, { 0 } };
  384. ev.events = EPOLLIN | EPOLLERR | EPOLLET;
  385. ev.data.ptr = &interrupter_;
  386. epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, interrupter_.read_descriptor(), &ev);
  387. }
  388. int epoll_reactor::do_epoll_create()
  389. {
  390. #if defined(EPOLL_CLOEXEC)
  391. int fd = epoll_create1(EPOLL_CLOEXEC);
  392. #else // defined(EPOLL_CLOEXEC)
  393. int fd = -1;
  394. errno = EINVAL;
  395. #endif // defined(EPOLL_CLOEXEC)
  396. if (fd == -1 && (errno == EINVAL || errno == ENOSYS))
  397. {
  398. fd = epoll_create(epoll_size);
  399. if (fd != -1)
  400. ::fcntl(fd, F_SETFD, FD_CLOEXEC);
  401. }
  402. if (fd == -1)
  403. {
  404. boost::system::error_code ec(errno,
  405. boost::asio::error::get_system_category());
  406. boost::asio::detail::throw_error(ec, "epoll");
  407. }
  408. return fd;
  409. }
  410. int epoll_reactor::do_timerfd_create()
  411. {
  412. #if defined(BOOST_ASIO_HAS_TIMERFD)
  413. # if defined(TFD_CLOEXEC)
  414. int fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
  415. # else // defined(TFD_CLOEXEC)
  416. int fd = -1;
  417. errno = EINVAL;
  418. # endif // defined(TFD_CLOEXEC)
  419. if (fd == -1 && errno == EINVAL)
  420. {
  421. fd = timerfd_create(CLOCK_MONOTONIC, 0);
  422. if (fd != -1)
  423. ::fcntl(fd, F_SETFD, FD_CLOEXEC);
  424. }
  425. return fd;
  426. #else // defined(BOOST_ASIO_HAS_TIMERFD)
  427. return -1;
  428. #endif // defined(BOOST_ASIO_HAS_TIMERFD)
  429. }
  430. epoll_reactor::descriptor_state* epoll_reactor::allocate_descriptor_state()
  431. {
  432. mutex::scoped_lock descriptors_lock(registered_descriptors_mutex_);
  433. return registered_descriptors_.alloc();
  434. }
  435. void epoll_reactor::free_descriptor_state(epoll_reactor::descriptor_state* s)
  436. {
  437. mutex::scoped_lock descriptors_lock(registered_descriptors_mutex_);
  438. registered_descriptors_.free(s);
  439. }
  440. void epoll_reactor::do_add_timer_queue(timer_queue_base& queue)
  441. {
  442. mutex::scoped_lock lock(mutex_);
  443. timer_queues_.insert(&queue);
  444. }
  445. void epoll_reactor::do_remove_timer_queue(timer_queue_base& queue)
  446. {
  447. mutex::scoped_lock lock(mutex_);
  448. timer_queues_.erase(&queue);
  449. }
  450. void epoll_reactor::update_timeout()
  451. {
  452. #if defined(BOOST_ASIO_HAS_TIMERFD)
  453. if (timer_fd_ != -1)
  454. {
  455. itimerspec new_timeout;
  456. itimerspec old_timeout;
  457. int flags = get_timeout(new_timeout);
  458. timerfd_settime(timer_fd_, flags, &new_timeout, &old_timeout);
  459. return;
  460. }
  461. #endif // defined(BOOST_ASIO_HAS_TIMERFD)
  462. interrupt();
  463. }
  464. int epoll_reactor::get_timeout()
  465. {
  466. // By default we will wait no longer than 5 minutes. This will ensure that
  467. // any changes to the system clock are detected after no longer than this.
  468. return timer_queues_.wait_duration_msec(5 * 60 * 1000);
  469. }
  470. #if defined(BOOST_ASIO_HAS_TIMERFD)
  471. int epoll_reactor::get_timeout(itimerspec& ts)
  472. {
  473. ts.it_interval.tv_sec = 0;
  474. ts.it_interval.tv_nsec = 0;
  475. long usec = timer_queues_.wait_duration_usec(5 * 60 * 1000 * 1000);
  476. ts.it_value.tv_sec = usec / 1000000;
  477. ts.it_value.tv_nsec = usec ? (usec % 1000000) * 1000 : 1;
  478. return usec ? 0 : TFD_TIMER_ABSTIME;
  479. }
  480. #endif // defined(BOOST_ASIO_HAS_TIMERFD)
  481. struct epoll_reactor::perform_io_cleanup_on_block_exit
  482. {
  483. explicit perform_io_cleanup_on_block_exit(epoll_reactor* r)
  484. : reactor_(r), first_op_(0)
  485. {
  486. }
  487. ~perform_io_cleanup_on_block_exit()
  488. {
  489. if (first_op_)
  490. {
  491. // Post the remaining completed operations for invocation.
  492. if (!ops_.empty())
  493. reactor_->io_service_.post_deferred_completions(ops_);
  494. // A user-initiated operation has completed, but there's no need to
  495. // explicitly call work_finished() here. Instead, we'll take advantage of
  496. // the fact that the task_io_service will call work_finished() once we
  497. // return.
  498. }
  499. else
  500. {
  501. // No user-initiated operations have completed, so we need to compensate
  502. // for the work_finished() call that the task_io_service will make once
  503. // this operation returns.
  504. reactor_->io_service_.work_started();
  505. }
  506. }
  507. epoll_reactor* reactor_;
  508. op_queue<operation> ops_;
  509. operation* first_op_;
  510. };
  511. epoll_reactor::descriptor_state::descriptor_state()
  512. : operation(&epoll_reactor::descriptor_state::do_complete)
  513. {
  514. }
  515. operation* epoll_reactor::descriptor_state::perform_io(uint32_t events)
  516. {
  517. mutex_.lock();
  518. perform_io_cleanup_on_block_exit io_cleanup(reactor_);
  519. mutex::scoped_lock descriptor_lock(mutex_, mutex::scoped_lock::adopt_lock);
  520. // Exception operations must be processed first to ensure that any
  521. // out-of-band data is read before normal data.
  522. static const int flag[max_ops] = { EPOLLIN, EPOLLOUT, EPOLLPRI };
  523. for (int j = max_ops - 1; j >= 0; --j)
  524. {
  525. if (events & (flag[j] | EPOLLERR | EPOLLHUP))
  526. {
  527. while (reactor_op* op = op_queue_[j].front())
  528. {
  529. if (op->perform())
  530. {
  531. op_queue_[j].pop();
  532. io_cleanup.ops_.push(op);
  533. }
  534. else
  535. break;
  536. }
  537. }
  538. }
  539. // The first operation will be returned for completion now. The others will
  540. // be posted for later by the io_cleanup object's destructor.
  541. io_cleanup.first_op_ = io_cleanup.ops_.front();
  542. io_cleanup.ops_.pop();
  543. return io_cleanup.first_op_;
  544. }
  545. void epoll_reactor::descriptor_state::do_complete(
  546. io_service_impl* owner, operation* base,
  547. const boost::system::error_code& ec, std::size_t bytes_transferred)
  548. {
  549. if (owner)
  550. {
  551. descriptor_state* descriptor_data = static_cast<descriptor_state*>(base);
  552. uint32_t events = static_cast<uint32_t>(bytes_transferred);
  553. if (operation* op = descriptor_data->perform_io(events))
  554. {
  555. op->complete(*owner, ec, 0);
  556. }
  557. }
  558. }
  559. } // namespace detail
  560. } // namespace asio
  561. } // namespace boost
  562. #include <boost/asio/detail/pop_options.hpp>
  563. #endif // defined(BOOST_ASIO_HAS_EPOLL)
  564. #endif // BOOST_ASIO_DETAIL_IMPL_EPOLL_REACTOR_IPP