diff --git a/.gitignore b/.gitignore index b19a59c..dadd420 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ cmake-get_encap_msg* cmake-build* get_encap_msg - +build/ diff --git a/src/Config.cpp b/src/Config.cpp index c6b79db..da40f21 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -515,7 +515,6 @@ void Config::parse_grouping(const YAML::Node &node) { } Config::~Config() { - delete singleton_instance; } diff --git a/src/Logger.cpp b/src/Logger.cpp index 46d90c5..b0ea77e 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -92,8 +92,6 @@ Logger::Logger(const char *log_filename, const char *debug_filename) { * Destructor for class ***********************************************************************/ Logger::~Logger() { - delete singleton_instance; - /* * Close open files */ diff --git a/src/MessageBus.cpp b/src/MessageBus.cpp index acce6db..7b56c10 100644 --- a/src/MessageBus.cpp +++ b/src/MessageBus.cpp @@ -47,7 +47,6 @@ MessageBus::MessageBus() { MessageBus::~MessageBus() { disconnect(); - delete singleton_instance; delete producer_config; delete event_callback; } diff --git a/src/SockBuffer.cpp b/src/SockBuffer.cpp index eea6884..083d578 100644 --- a/src/SockBuffer.cpp +++ b/src/SockBuffer.cpp @@ -1,3 +1,4 @@ + /* * Copyright (c) 2013-2016 Cisco Systems, Inc. and others. All rights reserved. * Copyright (c) 2019 Lumin Shi. All rights reserved. @@ -78,12 +79,18 @@ void SockBuffer::stop() { } void SockBuffer::save_data() { + int prc; if ((wrap_state and (write_position + 1) < read_position) or (not wrap_state and write_position < ring_buffer_size)) { // Attempt to read from socket - if (poll(&pfd_tcp, 1, 5)) { + prc = poll(&pfd_tcp, 1, 5); + if (prc < 0) { + LOG_ERR("tcp poll failed (%d)", errno); + throw "tcp poll failed"; + } else if (prc > 0) { if (pfd_tcp.revents & POLLHUP or pfd_tcp.revents & POLLERR) { + LOG_INFO("peer closed tcp connection"); bytes_read = 0; // Indicate to close the connection } else { if (not wrap_state) { @@ -108,7 +115,14 @@ void SockBuffer::save_data() { close(writer_fd); close(reader_fd); close(router_tcp_fd); - throw "bad tcp connection."; + if (bytes_read < 0) { + LOG_ERR("tcp read failed: %d", errno); + throw "tcp read failed"; + } else { + LOG_INFO("tcp connection eof"); + running = false; + return; + } } else { sock_buf_write_ptr += bytes_read; @@ -222,8 +236,9 @@ void SockBuffer::sock_bufferer() { try { save_data(); push_data(); - } catch (...) { - LOG_INFO("%s: Thread for sock [%d] ended abnormally: ", router_ip.c_str(), router_tcp_fd); + } catch (const char *err) { + LOG_ERR("%s: Thread for sock [%d] ended abnormally: %s", + router_ip.c_str(), router_tcp_fd, err); // set running to false to exit the while loop. running = false; } diff --git a/src/Worker.cpp b/src/Worker.cpp index ac87edb..8d7ec85 100644 --- a/src/Worker.cpp +++ b/src/Worker.cpp @@ -207,7 +207,7 @@ void Worker::refill_buffer(int recv_len) { received_bytes = recv(reader_fd,get_unread_buffer() + get_bmp_data_unread_len(), recv_len,MSG_WAITALL); if (received_bytes <= 0) { - LOG_INFO("bad connection"); + LOG_INFO("sock_buffer terminated, worker stopping"); // set worker status to stopped. the main thread will clean up later. status = WORKER_STATUS_STOPPED; }