diff --git a/Changelog b/Changelog index b7123ae..5a51588 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +2023-09-16: +- added message if a connection is closed. + 2022-10-31: - fixed use of uninitialized and wrong value. diff --git a/modbussrv.cc b/modbussrv.cc index d49687a..37286fe 100644 --- a/modbussrv.cc +++ b/modbussrv.cc @@ -179,12 +179,18 @@ void ModbusSrv::ServerThread() { char *msg; clients[slot] = tcp; msg = (char*) malloc (255); - snprintf (msg, 255, "new connection from %s\n", clients[slot]->GetRemoteAddr().c_str()); + snprintf (msg, 255, "new connection from %s, use slot:%d\n", clients[slot]->GetRemoteAddr().c_str(), slot); gdk_threads_add_idle(cb_thread_network_text_add, msg); } else { // no free slot, accept and close right away. - if (tcp) delete tcp; + if (tcp) { + char *msg; + msg = (char*) malloc (255); + snprintf (msg, 255, "no free slot, close connection.\n"); + gdk_threads_add_idle(cb_thread_network_text_add, msg); + delete tcp; + } } } @@ -195,6 +201,10 @@ void ModbusSrv::ServerThread() { if (clients[slot] != NULL) { len = clients[slot]->ReadTimeout(inbuffer, MODBUS_IOBUFFER, 0); if (len < 0) { + char *msg; + msg = (char*) malloc (255); + snprintf (msg, 255, "connection on slot %d closed.\n", slot); + gdk_threads_add_idle(cb_thread_network_text_add, msg); delete clients[slot]; clients[slot] = NULL; }