Skip to content
Newer
Older
100644 92 lines (73 sloc) 2.17 KB
5a63907 @aleks-f change EOL to 'native'
aleks-f authored Apr 29, 2012
1 //
2 // SocketNotifier.cpp
3 //
4 // $Id: //poco/1.4/Net/src/SocketNotifier.cpp#1 $
5 //
6 // Library: Net
7 // Package: Reactor
8 // Module: SocketNotifier
9 //
10 // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
11 // and Contributors.
12 //
628a06f @bufferoverflow LICENSE: add info about SPDX-License-Identifier usage and use it
bufferoverflow authored May 4, 2014
13 // SPDX-License-Identifier: BSL-1.0
5a63907 @aleks-f change EOL to 'native'
aleks-f authored Apr 29, 2012
14 //
15
16
17 #include "Poco/Net/SocketNotifier.h"
18 #include "Poco/Net/SocketReactor.h"
19 #include "Poco/Net/SocketNotification.h"
20
21
22 namespace Poco {
23 namespace Net {
24
25
26 SocketNotifier::SocketNotifier(const Socket& socket):
27 _socket(socket)
28 {
29 }
30
31
32 SocketNotifier::~SocketNotifier()
33 {
34 }
35
36
37 void SocketNotifier::addObserver(SocketReactor* pReactor, const Poco::AbstractObserver& observer)
38 {
39 _nc.addObserver(observer);
40 if (observer.accepts(pReactor->_pReadableNotification))
41 _events.insert(pReactor->_pReadableNotification.get());
42 else if (observer.accepts(pReactor->_pWritableNotification))
43 _events.insert(pReactor->_pWritableNotification.get());
44 else if (observer.accepts(pReactor->_pErrorNotification))
45 _events.insert(pReactor->_pErrorNotification.get());
46 else if (observer.accepts(pReactor->_pTimeoutNotification))
47 _events.insert(pReactor->_pTimeoutNotification.get());
48 }
49
50
51 void SocketNotifier::removeObserver(SocketReactor* pReactor, const Poco::AbstractObserver& observer)
52 {
53 _nc.removeObserver(observer);
54 EventSet::iterator it = _events.end();
55 if (observer.accepts(pReactor->_pReadableNotification))
56 it = _events.find(pReactor->_pReadableNotification.get());
57 else if (observer.accepts(pReactor->_pWritableNotification))
58 it = _events.find(pReactor->_pWritableNotification.get());
59 else if (observer.accepts(pReactor->_pErrorNotification))
60 it = _events.find(pReactor->_pErrorNotification.get());
61 else if (observer.accepts(pReactor->_pTimeoutNotification))
62 it = _events.find(pReactor->_pTimeoutNotification.get());
63 if (it != _events.end())
64 _events.erase(it);
65 }
66
67
68 namespace
69 {
70 static Socket nullSocket;
71 }
72
73
74 void SocketNotifier::dispatch(SocketNotification* pNotification)
75 {
76 pNotification->setSocket(_socket);
77 pNotification->duplicate();
78 try
79 {
80 _nc.postNotification(pNotification);
81 }
82 catch (...)
83 {
84 pNotification->setSocket(nullSocket);
85 throw;
86 }
87 pNotification->setSocket(nullSocket);
88 }
89
90
91 } } // namespace Poco::Net
Something went wrong with that request. Please try again.