server/state: Interface towards main program for listening to socket activity
This commit is contained in:
parent
94909e39d4
commit
c8a932c59f
@ -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()
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user