79370925

Date: 2025-01-20 10:16:16
Score: 0.5
Natty:
Report link

The problem is that the SIGPIPE signal terminates the program and the connection to the server is not implemented securely. It would be safer to entrust the reconnection work to one thread.

To ignore SIGPIPE:

#include <signal.h>
...
...
...
int main():
    signal(SIGPIPE, SIG_IGN);
...

And from thread1 need to remove reconnection part:

{
std::lock_guard<std::mutex> lock(atom_mtx);
            if (!connected.load())
            {
                std::cerr << "No connection to the server" << std::endl;
                connect_to_server();
            }
}
         
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: crono