Wt
4.11.0
|
A utility class for asynchronous notification of socket activity. More...
#include <Wt/WSocketNotifier.h>
Public Types | |
enum class | Type { Read , Write , Exception } |
Enumeration that event type. More... | |
Public Types inherited from Wt::WObject | |
typedef void(WObject::* | Method) () |
Typedef for a WObject method without arguments. | |
Public Member Functions | |
WSocketNotifier (int socket, Type type) | |
Creates a new socket notifier. | |
~WSocketNotifier () | |
Destructor. | |
int | socket () const |
Returns the socket. | |
Type | type () const |
Returns the event type. | |
void | setEnabled (bool enabled) |
Enables or disable the notifier. | |
bool | isEnabled () const |
Returns if the notifier is enabled. | |
Signal< int > & | activated () |
Signal indicating an event. | |
Public Member Functions inherited from Wt::WObject | |
void | addChild (std::unique_ptr< WObject > child) |
Add a child WObject whose lifetime is determined by this WObject. | |
template<typename Child > | |
Child * | addChild (std::unique_ptr< Child > child) |
Add a child WObject, returning a raw pointer. | |
std::unique_ptr< WObject > | removeChild (WObject *child) |
Remove a child WObject, so its lifetime is no longer determined by this WObject. | |
template<typename Child > | |
std::unique_ptr< Child > | removeChild (Child *child) |
Remove a child WObject, so its lifetime is no longer determined by this WObject. | |
virtual const std::string | id () const |
Returns the (unique) identifier for this object. | |
virtual void | setObjectName (const std::string &name) |
Sets an object name. | |
virtual std::string | objectName () const |
Returns the object name. | |
void | resetLearnedSlots () |
Resets learned stateless slot implementations. | |
template<class T > | |
void | resetLearnedSlot (void(T::*method)()) |
Resets a learned stateless slot implementation. | |
template<class T > | |
WStatelessSlot * | implementStateless (void(T::*method)()) |
Declares a slot to be stateless and learn client-side behaviour on first invocation. | |
template<class T > | |
WStatelessSlot * | implementStateless (void(T::*method)(), void(T::*undoMethod)()) |
Declares a slot to be stateless and learn client-side behaviour in advance. | |
void | isNotStateless () |
Marks the current function as not stateless. | |
template<class T > | |
WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode) |
Provides a JavaScript implementation for a method. | |
Public Member Functions inherited from Wt::Core::observable | |
observable () noexcept | |
Default constructor. | |
virtual | ~observable () |
Destructor. | |
template<typename... Args, typename C > | |
auto | bindSafe (void(C::*method)(Args...)) noexcept |
Protects a method call against object destruction. | |
template<typename... Args, typename C > | |
auto | bindSafe (void(C::*method)(Args...) const) const noexcept |
Protects a const method call against object destruction. | |
template<typename Function > | |
auto | bindSafe (const Function &function) noexcept |
Protects a function against object destruction. | |
Additional Inherited Members | |
Protected Member Functions inherited from Wt::WObject | |
virtual WStatelessSlot * | getStateless (Method method) |
On-demand stateless slot implementation. | |
A utility class for asynchronous notification of socket activity.
Use a socket notifier to integrate listening for socket events into the Wt event loop. In this way, you do not need a separate thread to listen for socket activity. Socket activity is either the availability of data to be read (Read event), possibility to write data (Write event), or an exception that occurred (Exception event).
When an event on a socket is available, the notifier emits the activated() signal. As in the case of a user interface event (like for example WInteractWidget::clicked()), you will typically modify the widget tree in response to the event. But, unless you use a timer (WTimer) or use server-initiated updates (see WApplication::triggerUpdates()), these changes are not propagated to the user interface, until the next user interface event.
Like other events, socket notification events are serial (not simultaneous), and there are no thread safety issues (you don't need to take the WApplication::UpdateLock).
|
strong |
Creates a new socket notifier.
Create a new socket listener to listen for events of given type
on a socket with file descriptor socket
. The WSocketNotifier is enabled after construction.
Signal indicating an event.
The signal is emitted when an event that was waited for is available. The signal argument is socket().