From: Wieger Opmeer Date: Mon, 2 Mar 2015 12:21:44 +0000 (+0100) Subject: second take of busy waiting fix, now with blocking io X-Git-Tag: auth-3.4.4~17^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=21cdbe5298bac81214251c38dbcc8b740241f770;p=pdns second take of busy waiting fix, now with blocking io --- diff --git a/modules/remotebackend/unixconnector.cc b/modules/remotebackend/unixconnector.cc index 6f8beedba..402b2b8b1 100644 --- a/modules/remotebackend/unixconnector.cc +++ b/modules/remotebackend/unixconnector.cc @@ -53,6 +53,14 @@ int UnixsocketConnector::recv_message(rapidjson::Document &output) { s_output = ""; while((t.tv_sec - t0.tv_sec)*1000 + (t.tv_usec - t0.tv_usec)/1000 < this->timeout) { + int avail = waitForData(this->fd, 0, this->timeout * 500); // use half the timeout as poll timeout + if (avail < 0) // poll error + return -1; + if (avail == 0) { // timeout + gettimeofday(&t, NULL); + continue; + } + std::string temp; temp.clear(); @@ -110,7 +118,7 @@ ssize_t UnixsocketConnector::write(const std::string &data) { nbuf = data.copy(buf, sizeof buf, pos); // copy data and write nwrite = ::write(fd, buf, nbuf); pos = pos + sizeof(buf); - if (nwrite == -1) { + if (nwrite < 1) { connected = false; close(fd); return -1; @@ -141,17 +149,7 @@ void UnixsocketConnector::reconnect() { return; } - if (fcntl(fd, F_SETFL, O_NONBLOCK, &fd)) { - connected = false; - L<(&sock), sizeof sock))==-1 && (errno == EINPROGRESS)) { - waitForData(fd, 0, -1); - rv = connect(fd, reinterpret_cast(&sock), sizeof sock); - } + rv = connect(fd, reinterpret_cast(&sock), sizeof sock); if (rv != 0 && errno != EISCONN && errno != 0) { L<