11 #ifndef ASIO_IO_CONTEXT_HPP 12 #define ASIO_IO_CONTEXT_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 18 #include "asio/detail/config.hpp" 22 #include "asio/async_result.hpp" 23 #include "asio/detail/wrapped_handler.hpp" 24 #include "asio/error_code.hpp" 25 #include "asio/execution.hpp" 26 #include "asio/execution_context.hpp" 28 #if defined(ASIO_HAS_CHRONO) 29 # include "asio/detail/chrono.hpp" 30 #endif // defined(ASIO_HAS_CHRONO) 32 #if defined(ASIO_WINDOWS) || defined(__CYGWIN__) 33 # include "asio/detail/winsock_init.hpp" 34 #elif defined(__sun) || defined(__QNX__) || defined(__hpux) || defined(_AIX) \ 36 # include "asio/detail/signal_init.hpp" 39 #if defined(ASIO_HAS_IOCP) 40 # include "asio/detail/win_iocp_io_context.hpp" 42 # include "asio/detail/scheduler.hpp" 45 #include "asio/detail/push_options.hpp" 50 #if defined(ASIO_HAS_IOCP) 51 typedef win_iocp_io_context io_context_impl;
52 class win_iocp_overlapped_ptr;
54 typedef scheduler io_context_impl;
59 ASIO_STATIC_CONSTEXPR(
unsigned int, blocking_never = 1);
60 ASIO_STATIC_CONSTEXPR(
unsigned int, relationship_continuation = 2);
61 ASIO_STATIC_CONSTEXPR(
unsigned int, outstanding_work_tracked = 4);
216 #if defined(ASIO_HAS_IOCP) 217 friend class detail::win_iocp_overlapped_ptr;
221 template <
typename Allocator,
unsigned int Bits>
224 template <
typename Allocator,
unsigned int Bits>
230 #if !defined(ASIO_NO_DEPRECATED) 233 #endif // !defined(ASIO_NO_DEPRECATED) 237 #if !defined(ASIO_NO_EXTENSIONS) \ 238 && !defined(ASIO_NO_TS_EXECUTORS) 240 #endif // !defined(ASIO_NO_EXTENSIONS) 256 ASIO_DECL
explicit io_context(
int concurrency_hint);
293 executor_type get_executor() ASIO_NOEXCEPT;
320 ASIO_DECL count_type run();
322 #if !defined(ASIO_NO_DEPRECATED) 352 #endif // !defined(ASIO_NO_DEPRECATED) 354 #if defined(ASIO_HAS_CHRONO) || defined(GENERATING_DOCUMENTATION) 366 template <
typename Rep,
typename Period>
367 std::size_t run_for(
const chrono::duration<Rep, Period>& rel_time);
379 template <
typename Clock,
typename Duration>
380 std::size_t run_until(
const chrono::time_point<Clock, Duration>& abs_time);
381 #endif // defined(ASIO_HAS_CHRONO) || defined(GENERATING_DOCUMENTATION) 400 ASIO_DECL count_type run_one();
402 #if !defined(ASIO_NO_DEPRECATED) 423 #endif // !defined(ASIO_NO_DEPRECATED) 425 #if defined(ASIO_HAS_CHRONO) || defined(GENERATING_DOCUMENTATION) 437 template <
typename Rep,
typename Period>
438 std::size_t run_one_for(
const chrono::duration<Rep, Period>& rel_time);
451 template <
typename Clock,
typename Duration>
452 std::size_t run_one_until(
453 const chrono::time_point<Clock, Duration>& abs_time);
454 #endif // defined(ASIO_HAS_CHRONO) || defined(GENERATING_DOCUMENTATION) 464 ASIO_DECL count_type poll();
466 #if !defined(ASIO_NO_DEPRECATED) 478 #endif // !defined(ASIO_NO_DEPRECATED) 488 ASIO_DECL count_type poll_one();
490 #if !defined(ASIO_NO_DEPRECATED) 502 #endif // !defined(ASIO_NO_DEPRECATED) 511 ASIO_DECL
void stop();
523 ASIO_DECL
bool stopped()
const;
536 ASIO_DECL
void restart();
538 #if !defined(ASIO_NO_DEPRECATED) 575 template <
typename LegacyCompletionHandler>
577 dispatch(ASIO_MOVE_ARG(LegacyCompletionHandler) handler);
602 template <typename LegacyCompletionHandler>
604 post(ASIO_MOVE_ARG(LegacyCompletionHandler) handler);
628 template <typename Handler>
629 #if defined(GENERATING_DOCUMENTATION) 634 wrap(Handler handler);
635 #endif // !defined(ASIO_NO_DEPRECATED) 641 #if !defined(ASIO_NO_DEPRECATED) 644 #endif // !defined(ASIO_NO_DEPRECATED) 647 ASIO_DECL impl_type& add_impl(impl_type* impl);
651 template <
typename Service>
654 #if defined(ASIO_WINDOWS) || defined(__CYGWIN__) 655 detail::winsock_init<> init_;
656 #elif defined(__sun) || defined(__QNX__) || defined(__hpux) || defined(_AIX) \ 670 template <
typename Allocator,
unsigned int Bits>
677 : io_context_(other.io_context_),
678 allocator_(other.allocator_),
681 if (Bits & outstanding_work_tracked)
683 io_context_->impl_.work_started();
686 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 689 : io_context_(other.io_context_),
690 allocator_(ASIO_MOVE_CAST(Allocator)(other.allocator_)),
693 if (Bits & outstanding_work_tracked)
694 other.io_context_ = 0;
696 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 701 if (Bits & outstanding_work_tracked)
703 io_context_->impl_.work_finished();
710 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 714 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 730 allocator_, bits_ & ~blocking_never);
747 allocator_, bits_ | blocking_never);
764 allocator_, bits_ & ~relationship_continuation);
781 allocator_, bits_ | relationship_continuation);
795 ASIO_UNSPECIFIED(Bits | outstanding_work_tracked)>
799 io_context_, allocator_, bits_);
813 ASIO_UNSPECIFIED(Bits & ~outstanding_work_tracked)>
817 io_context_, allocator_, bits_);
830 template <
typename OtherAllocator>
835 io_context_, a.value(), bits_);
848 ASIO_CONSTEXPR basic_executor_type<std::allocator<void>, Bits>
851 return basic_executor_type<std::allocator<void>, Bits>(
852 io_context_, std::allocator<void>(), bits_);
869 return execution::mapping.thread;
901 return (bits_ & blocking_never)
920 return (bits_ & relationship_continuation)
939 return (Bits & outstanding_work_tracked)
954 template <
typename OtherAllocator>
982 bool running_in_this_thread()
const ASIO_NOEXCEPT;
991 return a.io_context_ == b.io_context_
992 && a.allocator_ == b.allocator_
993 && a.bits_ == b.bits_;
1003 return a.io_context_ != b.io_context_
1004 || a.allocator_ != b.allocator_
1005 || a.bits_ != b.bits_;
1017 template <
typename Function>
1018 void execute(ASIO_MOVE_ARG(Function) f)
const;
1020 #if !defined(ASIO_NO_TS_EXECUTORS) 1030 void on_work_started()
const ASIO_NOEXCEPT;
1038 void on_work_finished()
const ASIO_NOEXCEPT;
1054 template <
typename Function,
typename OtherAllocator>
1055 void dispatch(ASIO_MOVE_ARG(Function) f,
1056 const OtherAllocator& a)
const;
1071 template <
typename Function,
typename OtherAllocator>
1072 void post(ASIO_MOVE_ARG(Function) f,
1073 const OtherAllocator& a)
const;
1092 template <
typename Function,
typename OtherAllocator>
1093 void defer(ASIO_MOVE_ARG(Function) f,
1094 const OtherAllocator& a)
const;
1095 #endif // !defined(ASIO_NO_TS_EXECUTORS) 1107 if (Bits & outstanding_work_tracked)
1108 io_context_->impl_.work_started();
1113 const Allocator& a,
unsigned int bits) ASIO_NOEXCEPT
1118 if (Bits & outstanding_work_tracked)
1120 io_context_->impl_.work_started();
1127 Allocator allocator_;
1133 #if !defined(ASIO_NO_DEPRECATED) 1177 void operator=(
const work& other);
1182 #endif // !defined(ASIO_NO_DEPRECATED) 1194 ASIO_DECL
virtual void shutdown();
1196 #if !defined(ASIO_NO_DEPRECATED) 1197 ASIO_DECL
virtual void shutdown_service();
1200 #endif // !defined(ASIO_NO_DEPRECATED) 1208 ASIO_DECL
virtual void notify_fork(
1211 #if !defined(ASIO_NO_DEPRECATED) 1218 ASIO_DECL
virtual void fork_service(
1220 #endif // !defined(ASIO_NO_DEPRECATED) 1230 ASIO_DECL
virtual ~service();
1236 template <
typename Type>
1250 template <
typename Type>
1255 #if !defined(GENERATING_DOCUMENTATION) 1259 #if !defined(ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) 1261 template <
typename Allocator,
unsigned int Bits>
1266 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1267 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
true);
1270 #endif // !defined(ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) 1272 #if !defined(ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) 1274 template <
typename Allocator,
unsigned int Bits,
typename Function>
1280 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1281 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
false);
1282 typedef void result_type;
1285 #endif // !defined(ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) 1287 #if !defined(ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT) 1289 template <
typename Allocator,
unsigned int Bits>
1295 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1296 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
false);
1301 template <
typename Allocator,
unsigned int Bits>
1307 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1308 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
false);
1313 template <
typename Allocator,
unsigned int Bits>
1319 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1320 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
false);
1325 template <
typename Allocator,
unsigned int Bits>
1331 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1332 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
false);
1337 template <
typename Allocator,
unsigned int Bits>
1343 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1344 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
false);
1346 Allocator, Bits | outstanding_work_tracked>
result_type;
1349 template <
typename Allocator,
unsigned int Bits>
1355 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1356 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
false);
1358 Allocator, Bits & ~outstanding_work_tracked>
result_type;
1361 template <
typename Allocator,
unsigned int Bits>
1367 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1368 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
false);
1373 template <
unsigned int Bits,
1374 typename Allocator,
typename OtherAllocator>
1380 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1381 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
false);
1386 #endif // !defined(ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT) 1388 #if !defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT) 1390 template <
typename Allocator,
unsigned int Bits,
typename Property>
1395 asio::is_convertible<
1397 asio::execution::outstanding_work_t
1402 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1403 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
true);
1406 static ASIO_CONSTEXPR result_type value() ASIO_NOEXCEPT
1408 return (Bits & outstanding_work_tracked)
1414 template <
typename Allocator,
unsigned int Bits,
typename Property>
1419 asio::is_convertible<
1421 asio::execution::mapping_t
1426 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1427 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
true);
1430 static ASIO_CONSTEXPR result_type value() ASIO_NOEXCEPT
1432 return result_type();
1436 #endif // !defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT) 1438 #if !defined(ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT) 1440 template <
typename Allocator,
unsigned int Bits,
typename Property>
1445 asio::is_convertible<
1447 asio::execution::blocking_t
1452 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1453 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
true);
1457 template <
typename Allocator,
unsigned int Bits,
typename Property>
1462 asio::is_convertible<
1464 asio::execution::relationship_t
1469 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1470 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
true);
1474 template <
typename Allocator,
unsigned int Bits>
1480 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1481 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
true);
1485 template <
typename Allocator,
unsigned int Bits>
1491 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1492 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
true);
1493 typedef Allocator result_type;
1496 template <
typename Allocator,
unsigned int Bits,
typename OtherAllocator>
1502 ASIO_STATIC_CONSTEXPR(
bool, is_valid =
true);
1503 ASIO_STATIC_CONSTEXPR(
bool, is_noexcept =
true);
1504 typedef Allocator result_type;
1507 #endif // !defined(ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT) 1511 #endif // !defined(GENERATING_DOCUMENTATION) 1515 #include "asio/detail/pop_options.hpp" 1517 #include "asio/impl/io_context.hpp" 1518 #if defined(ASIO_HEADER_ONLY) 1519 # include "asio/impl/io_context.ipp" 1520 #endif // defined(ASIO_HEADER_ONLY) 1524 #if !defined(ASIO_NO_EXTENSIONS) 1525 # if defined(ASIO_STRAND_HPP) 1526 # include "asio/io_context_strand.hpp" 1527 # endif // defined(ASIO_STRAND_HPP) 1528 #endif // !defined(ASIO_NO_EXTENSIONS) 1530 #endif // ASIO_IO_CONTEXT_HPP static ASIO_CONSTEXPR execution::mapping_t query(execution::mapping_t) ASIO_NOEXCEPT
Query the current value of the mapping property.
Definition: io_context.hpp:866
Definition: relationship.hpp:157
ASIO_CONSTEXPR basic_executor_type< Allocator, ASIO_UNSPECIFIED(Bits|outstanding_work_tracked)> require(execution::outstanding_work_t::tracked_t) const
Obtain an executor with the outstanding_work.tracked property.
Definition: io_context.hpp:796
ASIO_CONSTEXPR execution::relationship_t query(execution::relationship_t) const ASIO_NOEXCEPT
Query the current value of the relationship property.
Definition: io_context.hpp:917
friend bool operator==(const basic_executor_type &a, const basic_executor_type &b) ASIO_NOEXCEPT
Compare two executors for equality.
Definition: io_context.hpp:988
Definition: blocking.hpp:208
static ASIO_CONSTEXPR execution::outstanding_work_t query(execution::outstanding_work_t) ASIO_NOEXCEPT
Query the current value of the outstanding_work property.
Definition: io_context.hpp:936
std::size_t count_type
The type used to count the number of handlers executed by the context.
Definition: io_context.hpp:239
Definition: signal_init.hpp:30
ASIO_CONSTEXPR basic_executor_type require(execution::relationship_t::fork_t) const
Obtain an executor with the relationship.fork property.
Definition: io_context.hpp:760
Base class for all io_context services.
Definition: io_context.hpp:1185
Definition: blocking.hpp:193
ASIO_CONSTEXPR basic_executor_type< OtherAllocator, Bits > require(execution::allocator_t< OtherAllocator > a) const
Obtain an executor with the specified allocator property.
Definition: io_context.hpp:832
Definition: blocking.hpp:191
Definition: io_context.hpp:1237
ASIO_CONSTEXPR basic_executor_type< std::allocator< void >, Bits > require(execution::allocator_t< void >) const
Obtain an executor with the default allocator property.
Definition: io_context.hpp:849
Definition: query_member.hpp:38
ASIO_CONSTEXPR basic_executor_type require(execution::blocking_t::never_t) const
Obtain an executor with the blocking.never property.
Definition: io_context.hpp:743
Provides serialised handler execution.
Definition: io_context_strand.hpp:89
~basic_executor_type() ASIO_NOEXCEPT
Destructor.
Definition: io_context.hpp:699
basic_executor_type(const basic_executor_type &other) ASIO_NOEXCEPT
Copy constructor.
Definition: io_context.hpp:675
Base class for all io_context services.
Definition: execution_context.hpp:315
basic_executor_type< std::allocator< void >, 0 > executor_type
Executor used to submit functions to an io_context.
Definition: io_context.hpp:228
A context for function object execution.
Definition: execution_context.hpp:105
ASIO_INITFN_AUTO_RESULT_TYPE(RangeConnectHandler, void(asio::error_code, typename Protocol::endpoint)) async_connect(basic_socket< Protocol
Asynchronously establishes a socket connection by trying each endpoint in a sequence.
ASIO_CONSTEXPR basic_executor_type require(execution::relationship_t::continuation_t) const
Obtain an executor with the relationship.continuation property.
Definition: io_context.hpp:777
Definition: execute_member.hpp:38
Provides core I/O functionality.
Definition: io_context.hpp:211
Definition: allocator.hpp:78
Definition: type_traits.hpp:97
fork_event
Fork-related event notifications.
Definition: execution_context.hpp:142
Definition: mapping.hpp:192
Definition: require_member.hpp:38
Executor implementation type used to submit functions to an io_context.
Definition: io_context.hpp:222
(Deprecated: Use executor_work_guard.) Class to inform the io_context when it has work to do...
Definition: io_context.hpp:1145
Definition: outstanding_work.hpp:158
friend bool operator!=(const basic_executor_type &a, const basic_executor_type &b) ASIO_NOEXCEPT
Compare two executors for inequality.
Definition: io_context.hpp:1000
Definition: outstanding_work.hpp:153
ASIO_CONSTEXPR Allocator query(execution::allocator_t< OtherAllocator >) const ASIO_NOEXCEPT
Query the current value of the allocator property.
Definition: io_context.hpp:955
Definition: io_context.hpp:57
Definition: relationship.hpp:152
Class to represent an error code value.
Definition: error_code.hpp:80
Definition: query_static_constexpr_member.hpp:42
Definition: mapping.hpp:185
Definition: io_context.hpp:121
ASIO_CONSTEXPR basic_executor_type require(execution::blocking_t::possibly_t) const
Obtain an executor with the blocking.possibly property.
Definition: io_context.hpp:726
ASIO_CONSTEXPR basic_executor_type< Allocator, ASIO_UNSPECIFIED(Bits &~outstanding_work_tracked)> require(execution::outstanding_work_t::untracked_t) const
Obtain an executor with the outstanding_work.untracked property.
Definition: io_context.hpp:814
Definition: wrapped_handler.hpp:48
Definition: relationship.hpp:151
Definition: io_context.hpp:165
Definition: context.hpp:69
ASIO_CONSTEXPR Allocator query(execution::allocator_t< void >) const ASIO_NOEXCEPT
Query the current value of the allocator property.
Definition: io_context.hpp:971
Definition: allocator.hpp:132
io_context & query(execution::context_t) const ASIO_NOEXCEPT
Query the current value of the context property.
Definition: io_context.hpp:882
Definition: any_io_executor.hpp:28
ASIO_CONSTEXPR execution::blocking_t query(execution::blocking_t) const ASIO_NOEXCEPT
Query the current value of the blocking property.
Definition: io_context.hpp:898
Definition: scheduler.hpp:38
Definition: outstanding_work.hpp:152
Definition: execution_context.hpp:379
Definition: equality_comparable.hpp:36