Change the send Buffer size dynamically

On a Linux system the send buffer size has defaulted
to around 90k, and when a pldm message is sent via
the pldm_send() that is bigger than 90k, we get an error
ENOBUFS (No buffer space avilable).

This commit would dynamically change the socket parameter
(SO_SNDBUF) to set the new maximum socket send buffer size
so that we can successfully send the message.

Tested By:

1. hard coded the current buffer size value to 10 and forced
   the buffer size to be increase for mutiple commands & was able
   to power on the host with out any problems.

Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
Change-Id: I5f7a3948ea019b4dc983cf5e1926cfc128c02084
diff --git a/requester/request.hpp b/requester/request.hpp
index 24e6942..2f2470f 100644
--- a/requester/request.hpp
+++ b/requester/request.hpp
@@ -6,6 +6,8 @@
 #include "common/types.hpp"
 #include "common/utils.hpp"
 
+#include <sys/socket.h>
+
 #include <sdbusplus/timer.hpp>
 #include <sdeventplus/event.hpp>
 
@@ -141,6 +143,7 @@
      *
      *  @param[in] fd - fd of the MCTP communication socket
      *  @param[in] eid - endpoint ID of the remote MCTP endpoint
+     *  @param[in] currrentSendbuffSize - the current send buffer size
      *  @param[in] event - reference to PLDM daemon's main event loop
      *  @param[in] requestMsg - PLDM request message
      *  @param[in] numRetries - number of request retries
@@ -149,16 +152,19 @@
      */
     explicit Request(int fd, mctp_eid_t eid, sdeventplus::Event& event,
                      pldm::Request&& requestMsg, uint8_t numRetries,
-                     std::chrono::milliseconds timeout, bool verbose) :
+                     std::chrono::milliseconds timeout, int currentSendbuffSize,
+                     bool verbose) :
         RequestRetryTimer(event, numRetries, timeout),
-        fd(fd), eid(eid), requestMsg(std::move(requestMsg)), verbose(verbose)
+        fd(fd), eid(eid), requestMsg(std::move(requestMsg)),
+        currentSendbuffSize(currentSendbuffSize), verbose(verbose)
     {}
 
   private:
     int fd;                   //!< file descriptor of MCTP communications socket
     mctp_eid_t eid;           //!< endpoint ID of the remote MCTP endpoint
     pldm::Request requestMsg; //!< PLDM request message
-    bool verbose;             //!< verbose tracing flag
+    mutable int currentSendbuffSize; //!< current Send Buffer size
+    bool verbose;                    //!< verbose tracing flag
 
     /** @brief Sends the PLDM request message on the socket
      *
@@ -170,6 +176,24 @@
         {
             pldm::utils::printBuffer(pldm::utils::Tx, requestMsg);
         }
+        if (currentSendbuffSize >= 0 &&
+            (size_t)currentSendbuffSize < requestMsg.size())
+        {
+            int oldSendbuffSize = currentSendbuffSize;
+            currentSendbuffSize = requestMsg.size();
+            int res =
+                setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &currentSendbuffSize,
+                           sizeof(currentSendbuffSize));
+            if (res == -1)
+            {
+                std::cerr
+                    << "Requester : Failed to set the new send buffer size [bytes] : "
+                    << currentSendbuffSize
+                    << " from current size [bytes]: " << oldSendbuffSize
+                    << " , Error : " << strerror(errno) << std::endl;
+                return PLDM_ERROR;
+            }
+        }
         auto rc = pldm_send(eid, fd, requestMsg.data(), requestMsg.size());
         if (rc < 0)
         {