From 11d641f20f58ce5385d21f264849b7ba52e13fb6 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 29 Nov 2018 11:28:37 +0100 Subject: [PATCH] rec: Use the timeout passed to rec_control for sending too --- pdns/rec_channel.cc | 10 +++++++++- pdns/rec_channel.hh | 2 +- pdns/rec_control.cc | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pdns/rec_channel.cc b/pdns/rec_channel.cc index 2bbb54c1a3..cec4dff6a7 100644 --- a/pdns/rec_channel.cc +++ b/pdns/rec_channel.cc @@ -108,8 +108,16 @@ void RecursorControlChannel::connect(const string& path, const string& fname) } } -void RecursorControlChannel::send(const std::string& msg, const std::string* remote) +void RecursorControlChannel::send(const std::string& msg, const std::string* remote, unsigned int timeout) { + int ret = waitForRWData(d_fd, false, timeout, 0); + if(ret == 0) { + throw PDNSException("Timeout sending message over control channel"); + } + else if(ret < 0) { + throw PDNSException("Error sending message over control channel:" + string(strerror(errno))); + } + if(remote) { struct sockaddr_un remoteaddr; memset(&remoteaddr, 0, sizeof(remoteaddr)); diff --git a/pdns/rec_channel.hh b/pdns/rec_channel.hh index 1b8e4d8f30..0fadd41259 100644 --- a/pdns/rec_channel.hh +++ b/pdns/rec_channel.hh @@ -44,7 +44,7 @@ public: uint64_t getStat(const std::string& name); - void send(const std::string& msg, const std::string* remote=0); + void send(const std::string& msg, const std::string* remote=nullptr, unsigned int timeout=5); std::string recv(std::string* remote=0, unsigned int timeout=5); int d_fd; diff --git a/pdns/rec_control.cc b/pdns/rec_control.cc index 90f6fd1c21..56f6776c36 100644 --- a/pdns/rec_control.cc +++ b/pdns/rec_control.cc @@ -104,7 +104,7 @@ try command+=" "; command+=commands[i]; } - rccS.send(command); + rccS.send(command, nullptr, arg().asNum("timeout")); string receive=rccS.recv(0, arg().asNum("timeout")); if(receive.compare(0, 7, "Unknown") == 0) { cerr<