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

◆ close_endpoint()

void MayaFlux::Core::TCPBackend::close_endpoint ( uint64_t  endpoint_id)
overridevirtual

Close an endpoint and release its resources.

Parameters
endpoint_idEndpoint to close. No-op if already closed.

Implements MayaFlux::Core::INetworkBackend.

Definition at line 196 of file TCPBackend.cpp.

197{
198 {
199 std::unique_lock lock(m_connections_mutex);
200 auto it = m_connections.find(endpoint_id);
201 if (it != m_connections.end()) {
202 asio::error_code ec;
203
204 if (!it->second->socket.close(ec)) {
206 "Error closing TCP connection {}: {}", endpoint_id, ec.message());
207 }
208
209 if (it->second->reconnect_timer) {
210 it->second->reconnect_timer->cancel();
211 }
212 m_connections.erase(it);
213
215 "TCP connection {} closed", endpoint_id);
216 return;
217 }
218 }
219
220 {
221 std::unique_lock lock(m_listeners_mutex);
222 auto it = m_listeners.find(endpoint_id);
223 if (it != m_listeners.end()) {
224 asio::error_code ec;
225
226 if (it->second->acceptor.close(ec)) {
228 "Error closing TCP listener {}: {}", endpoint_id, ec.message());
229 }
230
231 m_listeners.erase(it);
232
234 "TCP listener {} closed", endpoint_id);
235 }
236 }
237}
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
std::unordered_map< uint64_t, std::unique_ptr< ConnectionState > > m_connections
std::shared_mutex m_listeners_mutex
std::unordered_map< uint64_t, std::unique_ptr< ListenerState > > m_listeners
std::shared_mutex m_connections_mutex
@ NetworkBackend
Network transport backend (UDP, TCP, SHM)
@ Core
Core engine, backend, subsystems.

References MayaFlux::Journal::Core, m_connections, m_connections_mutex, m_listeners, m_listeners_mutex, MF_DEBUG, MF_WARN, and MayaFlux::Journal::NetworkBackend.