summaryrefslogtreecommitdiff
path: root/ace/UPIPE_Stream.cpp
diff options
context:
space:
mode:
authorSteve Huston <shuston@riverace.com>2003-01-09 00:32:09 +0000
committerSteve Huston <shuston@riverace.com>2003-01-09 00:32:09 +0000
commitb5790d9632001eab45ff82ff6fb44537d1c71833 (patch)
tree0436d350282959f3a1c0ed4cfc47b0bce7520ac4 /ace/UPIPE_Stream.cpp
parent0b33b70f7b6f138cfb8009d33d105efa1b378fe6 (diff)
downloadATCD-b5790d9632001eab45ff82ff6fb44537d1c71833.tar.gz
ChangeLogTag:Wed Jan 8 19:27:49 2003 Steve Huston <shuston@riverace.com>
Diffstat (limited to 'ace/UPIPE_Stream.cpp')
-rw-r--r--ace/UPIPE_Stream.cpp141
1 files changed, 64 insertions, 77 deletions
diff --git a/ace/UPIPE_Stream.cpp b/ace/UPIPE_Stream.cpp
index 1aa48c5f728..c66ccde36c9 100644
--- a/ace/UPIPE_Stream.cpp
+++ b/ace/UPIPE_Stream.cpp
@@ -16,7 +16,6 @@ ACE_ALLOC_HOOK_DEFINE(ACE_UPIPE_Stream)
ACE_UPIPE_Stream::ACE_UPIPE_Stream (void)
: mb_last_ (0),
- remaining_ (0),
reference_count_ (0)
{
ACE_TRACE ("ACE_UPIPE_Stream::ACE_UPIPE_STREAM");
@@ -25,12 +24,15 @@ ACE_UPIPE_Stream::ACE_UPIPE_Stream (void)
ACE_UPIPE_Stream::~ACE_UPIPE_Stream (void)
{
if (this->mb_last_ != 0)
- this->mb_last_->release ();
+ {
+ this->mb_last_->release ();
+ this->mb_last_ = 0;
+ }
}
int
ACE_UPIPE_Stream::control (int cmd,
- void * val) const
+ void * val) const
{
ACE_TRACE ("ACE_UPIPE_Stream::control");
@@ -58,7 +60,7 @@ ACE_UPIPE_Stream::close (void)
// checking to see if closing it now fails.
if (this->ACE_SPIPE::get_handle () != ACE_INVALID_HANDLE)
- this->ACE_SPIPE::close ();
+ this->ACE_SPIPE::close ();
// Close down the ACE_stream.
return this->stream_.close ();
@@ -76,14 +78,14 @@ ACE_UPIPE_Stream::get_remote_addr (ACE_UPIPE_Addr &remote_sap) const
int
ACE_UPIPE_Stream::send (ACE_Message_Block *mb_p,
- ACE_Time_Value *timeout)
+ ACE_Time_Value *timeout)
{
ACE_TRACE ("ACE_UPIPE_Stream::send_msg");
return this->stream_.put (mb_p, timeout) == -1 ? -1 : 0;
}
int ACE_UPIPE_Stream::recv (ACE_Message_Block *& mb_p,
- ACE_Time_Value *timeout)
+ ACE_Time_Value *timeout)
{
return this->stream_.get (mb_p, timeout) == -1 ? -1 : 0;
}
@@ -92,8 +94,8 @@ int ACE_UPIPE_Stream::recv (ACE_Message_Block *& mb_p,
ssize_t
ACE_UPIPE_Stream::send (const char *buffer,
- size_t n,
- ACE_Time_Value *timeout)
+ size_t n,
+ ACE_Time_Value *timeout)
{
ACE_TRACE ("ACE_UPIPE_Stream::send");
@@ -105,24 +107,15 @@ ACE_UPIPE_Stream::send (const char *buffer,
return
this->stream_.put (mb_p, timeout) == -1
? -1
- : ACE_static_cast (ssize_t, n); // @@ Steve, I silenced the
- // warning with a
- // static_cast<>. Is this
- // okay? BTW, even without the
- // cast, isn't this code
- // broken? What if 'n" is
- // greater than the maximum
- // value of a ssize_t? The
- // return value won't make any
- // sense.
+ : ACE_static_cast (ssize_t, n);
}
// Receive a buffer.
ssize_t
ACE_UPIPE_Stream::recv (char *buffer,
- size_t n,
- ACE_Time_Value *timeout)
+ size_t n,
+ ACE_Time_Value *timeout)
{
ACE_TRACE ("ACE_UPIPE_Stream::recv");
// Index in buffer.
@@ -131,55 +124,49 @@ ACE_UPIPE_Stream::recv (char *buffer,
while (bytes_read < n)
if (this->mb_last_ != 0)
{
- // We have remaining data in our last read Message_Buffer.
-
- if (this->remaining_ < n)
- {
- // The remaining data is not enough.
-
- ACE_OS::memcpy ((void *) &buffer[bytes_read],
- this->mb_last_->rd_ptr (),
- this->remaining_);
- bytes_read += this->remaining_;
- this->remaining_ = 0;
- this->mb_last_ = this->mb_last_->release ();
- return bytes_read;
- }
- else
- {
- // The remaining data is at least enough. If there's
- // more, we'll get it the next time through.
-
- ACE_OS::memcpy (&buffer[bytes_read],
- this->mb_last_->rd_ptr (),
- n);
- bytes_read += n;
-
- // Advance rd_ptr.
- this->mb_last_->rd_ptr (n);
- this->remaining_ -= n;
-
- if (this->remaining_ == 0)
- // Now the Message_Buffer is empty.
-
- this->mb_last_ = this->mb_last_->release ();
- }
+ // We have remaining data in our last read Message_Buffer.
+ size_t this_len = this->mb_last_->length ();
+ if (this_len < n)
+ {
+ // The remaining data is not enough.
+
+ ACE_OS::memcpy ((void *) &buffer[bytes_read],
+ this->mb_last_->rd_ptr (),
+ this_len);
+ bytes_read += this_len;
+ this->mb_last_ = this->mb_last_->release (); // mb_last_ now 0
+ return bytes_read;
+ }
+ else
+ {
+ // The remaining data is at least enough. If there's
+ // more, we'll get it the next time through.
+ ACE_OS::memcpy (&buffer[bytes_read],
+ this->mb_last_->rd_ptr (),
+ n);
+ bytes_read += n;
+
+ // Advance rd_ptr.
+ this->mb_last_->rd_ptr (n);
+
+ if (this->mb_last_->length () == 0)
+ // Now the Message_Buffer is empty.
+ this->mb_last_ = this->mb_last_->release ();
+ }
}
else
{
- // We have to get a new Message_Buffer from our stream.
-
- int result = this->stream_.get (this->mb_last_, timeout);
-
- if (result == -1)
- {
- if (errno == EWOULDBLOCK && bytes_read > 0)
- // Return the number of bytes read before we timed out.
- return bytes_read;
- else
- return -1;
- }
- this->remaining_ = this->mb_last_->size ();
+ // We have to get a new Message_Buffer from our stream.
+ int result = this->stream_.get (this->mb_last_, timeout);
+
+ if (result == -1)
+ {
+ if (errno == EWOULDBLOCK && bytes_read > 0)
+ // Return the number of bytes read before we timed out.
+ return bytes_read;
+ else
+ return -1;
+ }
}
return bytes_read;
@@ -187,8 +174,8 @@ ACE_UPIPE_Stream::recv (char *buffer,
ssize_t
ACE_UPIPE_Stream::send_n (const char *buf,
- size_t n,
- ACE_Time_Value *timeout)
+ size_t n,
+ ACE_Time_Value *timeout)
{
ACE_TRACE ("ACE_UPIPE_Stream::send_n");
@@ -200,11 +187,11 @@ ACE_UPIPE_Stream::send_n (const char *buf,
bytes_written += len)
{
len = this->send (buf + bytes_written,
- n - bytes_written,
- timeout);
+ n - bytes_written,
+ timeout);
if (len == -1)
- return -1;
+ return -1;
}
return bytes_written;
@@ -212,8 +199,8 @@ ACE_UPIPE_Stream::send_n (const char *buf,
ssize_t
ACE_UPIPE_Stream::recv_n (char *buf,
- size_t n,
- ACE_Time_Value *timeout)
+ size_t n,
+ ACE_Time_Value *timeout)
{
ACE_TRACE ("ACE_UPIPE_Stream::recv_n");
size_t bytes_read;
@@ -224,12 +211,12 @@ ACE_UPIPE_Stream::recv_n (char *buf,
bytes_read += len)
{
len = this->recv (buf + bytes_read,
- n - bytes_read,
- timeout);
+ n - bytes_read,
+ timeout);
if (len == -1)
- return -1;
+ return -1;
else if (len == 0)
- break;
+ break;
}
return bytes_read;