mirror of
https://github.com/holub/mame
synced 2025-04-18 22:49:58 +03:00
Cleanup of network output module
This commit is contained in:
parent
18c91895bd
commit
a6f997cb4d
@ -76,7 +76,7 @@ void rtc_tcp_connection::user_on_tcp_connection_read()
|
||||
// the latest parsed frame filled it, then empty the full buffer.
|
||||
if ((m_frame_start + 2 + packet_len) == m_buffer_size)
|
||||
{
|
||||
osd_printf_error("no more space in the buffer, emptying the buffer data");
|
||||
osd_printf_error("no more space in the buffer, emptying the buffer data\n");
|
||||
|
||||
m_frame_start = 0;
|
||||
m_buffer_data_len = 0;
|
||||
@ -92,7 +92,7 @@ void rtc_tcp_connection::user_on_tcp_connection_read()
|
||||
// parse again. Otherwise break here and wait for more data.
|
||||
if (m_buffer_data_len > m_frame_start)
|
||||
{
|
||||
// osd_printf_error("there is more data after the parsed frame, continue parsing");
|
||||
// osd_printf_error("there is more data after the parsed frame, continue parsing\n");
|
||||
|
||||
continue;
|
||||
}
|
||||
@ -110,7 +110,7 @@ void rtc_tcp_connection::user_on_tcp_connection_read()
|
||||
// the buffer, so move the frame to the position 0.
|
||||
if (m_frame_start != 0)
|
||||
{
|
||||
// osd_printf_error("no more space in the buffer, moving parsed bytes to the beginning of the buffer and wait for more data");
|
||||
// osd_printf_error("no more space in the buffer, moving parsed bytes to the beginning of the buffer and wait for more data\n");
|
||||
|
||||
std::memmove(m_buffer, m_buffer + m_frame_start, m_buffer_size - m_frame_start);
|
||||
m_buffer_data_len = m_buffer_size - m_frame_start;
|
||||
@ -120,7 +120,7 @@ void rtc_tcp_connection::user_on_tcp_connection_read()
|
||||
// The frame is too big, so close the connection.
|
||||
else
|
||||
{
|
||||
osd_printf_error("no more space in the buffer for the unfinished frame being parsed, closing the connection");
|
||||
osd_printf_error("no more space in the buffer for the unfinished frame being parsed, closing the connection\n");
|
||||
|
||||
// Close the socket.
|
||||
close();
|
||||
@ -129,7 +129,7 @@ void rtc_tcp_connection::user_on_tcp_connection_read()
|
||||
// The buffer is not full.
|
||||
else
|
||||
{
|
||||
osd_printf_verbose("frame not finished yet, waiting for more data");
|
||||
osd_printf_verbose("frame not finished yet, waiting for more data\n");
|
||||
}
|
||||
|
||||
// Exit the parsing loop.
|
||||
|
@ -187,7 +187,7 @@ void tcp_connection::write(const uint8_t* data, size_t len)
|
||||
// Error. Should not happen.
|
||||
else if (written < 0)
|
||||
{
|
||||
osd_printf_warning("uv_try_write() failed, closing the connection: %s", uv_strerror(written));
|
||||
osd_printf_warning("uv_try_write() failed, closing the connection: %s\n", uv_strerror(written));
|
||||
|
||||
close();
|
||||
return;
|
||||
@ -245,7 +245,7 @@ void tcp_connection::write(const uint8_t* data1, size_t len1, const uint8_t* dat
|
||||
// Error. Should not happen.
|
||||
else if (written < 0)
|
||||
{
|
||||
osd_printf_warning("uv_try_write() failed, closing the connection: %s", uv_strerror(written));
|
||||
osd_printf_warning("uv_try_write() failed, closing the connection: %s\n", uv_strerror(written));
|
||||
|
||||
close();
|
||||
return;
|
||||
@ -301,7 +301,7 @@ bool tcp_connection::set_peer_address()
|
||||
err = uv_tcp_getpeername(m_uv_handle, (struct sockaddr*)&m_peer_addr, &len);
|
||||
if (err)
|
||||
{
|
||||
osd_printf_error("uv_tcp_getpeername() failed: %s", uv_strerror(err));
|
||||
osd_printf_error("uv_tcp_getpeername() failed: %s\n", uv_strerror(err));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -329,7 +329,7 @@ void tcp_connection::on_uv_read_alloc(size_t suggested_size, uv_buf_t* buf)
|
||||
{
|
||||
buf->len = 0;
|
||||
|
||||
osd_printf_warning("no available space in the buffer");
|
||||
osd_printf_warning("no available space in the buffer\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ void tcp_connection::on_uv_read(::ssize_t nread, const uv_buf_t* buf)
|
||||
// Client disconneted.
|
||||
else if (nread == UV_EOF || nread == UV_ECONNRESET)
|
||||
{
|
||||
osd_printf_info("connection closed by peer, closing server side");
|
||||
osd_printf_verbose("connection closed by peer, closing server side\n");
|
||||
|
||||
m_is_closed_by_peer = true;
|
||||
|
||||
@ -363,7 +363,7 @@ void tcp_connection::on_uv_read(::ssize_t nread, const uv_buf_t* buf)
|
||||
// Some error.
|
||||
else
|
||||
{
|
||||
osd_printf_info("read error, closing the connection: %s", uv_strerror(nread));
|
||||
osd_printf_verbose("read error, closing the connection: %s\n", uv_strerror(nread));
|
||||
|
||||
m_has_error = true;
|
||||
|
||||
@ -379,11 +379,11 @@ void tcp_connection::on_uv_write_error(int error)
|
||||
|
||||
if (error == UV_EPIPE || error == UV_ENOTCONN)
|
||||
{
|
||||
osd_printf_info("write error, closing the connection: %s", uv_strerror(error));
|
||||
osd_printf_verbose("write error, closing the connection: %s\n", uv_strerror(error));
|
||||
}
|
||||
else
|
||||
{
|
||||
osd_printf_info("write error, closing the connection: %s", uv_strerror(error));
|
||||
osd_printf_verbose("write error, closing the connection: %s\n", uv_strerror(error));
|
||||
|
||||
m_has_error = true;
|
||||
}
|
||||
@ -396,9 +396,9 @@ void tcp_connection::on_uv_shutdown(uv_shutdown_t* req, int status)
|
||||
delete req;
|
||||
|
||||
if (status == UV_EPIPE || status == UV_ENOTCONN || status == UV_ECANCELED)
|
||||
osd_printf_info("shutdown error: %s", uv_strerror(status));
|
||||
osd_printf_verbose("shutdown error: %s\n", uv_strerror(status));
|
||||
else if (status)
|
||||
osd_printf_info("shutdown error: %s", uv_strerror(status));
|
||||
osd_printf_verbose("shutdown error: %s\n", uv_strerror(status));
|
||||
|
||||
// Now do close the handle.
|
||||
uv_close((uv_handle_t*)m_uv_handle, (uv_close_cb)on_close);
|
||||
|
@ -94,7 +94,7 @@ void tcp_server::close()
|
||||
// Otherwise close all the connections (but not the TCP server).
|
||||
else
|
||||
{
|
||||
osd_printf_info("closing %d active connections", (int)m_connections.size());
|
||||
osd_printf_verbose("closing %d active connections\n", (int)m_connections.size());
|
||||
|
||||
for (auto it = m_connections.begin(); it != m_connections.end(); ++it)
|
||||
{
|
||||
@ -119,7 +119,7 @@ void tcp_server::terminate()
|
||||
// Otherwise close all the connections (but not the TCP server).
|
||||
else
|
||||
{
|
||||
osd_printf_info("closing %d active connections", (int)m_connections.size());
|
||||
osd_printf_verbose("closing %d active connections\n", (int)m_connections.size());
|
||||
|
||||
for (auto it = m_connections.begin(); it != m_connections.end(); ++it)
|
||||
{
|
||||
@ -144,7 +144,7 @@ void tcp_server::send_to_all(const uint8_t* data, size_t len)
|
||||
|
||||
void tcp_server::dump()
|
||||
{
|
||||
osd_printf_info("[TCP, local:%s :%d, status:%s, connections:%d]",
|
||||
osd_printf_verbose("[TCP, local:%s :%d, status:%s, connections:%d]",
|
||||
m_local_ip.c_str(), (uint16_t)m_local_port,
|
||||
(!m_is_closing) ? "open" : "closed",
|
||||
(int)m_connections.size());
|
||||
@ -173,7 +173,7 @@ bool tcp_server::set_local_address()
|
||||
err = uv_tcp_getsockname(m_uv_handle, (struct sockaddr*)&m_local_addr, &len);
|
||||
if (err)
|
||||
{
|
||||
osd_printf_error("uv_tcp_getsockname() failed: %s", uv_strerror(err));
|
||||
osd_printf_error("uv_tcp_getsockname() failed: %s\n", uv_strerror(err));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -193,7 +193,7 @@ inline void tcp_server::on_uv_connection(int status)
|
||||
|
||||
if (status)
|
||||
{
|
||||
osd_printf_error("error while receiving a new TCP connection: %s", uv_strerror(status));
|
||||
osd_printf_error("error while receiving a new TCP connection: %s\n", uv_strerror(status));
|
||||
|
||||
return;
|
||||
}
|
||||
@ -201,8 +201,8 @@ inline void tcp_server::on_uv_connection(int status)
|
||||
// Notify the subclass so it provides an allocated derived class of TCPConnection.
|
||||
tcp_connection* connection = nullptr;
|
||||
user_on_tcp_connection_alloc(&connection);
|
||||
if (connection != nullptr)
|
||||
osd_printf_error("tcp_server pointer was not allocated by the user");
|
||||
if (connection == nullptr)
|
||||
osd_printf_error("tcp_server pointer was not allocated by the user\n");
|
||||
|
||||
try
|
||||
{
|
||||
@ -217,7 +217,7 @@ inline void tcp_server::on_uv_connection(int status)
|
||||
// Accept the connection.
|
||||
err = uv_accept((uv_stream_t*)m_uv_handle, (uv_stream_t*)connection->get_uv_handle());
|
||||
if (err)
|
||||
throw emu_fatalerror("uv_accept() failed: %s", uv_strerror(err));
|
||||
throw emu_fatalerror("uv_accept() failed: %s\n", uv_strerror(err));
|
||||
|
||||
// Insert the TCPConnection in the set.
|
||||
m_connections.insert(connection);
|
||||
@ -229,13 +229,13 @@ inline void tcp_server::on_uv_connection(int status)
|
||||
}
|
||||
catch (emu_exception &error)
|
||||
{
|
||||
osd_printf_error("cannot run the TCP connection, closing the connection: %s", error.what());
|
||||
osd_printf_error("cannot run the TCP connection, closing the connection: %s\n", error.what());
|
||||
connection->close();
|
||||
// NOTE: Don't return here so the user won't be notified about a "onclose" for a TCP connection
|
||||
// for which there was not a previous "onnew" event.
|
||||
}
|
||||
|
||||
osd_printf_info("new TCP connection:");
|
||||
osd_printf_verbose("new TCP connection:\n");
|
||||
connection->dump();
|
||||
|
||||
// Notify the subclass.
|
||||
@ -263,7 +263,7 @@ void tcp_server::on_tcp_connection_closed(tcp_connection* connection, bool is_cl
|
||||
|
||||
bool wasClosing = m_is_closing;
|
||||
|
||||
osd_printf_info("TCP connection closed:");
|
||||
osd_printf_verbose("TCP connection closed:\n");
|
||||
connection->dump();
|
||||
|
||||
// Remove the TCPConnection from the set.
|
||||
|
Loading…
Reference in New Issue
Block a user