vinfolog("Adding TCP Client thread");
int pipefds[2] = { -1, -1};
- if(pipe(pipefds) < 0)
- unixDie("Creating pipe");
+ if (pipe(pipefds) < 0) {
+ errlog("Error creating the TCP thread communication pipe: %s", strerror(errno));
+ return;
+ }
if (!setNonBlocking(pipefds[1])) {
close(pipefds[0]);
close(pipefds[1]);
- unixDie("Setting pipe non-blocking");
+ errlog("Error setting the TCP thread communication pipe non-blocking: %s", strerror(errno));
+ return;
+ }
+
+ try {
+ thread t1(tcpClientThread, pipefds[0]);
+ t1.detach();
+ }
+ catch(const std::runtime_error& e) {
+ /* the thread creation failed, don't leak */
+ errlog("Error creating a TCP thread: %s", e.what());
+ close(pipefds[0]);
+ close(pipefds[1]);
+ return;
}
d_tcpclientthreads.push_back(pipefds[1]);
++d_numthreads;
- thread t1(tcpClientThread, pipefds[0]);
- t1.detach();
}
static bool getNonBlockingMsgLen(int fd, uint16_t* len, int timeout)