mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 10:09:36 +02:00
Idle Reactor high CPU usage #607
This commit is contained in:
@@ -129,6 +129,7 @@ public:
|
||||
{
|
||||
pNotification->release();
|
||||
StreamSocket sock = _socket.acceptConnection();
|
||||
_pReactor->wakeUp();
|
||||
createServiceHandler(sock);
|
||||
}
|
||||
|
||||
@@ -140,6 +141,7 @@ protected:
|
||||
{
|
||||
std::size_t next = _next++;
|
||||
if (_next == _reactors.size()) _next = 0;
|
||||
_reactors[next]->wakeUp();
|
||||
return new ServiceHandler(socket, *_reactors[next]);
|
||||
}
|
||||
|
||||
@@ -167,9 +169,27 @@ protected:
|
||||
_reactors.push_back(new ParallelReactor);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::vector<typename ParallelReactor::Ptr> ReactorVec;
|
||||
|
||||
ReactorVec& reactors()
|
||||
/// Returns reference to vector of reactors.
|
||||
{
|
||||
return _reactors;
|
||||
}
|
||||
|
||||
SocketReactor* reactor(std::size_t idx)
|
||||
/// Returns reference to the reactor at position idx.
|
||||
{
|
||||
return _reactors.at(idx).get();
|
||||
}
|
||||
|
||||
std::size_t& next()
|
||||
/// Returns reference to the next reactor index.
|
||||
{
|
||||
return _next;
|
||||
}
|
||||
|
||||
private:
|
||||
ParallelSocketAcceptor();
|
||||
ParallelSocketAcceptor(const ParallelSocketAcceptor&);
|
||||
ParallelSocketAcceptor& operator = (const ParallelSocketAcceptor&);
|
||||
|
||||
@@ -129,6 +129,7 @@ public:
|
||||
{
|
||||
pNotification->release();
|
||||
StreamSocket sock = _socket.acceptConnection();
|
||||
_pReactor->wakeUp();
|
||||
createServiceHandler(sock);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Thread;
|
||||
|
||||
|
||||
namespace Net {
|
||||
|
||||
|
||||
@@ -128,6 +133,9 @@ public:
|
||||
/// The reactor will be stopped when the next event
|
||||
/// (including a timeout event) occurs.
|
||||
|
||||
void wakeUp();
|
||||
/// Wakes up idle reactor.
|
||||
|
||||
void setTimeout(const Poco::Timespan& timeout);
|
||||
/// Sets the timeout.
|
||||
///
|
||||
@@ -166,7 +174,7 @@ 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.
|
||||
///
|
||||
@@ -194,7 +202,7 @@ protected:
|
||||
|
||||
void dispatch(SocketNotification* pNotification);
|
||||
/// Dispatches the given notification to all observers.
|
||||
|
||||
|
||||
private:
|
||||
typedef Poco::AutoPtr<SocketNotifier> NotifierPtr;
|
||||
typedef Poco::AutoPtr<SocketNotification> NotificationPtr;
|
||||
@@ -206,7 +214,7 @@ private:
|
||||
{
|
||||
DEFAULT_TIMEOUT = 250000
|
||||
};
|
||||
|
||||
|
||||
bool _stop;
|
||||
Poco::Timespan _timeout;
|
||||
EventHandlerMap _handlers;
|
||||
@@ -217,6 +225,7 @@ private:
|
||||
NotificationPtr _pIdleNotification;
|
||||
NotificationPtr _pShutdownNotification;
|
||||
Poco::FastMutex _mutex;
|
||||
Poco::Thread* _pThread;
|
||||
|
||||
friend class SocketNotifier;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user