UIPMC_Message_Block_Data_Iterator.cpp

Go to the documentation of this file.
00001 // $Id: UIPMC_Message_Block_Data_Iterator.cpp 71526 2006-03-14 06:14:35Z jtc $
00002 
00003 #include "orbsvcs/PortableGroup/UIPMC_Message_Block_Data_Iterator.h"
00004 
00005 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00006 
00007 UIPMC_Message_Block_Data_Iterator::UIPMC_Message_Block_Data_Iterator (iovec *iov, int iovcnt) :
00008   iov_ (iov),
00009   iovcnt_ (iovcnt),
00010   iov_ptr_ (0),
00011   iov_index_ (0),
00012   iov_len_left_ (0),
00013   state_ (INTER_BLOCK)
00014 {
00015 }
00016 
00017 size_t
00018 UIPMC_Message_Block_Data_Iterator::next_block (size_t max_length,
00019                                                iovec &block)
00020 {
00021   if (this->state_ == INTER_BLOCK)
00022     {
00023       // Check that there are some iovec buffers left.
00024       if (this->iov_index_ >= this->iovcnt_)
00025         return 0;
00026 
00027 
00028       size_t current_iov_len =
00029                     this->iov_[this->iov_index_].iov_len;
00030 
00031       if (current_iov_len <= max_length)
00032         {
00033           // Return the full data portion.
00034           block.iov_len = static_cast<u_long> (current_iov_len);
00035           block.iov_base = this->iov_[this->iov_index_].iov_base;
00036 
00037           // Go to the next block.
00038           this->iov_index_++;
00039 
00040           return current_iov_len;
00041         }
00042       else
00043         {
00044           // Let the caller use the first part of this
00045           // message block.
00046           block.iov_len = static_cast<u_long> (max_length);
00047           block.iov_base = this->iov_[this->iov_index_].iov_base;
00048 
00049           // Break up the block.
00050           this->iov_len_left_ = current_iov_len - max_length;
00051           this->iov_ptr_ =
00052             reinterpret_cast<char *> (reinterpret_cast<char *> (block.iov_base)
00053                                   + max_length);
00054           this->state_ = INTRA_BLOCK;
00055 
00056           return max_length;
00057         }
00058     }
00059   else
00060     {
00061       // Currently scanning a split block.
00062       if (this->iov_len_left_ <= max_length)
00063         {
00064           // Return everything that's left in the block.
00065           block.iov_len = static_cast<u_long> (this->iov_len_left_);
00066           block.iov_base = this->iov_ptr_;
00067 
00068           // Go to the next block.
00069           this->iov_index_++;
00070 
00071           // Update the state.
00072           this->state_ = INTER_BLOCK;
00073 
00074           return this->iov_len_left_;
00075         }
00076       else
00077         {
00078           // Split a little more off the block.
00079           block.iov_len = static_cast<u_long> (this->iov_len_left_);
00080           block.iov_base = this->iov_ptr_;
00081 
00082           this->iov_len_left_ -= max_length;
00083           this->iov_ptr_ += max_length;
00084           return max_length;
00085         }
00086     }
00087 }
00088 
00089 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:49:50 2010 for TAO_PortableGroup by  doxygen 1.4.7