From c8a932c59f47b6c83f31c760a47b50b6eac263de Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 17 Sep 2014 16:56:28 +0300 Subject: [PATCH] server/state: Interface towards main program for listening to socket activity --- src/server/state.cpp | 24 ++++++++++++++++++++++++ src/server/state.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/src/server/state.cpp b/src/server/state.cpp index a9270e2..c29d188 100644 --- a/src/server/state.cpp +++ b/src/server/state.cpp @@ -234,8 +234,32 @@ struct CState: public State, public interface::Server void remove_socket_event(int fd) { + interface::MutexScope ms(m_sockets_mutex); // TODO } + + sv_ get_sockets() + { + interface::MutexScope ms(m_sockets_mutex); + sv_ result; + for(auto &pair : m_sockets) + result.push_back(pair.second.fd); + return result; + } + + void emit_socket_event(int fd) + { + interface::MutexScope ms(m_sockets_mutex); + auto it = m_sockets.find(fd); + if(it == m_sockets.end()){ + // This can be valid if the socket has been removed while waiting + // for it elsewhere + log_w("state", "emit_socket_event(): fd=%i not found", fd); + return; + } + SocketState &s = it->second; + emit_event(Event(s.event_type)); + } }; State* createState() diff --git a/src/server/state.h b/src/server/state.h index 4a8a64f..4a50279 100644 --- a/src/server/state.h +++ b/src/server/state.h @@ -25,6 +25,8 @@ namespace server const interface::Event::Type &type) = 0; virtual void emit_event(const interface::Event &event) = 0; virtual void handle_events() = 0; + virtual sv_ get_sockets() = 0; + virtual void emit_socket_event(int fd) = 0; }; State* createState();