00001
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 78931 2007-07-18 09:59:36Z 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 , messaging_object_ (0)
00031 {
00032
00033
00034
00035
00036
00037
00038
00039 ACE_NEW (this->messaging_object_,
00040 TAO_GIOP_Message_Base (orb_core, this));
00041
00042 }
00043
00044 TAO_UIOP_Transport::~TAO_UIOP_Transport (void)
00045 {
00046 delete this->messaging_object_;
00047 }
00048
00049 ACE_Event_Handler *
00050 TAO_UIOP_Transport::event_handler_i (void)
00051 {
00052 return this->connection_handler_;
00053 }
00054
00055 TAO_Connection_Handler *
00056 TAO_UIOP_Transport::connection_handler_i (void)
00057 {
00058 return this->connection_handler_;
00059 }
00060
00061 TAO_Pluggable_Messaging *
00062 TAO_UIOP_Transport::messaging_object (void)
00063 {
00064 return this->messaging_object_;
00065 }
00066
00067 ssize_t
00068 TAO_UIOP_Transport::send (iovec *iov, int iovcnt,
00069 size_t &bytes_transferred,
00070 const ACE_Time_Value *max_wait_time)
00071 {
00072 ssize_t const retval =
00073 this->connection_handler_->peer ().sendv (iov, iovcnt, max_wait_time);
00074
00075 if (retval > 0)
00076 bytes_transferred = retval;
00077
00078 return retval;
00079 }
00080
00081 ssize_t
00082 TAO_UIOP_Transport::recv (char *buf,
00083 size_t len,
00084 const ACE_Time_Value *max_wait_time)
00085 {
00086 const ssize_t n = this->connection_handler_->peer ().recv (buf,
00087 len,
00088 max_wait_time);
00089
00090
00091
00092 if (n == -1 &&
00093 TAO_debug_level > 4 &&
00094 errno != ETIME)
00095 {
00096 ACE_DEBUG ((LM_DEBUG,
00097 ACE_TEXT ("TAO (%P|%t) - %p \n"),
00098 ACE_TEXT ("TAO - read message failure ")
00099 ACE_TEXT ("recv () \n")));
00100 }
00101
00102
00103 if (n == -1)
00104 {
00105 if (errno == EWOULDBLOCK)
00106 return 0;
00107
00108 return -1;
00109 }
00110
00111 else if (n == 0)
00112 {
00113 return -1;
00114 }
00115
00116 return n;
00117 }
00118
00119 int
00120 TAO_UIOP_Transport::send_request (TAO_Stub *stub,
00121 TAO_ORB_Core *orb_core,
00122 TAO_OutputCDR &stream,
00123 int message_semantics,
00124 ACE_Time_Value *max_wait_time)
00125 {
00126 if (this->ws_->sending_request (orb_core, message_semantics) == -1)
00127 return -1;
00128
00129 if (this->send_message (stream, stub, message_semantics, max_wait_time) == -1)
00130 return -1;
00131
00132 this->first_request_sent();
00133
00134 return 0;
00135 }
00136
00137 int
00138 TAO_UIOP_Transport::send_message (TAO_OutputCDR &stream,
00139 TAO_Stub *stub,
00140 int message_semantics,
00141 ACE_Time_Value *max_wait_time)
00142 {
00143
00144 if (this->messaging_object_->format_message (stream) != 0)
00145 return -1;
00146
00147
00148
00149
00150
00151
00152 const ssize_t n = this->send_message_shared (stub,
00153 message_semantics,
00154 stream.begin (),
00155 max_wait_time);
00156
00157 if (n == -1)
00158 {
00159 if (TAO_debug_level)
00160 ACE_DEBUG ((LM_DEBUG,
00161 ACE_TEXT ("TAO: (%P|%t|%N|%l) closing transport %d after fault %p\n"),
00162 this->id (),
00163 ACE_TEXT ("send_message ()\n")));
00164
00165 return -1;
00166 }
00167
00168 return 1;
00169 }
00170
00171 int
00172 TAO_UIOP_Transport::messaging_init (CORBA::Octet major,
00173 CORBA::Octet minor)
00174 {
00175 this->messaging_object_->init (major, minor);
00176 return 1;
00177 }
00178
00179 TAO_END_VERSIONED_NAMESPACE_DECL
00180
00181 #endif