Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various bugfixes and logging improvements #90

Draft
wants to merge 3 commits into
base: v2-beta
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
cmake-get_encap_msg*
cmake-build*
get_encap_msg

build/
1 change: 0 additions & 1 deletion src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ void Config::parse_grouping(const YAML::Node &node) {
}

Config::~Config() {
delete singleton_instance;
}


Expand Down
2 changes: 0 additions & 2 deletions src/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 0 additions & 1 deletion src/MessageBus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ MessageBus::MessageBus() {

MessageBus::~MessageBus() {
disconnect();
delete singleton_instance;
delete producer_config;
delete event_callback;
}
Expand Down
23 changes: 19 additions & 4 deletions src/SockBuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* Copyright (c) 2013-2016 Cisco Systems, Inc. and others. All rights reserved.
* Copyright (c) 2019 Lumin Shi. All rights reserved.
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down