📄 io_service.hpp
字号:
* This function must be called prior to any second or later set of * invocations of the run(), run_one(), poll() or poll_one() functions when a * previous invocation of these functions returned due to the io_service * being stopped or running out of work. This function allows the io_service * to reset any internal state, such as a "stopped" flag. * * This function must not be called while there are any unfinished calls to * the run(), run_one(), poll() or poll_one() functions. */ void reset(); /// Request the io_service to invoke the given handler. /** * This function is used to ask the io_service to execute the given handler. * * The io_service guarantees that the handler will only be called in a thread * in which the run(), run_one(), poll() or poll_one() member functions is * currently being invoked. The handler may be executed inside this function * if the guarantee can be met. * * @param handler The handler to be called. The io_service will make * a copy of the handler object as required. The function signature of the * handler must be: @code void handler(); @endcode */ template <typename CompletionHandler> void dispatch(CompletionHandler handler); /// Request the io_service to invoke the given handler and return immediately. /** * This function is used to ask the io_service to execute the given handler, * but without allowing the io_service to call the handler from inside this * function. * * The io_service guarantees that the handler will only be called in a thread * in which the run(), run_one(), poll() or poll_one() member functions is * currently being invoked. * * @param handler The handler to be called. The io_service will make * a copy of the handler object as required. The function signature of the * handler must be: @code void handler(); @endcode */ template <typename CompletionHandler> void post(CompletionHandler handler); /// Create a new handler that automatically dispatches the wrapped handler /// on the io_service. /** * This function is used to create a new handler function object that, when * invoked, will automatically pass the wrapped handler to the io_service's * dispatch function. * * @param handler The handler to be wrapped. The io_service will make a copy * of the handler object as required. The function signature of the handler * must be: @code void handler(A1 a1, ... An an); @endcode * * @return A function object that, when invoked, passes the wrapped handler to * the io_service's dispatch function. Given a function object with the * signature: * @code R f(A1 a1, ... An an); @endcode * If this function object is passed to the wrap function like so: * @code io_service.wrap(f); @endcode * then the return value is a function object with the signature * @code void g(A1 a1, ... An an); @endcode * that, when invoked, executes code equivalent to: * @code io_service.dispatch(boost::bind(f, a1, ... an)); @endcode */ template <typename Handler>#if defined(GENERATING_DOCUMENTATION) unspecified#else detail::wrapped_handler<io_service&, Handler>#endif wrap(Handler handler); /// Obtain the service object corresponding to the given type. /** * This function is used to locate a service object that corresponds to * the given service type. If there is no existing implementation of the * service, then the io_service will create a new instance of the service. * * @param ios The io_service object that owns the service. * * @return The service interface implementing the specified service type. * Ownership of the service interface is not transferred to the caller. */ template <typename Service> friend Service& use_service(io_service& ios); /// Add a service object to the io_service. /** * This function is used to add a service to the io_service. * * @param ios The io_service object that owns the service. * * @param svc The service object. On success, ownership of the service object * is transferred to the io_service. When the io_service object is destroyed, * it will destroy the service object by performing: * @code delete static_cast<io_service::service*>(svc) @endcode * * @throws asio::service_already_exists Thrown if a service of the * given type is already present in the io_service. * * @throws asio::invalid_service_owner Thrown if the service's owning * io_service is not the io_service object specified by the ios parameter. */ template <typename Service> friend void add_service(io_service& ios, Service* svc); /// Determine if an io_service contains a specified service type. /** * This function is used to determine whether the io_service contains a * service object corresponding to the given service type. * * @param ios The io_service object that owns the service. * * @return A boolean indicating whether the io_service contains the service. */ template <typename Service> friend bool has_service(io_service& ios);private:#if defined(BOOST_WINDOWS) || defined(__CYGWIN__) detail::winsock_init<> init_;#elif defined(__sun) || defined(__QNX__) || defined(__hpux) || defined(_AIX) \ || defined(__osf__) detail::signal_init<> init_;#endif // The service registry. asio::detail::service_registry* service_registry_; // The implementation. impl_type& impl_;};/// Class to inform the io_service when it has work to do./** * The work class is used to inform the io_service when work starts and * finishes. This ensures that the io_service's run() function will not exit * while work is underway, and that it does exit when there is no unfinished * work remaining. * * The work class is copy-constructible so that it may be used as a data member * in a handler class. It is not assignable. */class io_service::work{public: /// Constructor notifies the io_service that work is starting. /** * The constructor is used to inform the io_service that some work has begun. * This ensures that the io_service's run() function will not exit while the * work is underway. */ explicit work(asio::io_service& io_service); /// Copy constructor notifies the io_service that work is starting. /** * The constructor is used to inform the io_service that some work has begun. * This ensures that the io_service's run() function will not exit while the * work is underway. */ work(const work& other); /// Destructor notifies the io_service that the work is complete. /** * The destructor is used to inform the io_service that some work has * finished. Once the count of unfinished work reaches zero, the io_service's * run() function is permitted to exit. */ ~work(); /// (Deprecated: use get_io_service().) Get the io_service associated with the /// work. asio::io_service& io_service(); /// Get the io_service associated with the work. asio::io_service& get_io_service();private: // Prevent assignment. void operator=(const work& other); // The io_service. asio::io_service& io_service_;};/// Class used to uniquely identify a service.class io_service::id : private noncopyable{public: /// Constructor. id() {}};/// Base class for all io_service services.class io_service::service : private noncopyable{public: /// (Deprecated: use get_io_service().) Get the io_service object that owns /// the service. asio::io_service& io_service(); /// Get the io_service object that owns the service. asio::io_service& get_io_service();protected: /// Constructor. /** * @param owner The io_service object that owns the service. */ service(asio::io_service& owner); /// Destructor. virtual ~service();private: /// Destroy all user-defined handler objects owned by the service. virtual void shutdown_service() = 0; friend class asio::detail::service_registry; asio::io_service& owner_; const std::type_info* type_info_; const asio::io_service::id* id_; service* next_;};/// Exception thrown when trying to add a duplicate service to an io_service.class service_already_exists : public std::logic_error{public: service_already_exists() : std::logic_error("Service already exists.") { }};/// Exception thrown when trying to add a service object to an io_service where/// the service has a different owner.class invalid_service_owner : public std::logic_error{public: invalid_service_owner() : std::logic_error("Invalid service owner.") { }};} // namespace asio#include "asio/impl/io_service.ipp"#include "asio/detail/pop_options.hpp"#endif // ASIO_IO_SERVICE_HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -