MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ stop()

void Lila::Server::stop ( )
noexcept

Stops the server and disconnects all clients.

Definition at line 157 of file Server.cpp.

158{
159 if (!m_running)
160 return;
161
162 m_running = false;
163
167 }
168
169 if (m_server_fd >= 0) {
171 m_server_fd = -1;
172 }
173
174 {
175 std::unique_lock lock(m_clients_mutex);
176 for (const auto& [fd, client] : m_connected_clients) {
177 socket_close(fd);
178 }
179 m_connected_clients.clear();
180 }
181
182 m_event_bus.publish(StreamEvent { EventType::ServerStop });
183
184#ifdef MAYAFLUX_PLATFORM_WINDOWS
185 WSACleanup();
186#endif
187
188 LILA_INFO(Emitter::SERVER, "Server stopped");
189}
#define LILA_INFO(emitter, msg)
void publish(const StreamEvent &event)
Publish an event to all subscribers of its type.
Definition EventBus.cpp:18
void request_stop() noexcept
bool joinable() const noexcept
ServerThread m_server_thread
Server thread.
Definition Server.hpp:165
std::atomic< bool > m_running
Server running state.
Definition Server.hpp:164
std::shared_mutex m_clients_mutex
Mutex for client map.
Definition Server.hpp:173
std::unordered_map< int, ClientInfo > m_connected_clients
Map of connected clients.
Definition Server.hpp:174
int m_server_fd
Server socket file descriptor.
Definition Server.hpp:163
EventBus m_event_bus
Event bus for publishing server events.
Definition Server.hpp:171
static void socket_close(int fd)
Definition Server.cpp:43

References Lila::ServerThread::join(), Lila::ServerThread::joinable(), LILA_INFO, m_clients_mutex, m_connected_clients, m_event_bus, m_running, m_server_fd, m_server_thread, Lila::EventBus::publish(), Lila::ServerThread::request_stop(), and Lila::socket_close().

Referenced by ~Server().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: