changeset 274:e60352f74985

Socket: fix poll method add function
author David Demelier <markand@malikania.fr>
date Thu, 23 Oct 2014 12:00:55 +0200
parents 4b2e82992765
children d945fa44f601
files C++/SocketListener.cpp
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/C++/SocketListener.cpp	Wed Oct 22 23:08:39 2014 +0200
+++ b/C++/SocketListener.cpp	Thu Oct 23 12:00:55 2014 +0200
@@ -221,8 +221,16 @@
 
 void PollMethod::add(Socket &&s, SocketDirection direction)
 {
-	m_lookup[s.handle()] = s;
-	m_fds.push_back({ s.handle(), topoll(direction), 0 });
+	bool found(false);
+	auto it = std::find_if(m_fds.begin(), m_fds.end(), [&] (const auto &pfd) { return pfd.fd == s.handle(); });
+
+	// If found, add the new direction, otherwise add a new socket
+	if (it != m_fds.end())
+		it->events |= topoll(direction);
+	else {
+		m_lookup[s.handle()] = s;
+		m_fds.push_back({ s.handle(), topoll(direction), 0 });
+	}
 }
 
 void PollMethod::remove(const Socket &s, SocketDirection direction)