UIOP_Transport.cpp

Go to the documentation of this file.
00001 // $Id: UIOP_Transport.cpp 80288 2007-12-17 20:05:04Z johnnyw $
00002 
00003 #include "tao/Strategies/UIOP_Transport.h"
00004 
00005 #if TAO_HAS_UIOP == 1
00006 
00007 #include "tao/Strategies/UIOP_Connection_Handler.h"
00008 #include "tao/Strategies/UIOP_Profile.h"
00009 #include "tao/Timeprobe.h"
00010 #include "tao/CDR.h"
00011 #include "tao/Transport_Mux_Strategy.h"
00012 #include "tao/Wait_Strategy.h"
00013 #include "tao/Stub.h"
00014 #include "tao/ORB_Core.h"
00015 #include "tao/debug.h"
00016 #include "tao/GIOP_Message_Base.h"
00017 
00018 ACE_RCSID (Strategies,
00019            UIOP_Transport,
00020            "$Id: UIOP_Transport.cpp 80288 2007-12-17 20:05:04Z johnnyw $")
00021 
00022 
00023 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00024 
00025 TAO_UIOP_Transport::TAO_UIOP_Transport (TAO_UIOP_Connection_Handler *handler,
00026                                         TAO_ORB_Core *orb_core)
00027   : TAO_Transport (TAO_TAG_UIOP_PROFILE,
00028                    orb_core)
00029   , connection_handler_ (handler)
00030 {
00031 }
00032 
00033 TAO_UIOP_Transport::~TAO_UIOP_Transport (void)
00034 {
00035 }
00036 
00037 ACE_Event_Handler *
00038 TAO_UIOP_Transport::event_handler_i (void)
00039 {
00040   return this->connection_handler_;
00041 }
00042 
00043 TAO_Connection_Handler *
00044 TAO_UIOP_Transport::connection_handler_i (void)
00045 {
00046   return this->connection_handler_;
00047 }
00048 
00049 ssize_t
00050 TAO_UIOP_Transport::send (iovec *iov, int iovcnt,
00051                           size_t &bytes_transferred,
00052                           const ACE_Time_Value *max_wait_time)
00053 {
00054   ssize_t const retval =
00055     this->connection_handler_->peer ().sendv (iov, iovcnt, max_wait_time);
00056 
00057   if (retval > 0)
00058     bytes_transferred = retval;
00059 
00060   return retval;
00061 }
00062 
00063 ssize_t
00064 TAO_UIOP_Transport::recv (char *buf,
00065                           size_t len,
00066                           const ACE_Time_Value *max_wait_time)
00067 {
00068   const ssize_t n = this->connection_handler_->peer ().recv (buf,
00069                                                              len,
00070                                                              max_wait_time);
00071 
00072   // Most of the errors handling is common for
00073   // Now the message has been read
00074   if (n == -1 &&
00075       TAO_debug_level > 4 &&
00076       errno != ETIME)
00077     {
00078       ACE_DEBUG ((LM_DEBUG,
00079                   ACE_TEXT ("TAO (%P|%t) - UIOP_Transport::recv, %p %p \n"),
00080                   ACE_TEXT ("TAO - read message failure ")
00081                   ACE_TEXT ("recv () \n")));
00082     }
00083 
00084   // Error handling
00085   if (n == -1)
00086     {
00087       if (errno == EWOULDBLOCK)
00088         return 0;
00089 
00090       return -1;
00091     }
00092   // @@ What are the other error handling here??
00093   else if (n == 0)
00094     {
00095       return -1;
00096     }
00097 
00098   return n;
00099 }
00100 
00101 int
00102 TAO_UIOP_Transport::send_request (TAO_Stub *stub,
00103                                   TAO_ORB_Core *orb_core,
00104                                   TAO_OutputCDR &stream,
00105                                   TAO_Message_Semantics message_semantics,
00106                                   ACE_Time_Value *max_wait_time)
00107 {
00108   if (this->ws_->sending_request (orb_core, message_semantics) == -1)
00109     return -1;
00110 
00111   if (this->send_message (stream, stub, message_semantics, max_wait_time) == -1)
00112     return -1;
00113 
00114   this->first_request_sent();
00115 
00116   return 0;
00117 }
00118 
00119 int
00120 TAO_UIOP_Transport::send_message (TAO_OutputCDR &stream,
00121                                   TAO_Stub *stub,
00122                                   TAO_Message_Semantics message_semantics,
00123                                   ACE_Time_Value *max_wait_time)
00124 {
00125   // Format the message in the stream first
00126   if (this->messaging_object_->format_message (stream) != 0)
00127     return -1;
00128 
00129   // Strictly speaking, should not need to loop here because the
00130   // socket never gets set to a nonblocking mode ... some Linux
00131   // versions seem to need it though.  Leaving it costs little.
00132 
00133   // This guarantees to send all data (bytes) or return an error.
00134   const ssize_t n = this->send_message_shared (stub,
00135                                                message_semantics,
00136                                                stream.begin (),
00137                                                max_wait_time);
00138 
00139   if (n == -1)
00140     {
00141       if (TAO_debug_level)
00142         ACE_DEBUG ((LM_DEBUG,
00143                     ACE_TEXT ("TAO (%P|%t) closing transport %d after fault %p\n"),
00144                     this->id (),
00145                     ACE_TEXT ("send_message ()\n")));
00146 
00147       return -1;
00148     }
00149 
00150   return 1;
00151 }
00152 
00153 TAO_END_VERSIONED_NAMESPACE_DECL
00154 
00155 #endif  /* TAO_HAS_UIOP */

Generated on Tue Feb 2 17:47:18 2010 for TAO_Strategies by  doxygen 1.4.7