From: Otto Moerbeek Date: Mon, 1 Jul 2019 08:07:41 +0000 (+0200) Subject: And a sweep of .hh files for stringerror(errno) -> stringerror() X-Git-Tag: dnsdist-1.4.0-rc3~39^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c52b8cb66acf27ffa984d647d1154447833b0886;p=pdns And a sweep of .hh files for stringerror(errno) -> stringerror() Plus zap some redundant string conversions. --- diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index a96a87b43..d822acba7 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -694,21 +694,22 @@ public: if (d_useSinglePipe) { if (pipe(d_singlePipe) < 0) { - throw std::runtime_error("Error creating the TCP single communication pipe: " + string(strerror(errno))); + int err = errno; + throw std::runtime_error("Error creating the TCP single communication pipe: " + stringerror(err)); } if (!setNonBlocking(d_singlePipe[0])) { int err = errno; close(d_singlePipe[0]); close(d_singlePipe[1]); - throw std::runtime_error("Error setting the TCP single communication pipe non-blocking: " + string(strerror(err))); + throw std::runtime_error("Error setting the TCP single communication pipe non-blocking: " + stringerror(err)); } if (!setNonBlocking(d_singlePipe[1])) { int err = errno; close(d_singlePipe[0]); close(d_singlePipe[1]); - throw std::runtime_error("Error setting the TCP single communication pipe non-blocking: " + string(strerror(err))); + throw std::runtime_error("Error setting the TCP single communication pipe non-blocking: " + stringerror(err)); } } } diff --git a/pdns/ixfrutils.cc b/pdns/ixfrutils.cc index b44529066..b9a342abb 100644 --- a/pdns/ixfrutils.cc +++ b/pdns/ixfrutils.cc @@ -125,7 +125,7 @@ void writeZoneToDisk(const records_t& records, const DNSName& zone, const std::s string fname=directory +"/"+std::to_string(serial); FILE* fp=fopen((fname+".partial").c_str(), "w"); if(!fp) - throw runtime_error("Unable to open file '"+fname+".partial' for writing: "+string(stringerror())); + throw runtime_error("Unable to open file '"+fname+".partial' for writing: "+stringerror()); records_t soarecord; soarecord.insert(soa); @@ -137,7 +137,7 @@ void writeZoneToDisk(const records_t& records, const DNSName& zone, const std::s fclose(fp); if (rename( (fname+".partial").c_str(), fname.c_str()) != 0) { - throw std::runtime_error("Unable to move the zone file for " + zone.toLogString() + " from " + fname + ".partial to " + fname + ": " + string(stringerror())); + throw std::runtime_error("Unable to move the zone file for " + zone.toLogString() + " from " + fname + ".partial to " + fname + ": " + stringerror()); } } diff --git a/pdns/nameserver.cc b/pdns/nameserver.cc index e45fa5cb0..4e56ac6a2 100644 --- a/pdns/nameserver.cc +++ b/pdns/nameserver.cc @@ -103,8 +103,8 @@ void UDPNameserver::bindIPv4() s=socket(AF_INET,SOCK_DGRAM,0); if(s<0) { - g_log<(new Socket(s)); @@ -135,10 +135,10 @@ public: { int tmp=1; if(reuseaddr && setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast(&tmp), sizeof tmp)<0) - throw NetworkError(string("Setsockopt failed: ")+strerror(errno)); + throw NetworkError("Setsockopt failed: "+stringerror()); if(::bind(d_socket, reinterpret_cast(&local), local.getSocklen())<0) - throw NetworkError("While binding: "+string(strerror(errno))); + throw NetworkError("While binding: "+stringerror()); } //! Connect the socket to a specified endpoint @@ -158,7 +158,7 @@ public: ssize_t bytes; d_buffer.resize(s_buflen); if((bytes=recvfrom(d_socket, &d_buffer[0], s_buflen, 0, reinterpret_cast(&ep) , &remlen)) <0) - throw NetworkError("After recvfrom: "+string(strerror(errno))); + throw NetworkError("After recvfrom: "+stringerror()); dgram.assign(d_buffer, 0, static_cast(bytes)); } @@ -171,7 +171,7 @@ public: d_buffer.resize(s_buflen); if((bytes=recvfrom(d_socket, &d_buffer[0], s_buflen, 0, reinterpret_cast(&remote), &remlen))<0) { if(errno!=EAGAIN) { - throw NetworkError("After async recvfrom: "+string(strerror(errno))); + throw NetworkError("After async recvfrom: "+stringerror()); } else { return false; @@ -186,14 +186,14 @@ public: void sendTo(const char* msg, size_t len, const ComboAddress &ep) { if(sendto(d_socket, msg, len, 0, reinterpret_cast(&ep), ep.getSocklen())<0) - throw NetworkError("After sendto: "+string(strerror(errno))); + throw NetworkError("After sendto: "+stringerror()); } //! For connected datagram sockets, send a datagram void send(const std::string& msg) { if(::send(d_socket, msg.c_str(), msg.size(), 0)<0) - throw NetworkError("After send: "+string(strerror(errno))); + throw NetworkError("After send: "+stringerror()); } @@ -219,7 +219,7 @@ public: do { res=::send(d_socket, ptr, toWrite, 0); if(res<0) - throw NetworkError("Writing to a socket: "+string(strerror(errno))); + throw NetworkError("Writing to a socket: "+stringerror()); if(!res) throw NetworkError("EOF on socket"); toWrite -= static_cast(res); @@ -246,7 +246,7 @@ public: if(errno==EAGAIN) return 0; - throw NetworkError("Writing to a socket: "+string(strerror(errno))); + throw NetworkError("Writing to a socket: "+stringerror()); } //! Writes toWrite bytes from ptr to the socket @@ -256,7 +256,7 @@ public: ssize_t res; res=::send(d_socket,ptr,toWrite,0); if(res<0) { - throw NetworkError("Writing to a socket: "+string(strerror(errno))); + throw NetworkError("Writing to a socket: "+stringerror()); } return res; } @@ -317,7 +317,7 @@ public: d_buffer.resize(s_buflen); ssize_t res=::recv(d_socket, &d_buffer[0], s_buflen, 0); if(res<0) - throw NetworkError("Reading from a socket: "+string(strerror(errno))); + throw NetworkError("Reading from a socket: "+stringerror()); data.assign(d_buffer, 0, static_cast(res)); } @@ -326,7 +326,7 @@ public: { ssize_t res=::recv(d_socket, buffer, bytes, 0); if(res<0) - throw NetworkError("Reading from a socket: "+string(strerror(errno))); + throw NetworkError("Reading from a socket: "+stringerror()); return static_cast(res); } @@ -337,7 +337,7 @@ public: if(err == 0) throw NetworkError("timeout reading"); if(err < 0) - throw NetworkError("nonblocking read failed: "+string(strerror(errno))); + throw NetworkError("nonblocking read failed: "+stringerror()); return read(buffer, n); } @@ -346,7 +346,7 @@ public: void listen(unsigned int length=10) { if(::listen(d_socket,length)<0) - throw NetworkError("Setting socket to listen: "+string(strerror(errno))); + throw NetworkError("Setting socket to listen: "+stringerror()); } //! Returns the internal file descriptor of the socket diff --git a/pdns/tcpiohandler.hh b/pdns/tcpiohandler.hh index dd82281a7..e125e16f1 100644 --- a/pdns/tcpiohandler.hh +++ b/pdns/tcpiohandler.hh @@ -219,7 +219,7 @@ public: return IOState::NeedRead; } else { - throw std::runtime_error(std::string("Error while reading message: ") + strerror(errno)); + throw std::runtime_error("Error while reading message: " + stringerror()); } } @@ -254,7 +254,7 @@ public: return IOState::NeedWrite; } else { - throw std::runtime_error(std::string("Error while writing message: ") + strerror(errno)); + throw std::runtime_error("Error while writing message: " + stringerror()); } }