mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-poco.git
synced 2025-11-01 11:07:53 +00:00
Merge branch 'develop' of https://github.com/pocoproject/poco.git into develop
This commit is contained in:
@@ -70,10 +70,13 @@ protected:
|
||||
|
||||
private:
|
||||
typedef std::multiset<SocketNotification*> EventSet;
|
||||
typedef Poco::FastMutex MutexType;
|
||||
typedef MutexType::ScopedLock ScopedLock;
|
||||
|
||||
EventSet _events;
|
||||
Poco::NotificationCenter _nc;
|
||||
Socket _socket;
|
||||
MutexType _mutex;
|
||||
};
|
||||
|
||||
|
||||
@@ -82,6 +85,7 @@ private:
|
||||
//
|
||||
inline bool SocketNotifier::accepts(SocketNotification* pNotification)
|
||||
{
|
||||
ScopedLock l(_mutex);
|
||||
return _events.find(pNotification) != _events.end();
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,10 @@ public:
|
||||
{
|
||||
PollSet::SocketModeMap result;
|
||||
|
||||
if(_socketMap.empty()) return result;
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
if(_socketMap.empty()) return result;
|
||||
}
|
||||
|
||||
Poco::Timespan remainingTime(timeout);
|
||||
int rc;
|
||||
|
||||
@@ -35,6 +35,7 @@ SocketNotifier::~SocketNotifier()
|
||||
void SocketNotifier::addObserver(SocketReactor* pReactor, const Poco::AbstractObserver& observer)
|
||||
{
|
||||
_nc.addObserver(observer);
|
||||
ScopedLock l(_mutex);
|
||||
if (observer.accepts(pReactor->_pReadableNotification))
|
||||
_events.insert(pReactor->_pReadableNotification.get());
|
||||
else if (observer.accepts(pReactor->_pWritableNotification))
|
||||
@@ -49,6 +50,7 @@ void SocketNotifier::addObserver(SocketReactor* pReactor, const Poco::AbstractOb
|
||||
void SocketNotifier::removeObserver(SocketReactor* pReactor, const Poco::AbstractObserver& observer)
|
||||
{
|
||||
_nc.removeObserver(observer);
|
||||
ScopedLock l(_mutex);
|
||||
EventSet::iterator it = _events.end();
|
||||
if (observer.accepts(pReactor->_pReadableNotification))
|
||||
it = _events.find(pReactor->_pReadableNotification.get());
|
||||
|
||||
@@ -52,13 +52,10 @@ namespace
|
||||
_reactor(reactor)
|
||||
{
|
||||
_reactor.addEventHandler(_socket, Observer<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onReadable));
|
||||
_reactor.addEventHandler(_socket, Observer<EchoServiceHandler, ShutdownNotification>(*this, &EchoServiceHandler::onShutdown));
|
||||
}
|
||||
|
||||
~EchoServiceHandler()
|
||||
{
|
||||
_reactor.removeEventHandler(_socket, Observer<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onReadable));
|
||||
_reactor.removeEventHandler(_socket, Observer<EchoServiceHandler, ShutdownNotification>(*this, &EchoServiceHandler::onShutdown));
|
||||
}
|
||||
|
||||
void onReadable(ReadableNotification* pNf)
|
||||
@@ -70,13 +67,11 @@ namespace
|
||||
{
|
||||
_socket.sendBytes(buffer, n);
|
||||
}
|
||||
else delete this;
|
||||
}
|
||||
|
||||
void onShutdown(ShutdownNotification* pNf)
|
||||
{
|
||||
pNf->release();
|
||||
delete this;
|
||||
else
|
||||
{
|
||||
_reactor.removeEventHandler(_socket, Observer<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onReadable));
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -129,8 +124,11 @@ namespace
|
||||
checkReadableObserverCount(1);
|
||||
_reactor.removeEventHandler(_socket, Observer<ClientServiceHandler, ReadableNotification>(*this, &ClientServiceHandler::onReadable));
|
||||
checkReadableObserverCount(0);
|
||||
if (_once || _data.size() == 8192) _reactor.stop();
|
||||
delete this;
|
||||
if (_once || _data.size() == 8192)
|
||||
{
|
||||
_reactor.stop();
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user