for(;;) {
ConnectionInfo* citmp, ci;
- readn2(pipefd, &citmp, sizeof(citmp));
+ try {
+ readn2(pipefd, &citmp, sizeof(citmp));
+ }
+ catch(const std::runtime_error& e) {
+ throw std::runtime_error("Error reading from TCP acceptor pipe (" + std::to_string(pipefd) + ") in " + std::string(isNonBlocking(pipefd) ? "non-blocking" : "blocking") + " mode: " + e.what());
+ }
+
--g_tcpclientthreads->d_queued;
ci=*citmp;
delete citmp;
break;
}
- int dsock;
+ int dsock = -1;
if(sockets.count(ds->remote) == 0) {
dsock=sockets[ds->remote]=setupTCPDownstream(ds);
}
if (ds->retries > 0 && downstream_failures > ds->retries) {
vinfolog("Downstream connection to %s failed %d times in a row, giving up.", ds->getName(), downstream_failures);
close(dsock);
+ dsock=-1;
sockets.erase(ds->remote);
break;
}
--g_tcpclientthreads->d_queued;
close(ci->fd);
delete ci;
+ ci=nullptr;
}
}
catch(std::exception& e) {
return true;
}
+bool isNonBlocking(int sock)
+{
+ int flags=fcntl(sock,F_GETFL,0);
+ return flags & O_NONBLOCK;
+}
+
// Closes a socket.
int closesocket( int socket )
{
//! Sets the socket into non-blocking mode.
bool setNonBlocking( int sock );
+bool isNonBlocking(int sock);
int closesocket(int fd);
bool setCloseOnExec(int sock);
uint64_t udpErrorStats(const std::string& str);