diff options
author | Steve Huston <shuston@riverace.com> | 2022-03-19 19:30:31 +0000 |
---|---|---|
committer | Steve Huston <shuston@riverace.com> | 2022-03-19 19:30:31 +0000 |
commit | 7cf5c386fe0a5df066a7296e687a23b06e93d672 (patch) | |
tree | 816847c9c5e2f47b84c985277ac15db9257ca328 | |
parent | bbe56f774f23d10bff8d082500e321ee9dda6bcb (diff) | |
download | ATCD-7cf5c386fe0a5df066a7296e687a23b06e93d672.tar.gz |
Refactor switch to avoid fallthrough and read easier
-rw-r--r-- | ACE/ace/Name_Proxy.cpp | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/ACE/ace/Name_Proxy.cpp b/ACE/ace/Name_Proxy.cpp index 3e4a676e4b0..95a905102a8 100644 --- a/ACE/ace/Name_Proxy.cpp +++ b/ACE/ace/Name_Proxy.cpp @@ -145,55 +145,55 @@ ACE_Name_Proxy::recv_reply (ACE_Name_Request &reply) // implementation assumes that the first 4 bytes are the length of // the message. ssize_t n = this->peer_.recv ((void *) &reply, sizeof (ACE_UINT32)); + if (n != sizeof (ACE_UINT32)) + { + // Not the correct number of bytes. Sort out just what kind of fail, + // but this is wrong and will end up failing the call. + if (n == -1) + { + ACELIB_DEBUG ((LM_DEBUG, + ACE_TEXT ("****************** recv_reply returned -1\n"))); + } + else if (n != 0) + { + ACELIB_ERROR ((LM_ERROR, + ACE_TEXT ("%p got %d bytes, expected %d bytes\n"), + ACE_TEXT ("recv failed"), + n, + sizeof (ACE_UINT32))); + } + // If 0, no diagnostic - the peer shut it down. + // We've shutdown unexpectedly + return -1; + } + + // Transform the length into host byte order. + ssize_t length = ACE_NTOHL (reply.length ()); + + // Receive the rest of the request message. + // @@ beware of blocking read!!!. + n = this->peer_.recv ((void *) (((char *) &reply) + + sizeof (ACE_UINT32)), + length - sizeof (ACE_UINT32)); - switch (n) + // Subtract off the size of the part we skipped over... + if (n != ssize_t (length - sizeof (ACE_UINT32))) { - case -1: - ACELIB_DEBUG ((LM_DEBUG, - ACE_TEXT ("****************** recv_reply returned -1\n"))); - ACE_FALLTHROUGH; - default: ACELIB_ERROR ((LM_ERROR, - ACE_TEXT ("%p got %d bytes, expected %d bytes\n"), - ACE_TEXT ("recv failed"), - n, - sizeof (ACE_UINT32))); - ACE_FALLTHROUGH; - case 0: - // We've shutdown unexpectedly + ACE_TEXT ("%p expected %d, got %d\n"), + ACE_TEXT ("invalid length"), + length, + n)); + return -1; + } + + // Decode the request into host byte order. + if (reply.decode () == -1) + { + ACELIB_ERROR ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("decode failed"))); return -1; - // NOTREACHED - case sizeof (ACE_UINT32): - { - // Transform the length into host byte order. - ssize_t length = ACE_NTOHL (reply.length ()); - - // Receive the rest of the request message. - // @@ beware of blocking read!!!. - n = this->peer_.recv ((void *) (((char *) &reply) - + sizeof (ACE_UINT32)), - length - sizeof (ACE_UINT32)); - - // Subtract off the size of the part we skipped over... - if (n != ssize_t (length - sizeof (ACE_UINT32))) - { - ACELIB_ERROR ((LM_ERROR, - ACE_TEXT ("%p expected %d, got %d\n"), - ACE_TEXT ("invalid length"), - length, - n)); - return -1; - } - - // Decode the request into host byte order. - if (reply.decode () == -1) - { - ACELIB_ERROR ((LM_ERROR, - ACE_TEXT ("%p\n"), - ACE_TEXT ("decode failed"))); - return -1; - } - } } return 0; } |