On_Demand_Fragmentation_Strategy.cpp

Go to the documentation of this file.
00001 // On_Demand_Fragmentation_Strategy.cpp,v 1.2 2006/04/20 12:37:17 jwillemsen Exp
00002 
00003 
00004 #include "tao/On_Demand_Fragmentation_Strategy.h"
00005 
00006 #include "tao/Transport.h"
00007 #include "tao/CDR.h"
00008 #include "tao/Pluggable_Messaging.h"
00009 #include "tao/debug.h"
00010 
00011 TAO_On_Demand_Fragmentation_Strategy::TAO_On_Demand_Fragmentation_Strategy (
00012   TAO_Transport * transport,
00013   CORBA::ULong max_message_size)
00014   : transport_ (transport)
00015   , max_message_size_ (max_message_size)
00016 {
00017 }
00018 
00019 TAO_On_Demand_Fragmentation_Strategy::~TAO_On_Demand_Fragmentation_Strategy (
00020   void)
00021 {
00022 }
00023 
00024 int
00025 TAO_On_Demand_Fragmentation_Strategy::fragment (
00026   TAO_OutputCDR & cdr,
00027   ACE_CDR::ULong pending_alignment,
00028   ACE_CDR::ULong pending_length)
00029 {
00030   if (this->transport_ == 0)
00031     return 0;  // No transport.  Can't fragment.
00032 
00033   CORBA::Octet major = 0;
00034   CORBA::Octet minor = 0;
00035 
00036   (void) cdr.get_version (major, minor);
00037 
00038   // GIOP fragments are supported in GIOP 1.1 and better, but TAO only
00039   // supports them in 1.2 or better since GIOP 1.1 fragments do not
00040   // have a fragment message header.
00041   if (major == 1 && minor < 2)
00042     return -1;
00043 
00044   // Determine increase in CDR stream length if pending data is
00045   // marshaled, taking into account the alignment for the given data
00046   // type.
00047   ACE_CDR::ULong const total_pending_length =
00048     ACE_align_binary (cdr.total_length (), pending_alignment)
00049     + pending_length;
00050 
00051   // Except for the last fragment, fragmented GIOP messages must
00052   // always be aligned on an 8-byte boundary.  Padding will be added
00053   // if necessary.
00054   ACE_CDR::ULong const aligned_length =
00055     ACE_align_binary (total_pending_length, ACE_CDR::MAX_ALIGNMENT);
00056 
00057   // this->max_message_size_ must be >= 24 bytes, i.e.:
00058   //   12 for GIOP protocol header
00059   //  + 4 for GIOP fragment header
00060   //  + 8 for payload (including padding)
00061   // since fragments must be aligned on an 8 byte boundary.
00062   if (aligned_length > this->max_message_size_)
00063     {
00064       // Pad the outgoing fragment if necessary.
00065       if (cdr.align_write_ptr (ACE_CDR::MAX_ALIGNMENT) != 0)
00066         return -1;
00067 
00068       // More fragments to come.
00069       cdr.more_fragments (true);
00070 
00071       if (TAO_debug_level > 0)
00072         ACE_DEBUG ((LM_DEBUG,
00073                     "TAO (%P|%t) - On_Demand_Fragmentation_Strategy::fragment, "
00074                     "sending fragment of size %d\n",
00075                     cdr.total_length ()));
00076 
00077       // Send the current CDR stream contents through the transport,
00078       // making sure to switch on the the GIOP flags "more fragments"
00079       // bit.
00080       if (this->transport_->send_message (cdr,
00081                                           cdr.stub (),
00082                                           cdr.message_semantics (),
00083                                           cdr.timeout ()) == -1
00084 
00085           // Now generate a fragment header.
00086           || this->transport_->messaging_object ()->generate_fragment_header (
00087                cdr,
00088                cdr.request_id ()) != 0)
00089         return -1;
00090     }
00091 
00092   return 0;
00093 }

Generated on Thu Nov 9 11:54:17 2006 for TAO by doxygen 1.3.6