diff options
author | Steve Huston <shuston@riverace.com> | 2002-08-22 21:36:20 +0000 |
---|---|---|
committer | Steve Huston <shuston@riverace.com> | 2002-08-22 21:36:20 +0000 |
commit | c5c8c704703b8d5d176c8f3995baa6a27da19d84 (patch) | |
tree | 4d84d8ef233363408e5ebacc70913c1c8f8d5544 | |
parent | 4543cbb11424ebd435470e2ad902fec12ffa33a1 (diff) | |
download | ATCD-c5c8c704703b8d5d176c8f3995baa6a27da19d84.tar.gz |
ChangeLogTag:Thu Aug 22 17:34:18 2002 Steve Huston <shuston@riverace.com>
-rw-r--r-- | ace/FIFO_Recv_Msg.h | 54 | ||||
-rw-r--r-- | ace/FIFO_Recv_Msg.i | 39 |
2 files changed, 84 insertions, 9 deletions
diff --git a/ace/FIFO_Recv_Msg.h b/ace/FIFO_Recv_Msg.h index 3920e063630..493ab63e436 100644 --- a/ace/FIFO_Recv_Msg.h +++ b/ace/FIFO_Recv_Msg.h @@ -25,6 +25,17 @@ * @class ACE_FIFO_Recv_Msg * * @brief Receiver side for the record oriented C++ wrapper for UNIX FIFOs. + * + * This method works slightly differently on platforms with the + * @c ACE_HAS_STREAM_PIPES configuration setting than those without. + * With ACE_HAS_STREAM_PIPES, the @c getmsg() system function is used + * and it preserves message boundaries internally. Without + * @c ACE_HAS_STREAM_PIPES, the message boundaries are emulated by + * this class and ACE_FIFO_Send_Msg cooperating. The sending class + * first writes an integer number of bytes in the message, then the + * message. ACE_FIFO_Recv_Msg reads the count, then the data. + * The operational differences occur primarily when a message is larger + * than what a caller of this class requests. See recv() for details. */ class ACE_Export ACE_FIFO_Recv_Msg : public ACE_FIFO_Recv { @@ -47,10 +58,49 @@ public: int persistent = 1, LPSECURITY_ATTRIBUTES sa = 0); - /// Recv <msg> as an ACE_Str_Buf. + /// Receive a message based on attributes in an ACE_Str_Buf. + /** + * @param msg Reference to an ACE_Str_Buf whose @c buf member points + * to the memory to receive the data and @c maxlen member + * contains the maximum number of bytes to receive. + * On return after successfully reading data, the + * @c len member contains the number of bytes received and + * placed in the buffer pointed to by @c msg.buf. + * + * @retval -1 Error; consult @c errno for specific error number. + * @return If the @c ACE_HAS_STREAM_PIPES configuration setting is + * defined, the return value is the number of bytes received + * in the message and will be the same as @c buf.len. + * The return value from the @c getmsg() system function + * is discarded. + * If @c ACE_HAS_STREAM_PIPES is not defined, the number + * of bytes in the message read from the FIFO is returned. + * If the message is larger than the maximum length + * requested in @c msg.maxlen, the return value reflects + * the entire message length, and the @c msg.len member + * reflects how many bytes were actually placed in the + * caller's buffer. Any part of the message longer than + * @c msg.maxlen is discarded. + */ ssize_t recv (ACE_Str_Buf &msg); - /// Recv <msg> as a buffer. + /// Receive a message based on buffer pointer and maximum size. + /** + * @param buf Pointer to the memory to receive the data. + * @param len The maximum number of bytes to receive. + * + * @retval -1 Error; consult @c errno for specific error number. + * @return The number of bytes received in the message. For messages + * that are larger than the requested maximum size, the + * behavior is different depending on the @c ACE_HAS_STREAM_PIPES + * configuration setting. With @c ACE_HAS_STREAM_PIPES, + * the return value will be the same as @arg len (this is + * also possible if the message is exactly the same length + * as @arg len, and the two cases are indistinguishable). + * Without @c ACE_HAS_STREAM_PIPES, the return value is + * the total length of the message, including bytes in + * excess of @arg len. The excess bytes are discarded. + */ ssize_t recv (void *buf, size_t len); #if defined (ACE_HAS_STREAM_PIPES) diff --git a/ace/FIFO_Recv_Msg.i b/ace/FIFO_Recv_Msg.i index e47c0beef3e..b3ada5c2b1b 100644 --- a/ace/FIFO_Recv_Msg.i +++ b/ace/FIFO_Recv_Msg.i @@ -3,10 +3,6 @@ // FIFO_Recv_Msg.i -// Note that the return values mean different things if -// ACE_HAS_STREAM_PIPES vs. if it doesn't... See the manual page on -// getmsg(2) and read(2) for more details. - ASYS_INLINE ssize_t ACE_FIFO_Recv_Msg::recv (ACE_Str_Buf &recv_msg) { @@ -26,9 +22,38 @@ ACE_FIFO_Recv_Msg::recv (ACE_Str_Buf &recv_msg) sizeof recv_msg.len) != sizeof recv_msg.len) return -1; else - return ACE_OS::read (this->get_handle (), - (char *) recv_msg.buf, - (int) recv_msg.len); + { + size_t remaining = ACE_static_cast (size_t, recv_msg.len); + size_t requested = ACE_static_cast (size_t, recv_msg.maxlen); + ssize_t recv_len = ACE_OS::read (this->get_handle (), + (char *) recv_msg.buf, + ACE_MIN (remaining, requested)); + if (recv_len == -1) + return -1; + // Tell caller what's really in the buffer. + recv_msg.len = ACE_static_cast (int, recv_len); + + // If there are more bytes remaining in the message, read them and + // throw them away. Leaving them in the FIFO would make it difficult + // to find the start of the next message in the fifo. + // Since the ACE_HAS_STREAM_PIPES version of this method doesn't + // return getmsg()'s indication of "data remaining", don't worry about + // saving the indication here either to read the remainder later. + size_t total_msg_size = remaining; + remaining -= recv_len; + while (remaining > 0) + { + const size_t throw_away = 1024; + char dev_null[throw_away]; + recv_len = ACE_OS::read (this->get_handle (), + dev_null, + ACE_MIN (remaining, throw_away)); + if (recv_len == -1) + break; + remaining -= recv_len; + } + return total_msg_size; + } #endif /* ACE_HAS_STREAM_PIPES */ } |