UIOP_Transport.cpp

Go to the documentation of this file.
00001 // UIOP_Transport.cpp,v 1.37 2006/04/20 12:37:17 jwillemsen Exp
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 #include "tao/GIOP_Message_Lite.h"
00018 
00019 ACE_RCSID (Strategies,
00020            UIOP_Transport,
00021            "UIOP_Transport.cpp,v 1.37 2006/04/20 12:37:17 jwillemsen Exp")
00022 
00023 
00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00025 
00026 TAO_UIOP_Transport::TAO_UIOP_Transport (TAO_UIOP_Connection_Handler *handler,
00027                                         TAO_ORB_Core *orb_core,
00028                                         CORBA::Boolean flag)
00029   : TAO_Transport (TAO_TAG_UIOP_PROFILE,
00030                    orb_core)
00031   , connection_handler_ (handler)
00032   , messaging_object_ (0)
00033 {
00034 
00035 /*
00036  * Hook to customize the messaging object when the concrete messaging
00037  * object is known a priori. In this case, the flag is ignored.
00038  */
00039 //@@ MESSAGING_SPL_COMMENT_HOOK_START
00040   if (flag)
00041     {
00042       // Use the lite version of the protocol
00043       ACE_NEW (this->messaging_object_,
00044                TAO_GIOP_Message_Lite (orb_core));
00045     }
00046   else
00047     {
00048       // Use the normal GIOP object
00049       ACE_NEW (this->messaging_object_,
00050                TAO_GIOP_Message_Base (orb_core, this));
00051     }
00052 //@@ MESSAGING_SPL_COMMENT_HOOK_END
00053 }
00054 
00055 TAO_UIOP_Transport::~TAO_UIOP_Transport (void)
00056 {
00057   delete this->messaging_object_;
00058 }
00059 
00060 ACE_Event_Handler *
00061 TAO_UIOP_Transport::event_handler_i (void)
00062 {
00063   return this->connection_handler_;
00064 }
00065 
00066 TAO_Connection_Handler *
00067 TAO_UIOP_Transport::connection_handler_i (void)
00068 {
00069   return this->connection_handler_;
00070 }
00071 
00072 TAO_Pluggable_Messaging *
00073 TAO_UIOP_Transport::messaging_object (void)
00074 {
00075   return this->messaging_object_;
00076 }
00077 
00078 ssize_t
00079 TAO_UIOP_Transport::send (iovec *iov, int iovcnt,
00080                           size_t &bytes_transferred,
00081                           const ACE_Time_Value *max_wait_time)
00082 {
00083   const ssize_t retval =
00084     this->connection_handler_->peer ().sendv (iov,
00085                                               iovcnt,
00086                                               max_wait_time);
00087 
00088   if (retval > 0)
00089     bytes_transferred = retval;
00090 
00091   return retval;
00092 }
00093 
00094 ssize_t
00095 TAO_UIOP_Transport::recv (char *buf,
00096                           size_t len,
00097                           const ACE_Time_Value *max_wait_time)
00098 {
00099   const ssize_t n = this->connection_handler_->peer ().recv (buf,
00100                                                              len,
00101                                                              max_wait_time);
00102 
00103   // Most of the errors handling is common for
00104   // Now the message has been read
00105   if (n == -1 &&
00106       TAO_debug_level > 4 &&
00107       errno != ETIME)
00108     {
00109       ACE_DEBUG ((LM_DEBUG,
00110                   ACE_TEXT ("TAO (%P|%t) - %p \n"),
00111                   ACE_TEXT ("TAO - read message failure ")
00112                   ACE_TEXT ("recv () \n")));
00113     }
00114 
00115   // Error handling
00116   if (n == -1)
00117     {
00118       if (errno == EWOULDBLOCK)
00119         return 0;
00120 
00121       return -1;
00122     }
00123   // @@ What are the other error handling here??
00124   else if (n == 0)
00125     {
00126       return -1;
00127     }
00128 
00129   return n;
00130 }
00131 
00132 int
00133 TAO_UIOP_Transport::send_request (TAO_Stub *stub,
00134                                   TAO_ORB_Core *orb_core,
00135                                   TAO_OutputCDR &stream,
00136                                   int message_semantics,
00137                                   ACE_Time_Value *max_wait_time)
00138 {
00139   if (this->ws_->sending_request (orb_core,
00140                                   message_semantics) == -1)
00141     return -1;
00142 
00143   if (this->send_message (stream,
00144                           stub,
00145                           message_semantics,
00146                           max_wait_time) == -1)
00147 
00148     return -1;
00149 
00150   this->first_request_sent();
00151 
00152   return 0;
00153 }
00154 
00155 int
00156 TAO_UIOP_Transport::send_message (TAO_OutputCDR &stream,
00157                                   TAO_Stub *stub,
00158                                   int message_semantics,
00159                                   ACE_Time_Value *max_wait_time)
00160 {
00161   // Format the message in the stream first
00162   if (this->messaging_object_->format_message (stream) != 0)
00163     return -1;
00164 
00165   // Strictly speaking, should not need to loop here because the
00166   // socket never gets set to a nonblocking mode ... some Linux
00167   // versions seem to need it though.  Leaving it costs little.
00168 
00169   // This guarantees to send all data (bytes) or return an error.
00170   const ssize_t n = this->send_message_shared (stub,
00171                                                message_semantics,
00172                                                stream.begin (),
00173                                                max_wait_time);
00174 
00175   if (n == -1)
00176     {
00177       if (TAO_debug_level)
00178         ACE_DEBUG ((LM_DEBUG,
00179                     ACE_TEXT ("TAO: (%P|%t|%N|%l) closing transport %d after fault %p\n"),
00180                     this->id (),
00181                     ACE_TEXT ("send_message ()\n")));
00182 
00183       return -1;
00184     }
00185 
00186   return 1;
00187 }
00188 
00189 int
00190 TAO_UIOP_Transport::messaging_init (CORBA::Octet major,
00191                                     CORBA::Octet minor)
00192 {
00193   this->messaging_object_->init (major,
00194                                  minor);
00195   return 1;
00196 }
00197 
00198 TAO_END_VERSIONED_NAMESPACE_DECL
00199 
00200 #endif  /* TAO_HAS_UIOP */

Generated on Thu Nov 9 13:39:31 2006 for TAO_Strategies by doxygen 1.3.6