]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
For setting socket buf size not decreasing is not an error 12345/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 16 Dec 2022 08:24:44 +0000 (09:24 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 20 Dec 2022 08:46:25 +0000 (09:46 +0100)
(cherry picked from commit fe65dec04f3fadaca8f5319cf02f4b302463afe9)

pdns/iputils.cc

index 528ae9014972c8c585b7d1c14975e7506f281b28..12263687389d6b2568e1a997f74eb44f1e8ff1b2 100644 (file)
@@ -516,11 +516,13 @@ void setSocketBuffer(int fd, int optname, uint32_t size)
   uint32_t psize = 0;
   socklen_t len = sizeof(psize);
 
-  if (!getsockopt(fd, SOL_SOCKET, optname, &psize, &len) && psize > size) {
-    throw std::runtime_error("Not decreasing socket buffer size from " + std::to_string(psize) + " to " + std::to_string(size));
+  if (getsockopt(fd, SOL_SOCKET, optname, &psize, &len) != 0) {
+    throw std::runtime_error("Unable to retrieve socket buffer size:" + stringerror());
   }
-
-  if (setsockopt(fd, SOL_SOCKET, optname, &size, sizeof(size)) < 0) {
+  if (psize >= size) {
+    return;
+  }
+  if (setsockopt(fd, SOL_SOCKET, optname, &size, sizeof(size)) != 0) {
     throw std::runtime_error("Unable to raise socket buffer size to " + std::to_string(size) + ": " + stringerror());
   }
 }