MayaFlux 0.4.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 192 of file TCPBackend.cpp.

193{
194 {
195 std::unique_lock lock(m_connections_mutex);
196 auto it = m_connections.find(endpoint_id);
197 if (it != m_connections.end()) {
198 asio::error_code ec;
199
200 if (!it->second->socket.close(ec)) {
202 "Error closing TCP connection {}: {}", endpoint_id, ec.message());
203 }
204
205 if (it->second->reconnect_timer) {
206 it->second->reconnect_timer->cancel();
207 }
208 m_connections.erase(it);
209
211 "TCP connection {} closed", endpoint_id);
212 return;
213 }
214 }
215
216 {
217 std::unique_lock lock(m_listeners_mutex);
218 auto it = m_listeners.find(endpoint_id);
219 if (it != m_listeners.end()) {
220 asio::error_code ec;
221
222 if (it->second->acceptor.close(ec)) {
224 "Error closing TCP listener {}: {}", endpoint_id, ec.message());
225 }
226
227 m_listeners.erase(it);
228
230 "TCP listener {} closed", endpoint_id);
231 }
232 }
233}
#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.