mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 04:17:55 +01:00
Socket::select and SocketReactor improvements
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Socket.h
|
||||
//
|
||||
// $Id: //poco/svn/Net/include/Poco/Net/Socket.h#3 $
|
||||
// $Id: //poco/1.3/Net/include/Poco/Net/Socket.h#3 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Sockets
|
||||
@@ -129,6 +129,10 @@ public:
|
||||
/// * readList contains those sockets ready for reading,
|
||||
/// * writeList contains those sockets ready for writing,
|
||||
/// * exceptList contains those sockets with a pending error.
|
||||
///
|
||||
/// If the total number of sockets passed in readList, writeList and
|
||||
/// exceptList is zero, select() will return immediately and the
|
||||
/// return value will be 0.
|
||||
|
||||
bool poll(const Poco::Timespan& timeout, int mode) const;
|
||||
/// Determines the status of the socket, using a
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// SocketNotification.h
|
||||
//
|
||||
// $Id: //poco/svn/Net/include/Poco/Net/SocketNotification.h#2 $
|
||||
// $Id: //poco/1.3/Net/include/Poco/Net/SocketNotification.h#2 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Reactor
|
||||
@@ -128,6 +128,19 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class Net_API IdleNotification: public SocketNotification
|
||||
/// This notification is sent when the SocketReactor does
|
||||
/// not have any sockets to react to.
|
||||
{
|
||||
public:
|
||||
IdleNotification(SocketReactor* pReactor);
|
||||
/// Creates the IdleNotification for the given SocketReactor.
|
||||
|
||||
~IdleNotification();
|
||||
/// Destroys the IdleNotification.
|
||||
};
|
||||
|
||||
|
||||
class Net_API ShutdownNotification: public SocketNotification
|
||||
/// This notification is sent when the SocketReactor is
|
||||
/// about to shut down.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// SocketReactor.h
|
||||
//
|
||||
// $Id: //poco/svn/Net/include/Poco/Net/SocketReactor.h#2 $
|
||||
// $Id: //poco/1.3/Net/include/Poco/Net/SocketReactor.h#2 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Reactor
|
||||
@@ -90,7 +90,8 @@ class Net_API SocketReactor: public Poco::Runnable
|
||||
/// If an event is detected, the corresponding event handler
|
||||
/// is invoked. There are five event types (and corresponding
|
||||
/// notification classes) defined: ReadableNotification, WritableNotification,
|
||||
/// ErrorNotification, TimeoutNotification and ShutdownNotification.
|
||||
/// ErrorNotification, TimeoutNotification, IdleNotification and
|
||||
/// ShutdownNotification.
|
||||
///
|
||||
/// The ReadableNotification will be dispatched if a socket becomes
|
||||
/// readable. The WritableNotification will be dispatched if a socket
|
||||
@@ -100,9 +101,17 @@ class Net_API SocketReactor: public Poco::Runnable
|
||||
/// If the timeout expires and no event has occured, a
|
||||
/// TimeoutNotification will be dispatched to all event handlers
|
||||
/// registered for it. This is done in the onTimeout() method
|
||||
/// which can be overridded by subclasses to perform custom
|
||||
/// which can be overridden by subclasses to perform custom
|
||||
/// timeout processing.
|
||||
///
|
||||
/// If there are no sockets for the SocketReactor to pass to
|
||||
/// Socket::select(), an IdleNotification will be dispatched to
|
||||
/// all event handlers registered for it. This is done in the
|
||||
/// onIdle() method which can be overridden by subclasses
|
||||
/// to perform custom idle processing. Since onIdle() will be
|
||||
/// called repeatedly in a loop, it is recommended to do a
|
||||
/// short sleep or yield in the event handler.
|
||||
///
|
||||
/// Finally, when the SocketReactor is about to shut down (as a result
|
||||
/// of stop() being called), it dispatches a ShutdownNotification
|
||||
/// to all event handlers. This is done in the onShutdown() method
|
||||
@@ -174,6 +183,13 @@ protected:
|
||||
/// Can be overridden by subclasses. The default implementation
|
||||
/// dispatches the TimeoutNotification and thus should be called by overriding
|
||||
/// implementations.
|
||||
|
||||
virtual void onIdle();
|
||||
/// Called if no sockets are available to call select() on.
|
||||
///
|
||||
/// Can be overridden by subclasses. The default implementation
|
||||
/// dispatches the IdleNotification and thus should be called by overriding
|
||||
/// implementations.
|
||||
|
||||
virtual void onShutdown();
|
||||
/// Called when the SocketReactor is about to terminate.
|
||||
@@ -208,6 +224,7 @@ private:
|
||||
NotificationPtr _pWritableNotification;
|
||||
NotificationPtr _pErrorNotification;
|
||||
NotificationPtr _pTimeoutNotification;
|
||||
NotificationPtr _pIdleNotification;
|
||||
NotificationPtr _pShutdownNotification;
|
||||
Poco::FastMutex _mutex;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user