server/state: Interface towards main program for listening to socket activity

This commit is contained in:
Perttu Ahola 2014-09-17 16:56:28 +03:00
parent 94909e39d4
commit c8a932c59f
2 changed files with 26 additions and 0 deletions

View File

@ -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_<int> get_sockets()
{
interface::MutexScope ms(m_sockets_mutex);
sv_<int> 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()

View File

@ -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_<int> get_sockets() = 0;
virtual void emit_socket_event(int fd) = 0;
};
State* createState();