changeset 372:d6e95a577fe9

Socket: - add name to Poll - clean the useless m_lookup table
author David Demelier <markand@malikania.fr>
date Thu, 30 Apr 2015 11:42:18 +0200
parents 166943bde655
children 69532542f7fc
files C++/modules/Socket/SocketListener.cpp C++/modules/Socket/SocketListener.h
diffstat 2 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/C++/modules/Socket/SocketListener.cpp	Wed Apr 29 17:26:55 2015 +0200
+++ b/C++/modules/Socket/SocketListener.cpp	Thu Apr 30 11:42:18 2015 +0200
@@ -130,7 +130,6 @@
 void Poll::set(const SocketTable &, Socket s, int flags, bool add)
 {
 	if (add) {
-		m_lookup.emplace(s.handle(), s);
 		m_fds.push_back(pollfd{s.handle(), topoll(flags), 0});
 	} else {
 		auto it = std::find_if(m_fds.begin(), m_fds.end(), [&] (const struct pollfd &pfd) {
@@ -148,14 +147,13 @@
 	});
 
 	if (remove) {
-		m_lookup.erase(it->fd);
 		m_fds.erase(it);
 	} else {
 		it->events &= ~(topoll(flags));
 	}
 }
 
-std::vector<SocketStatus> Poll::wait(const SocketTable &, int ms)
+std::vector<SocketStatus> Poll::wait(const SocketTable &table, int ms)
 {
 	auto result = poll(m_fds.data(), m_fds.size(), ms);
 	if (result == 0) {
@@ -168,7 +166,7 @@
 	std::vector<SocketStatus> sockets;
 	for (auto &fd : m_fds) {
 		if (fd.revents != 0) {
-			sockets.push_back(SocketStatus{m_lookup.at(fd.fd), toflags(fd.revents)});
+			sockets.push_back(SocketStatus{table.at(fd.fd).first, toflags(fd.revents)});
 		}
 	}
 
--- a/C++/modules/Socket/SocketListener.h	Wed Apr 29 17:26:55 2015 +0200
+++ b/C++/modules/Socket/SocketListener.h	Thu Apr 30 11:42:18 2015 +0200
@@ -158,7 +158,6 @@
 class Poll {
 private:
 	std::vector<pollfd> m_fds;
-	std::map<Socket::Handle, Socket> m_lookup;
 
 	short topoll(int flags) const noexcept;
 	int toflags(short &event) const noexcept;
@@ -167,6 +166,14 @@
 	void set(const SocketTable &, Socket sc, int flags, bool add);
 	void unset(const SocketTable &, Socket sc, int flags, bool remove);
 	std::vector<SocketStatus> wait(const SocketTable &, int ms);
+
+	/**
+	 * Backend identifier
+	 */
+	inline const char *name() const noexcept
+	{
+		return "poll";
+	}
 };
 
 #endif