Ack with minor comment: Return type from strlen() is size_t, and return type from send() is ssize_t. So a more type-correct way to implement this is outlined in my inlined comments in the code below.

regards,

Anders Widell


On 03/09/2018 02:44 AM, Gary Lee wrote:
---
  src/rde/agent/rda_papi.cc | 8 +++++---
  src/rde/rded/rde_rda.cc   | 8 +++++---
  2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/rde/agent/rda_papi.cc b/src/rde/agent/rda_papi.cc
index a07d2b06f..57ad57761 100644
--- a/src/rde/agent/rda_papi.cc
+++ b/src/rde/agent/rda_papi.cc
@@ -654,14 +654,16 @@ static PCSRDA_RETURN_CODE rda_callback_req(int sockfd, 
PCS_RDA_ROLE *role) {
*****************************************************************************/
  static PCSRDA_RETURN_CODE rda_write_msg(int sockfd, char *msg) {
-  int msg_size = 0;
+  const int msg_size = strlen(msg) + 1;

AndersW> const size_t msg_size = strlen(msg) + 1;

+  int bytes_sent = 0;

AndersW> Remove the line above.
/*
     ** Read from socket into input buffer
     */
- msg_size = send(sockfd, msg, strlen(msg) + 1, 0);
-  if (msg_size < 0) {
+  bytes_sent = send(sockfd, msg, msg_size, MSG_NOSIGNAL);

AndersW> Replace with: ssize_t bytes_sent = send(...

+  if (bytes_sent < 0 || bytes_sent != msg_size) {

AndersW> Replace with: if (bytes_sent < 0 || static_cast<size_t>(bytes_sent) != msg_size) {

+    // @todo handle partial write?
      return PCSRDA_RC_IPC_SEND_FAILED;
    }
diff --git a/src/rde/rded/rde_rda.cc b/src/rde/rded/rde_rda.cc
index 04e1c4bfc..ab9f25d77 100644
--- a/src/rde/rded/rde_rda.cc
+++ b/src/rde/rded/rde_rda.cc
@@ -179,11 +179,13 @@ static uint32_t rde_rda_sock_close(RDE_RDA_CB 
*rde_rda_cb) {
   
*****************************************************************************/
  static uint32_t rde_rda_write_msg(int fd, char *msg) {
    int rc = NCSCC_RC_SUCCESS;
-  int msg_size = 0;
+  const int msg_size = strlen(msg) + 1;
+  int bytes_sent = 0;

AndersW> Same comments as above.

TRACE_ENTER2("%u - '%s'", fd, msg);
-  msg_size = send(fd, msg, strlen(msg) + 1, 0);
-  if (msg_size < 0) {
+  bytes_sent = send(fd, msg, msg_size, MSG_NOSIGNAL);
+  if (bytes_sent < 0 || bytes_sent != msg_size) {
+    // @todo handle partial write?
      if (errno != EINTR && errno != EWOULDBLOCK)
        LOG_ER("send FAILED %s", strerror(errno));


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to