GIOP_Utils.cpp

Go to the documentation of this file.
00001 // GIOP_Utils.cpp,v 1.15 2005/11/02 07:13:03 ossama Exp
00002 
00003 #include "tao/GIOP_Utils.h"
00004 #include "tao/debug.h"
00005 #include "tao/Transport.h"
00006 #include "tao/CDR.h"
00007 
00008 ACE_RCSID (tao,
00009            GIOP_Utils,
00010            "GIOP_Utils.cpp,v 1.15 2005/11/02 07:13:03 ossama Exp")
00011 
00012 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00013 
00014 int
00015 TAO_GIOP_Utils::read_bytes_input (TAO_Transport *transport,
00016                                   TAO_InputCDR &input,
00017                                   CORBA::ULong read_size,
00018                                   ACE_Time_Value *value)
00019 {
00020   // Grow the size of CDR stream
00021   if (input.grow (read_size) == -1)
00022     return -1;
00023 
00024   // Read until all the header is received.  There should be no
00025   // problems with locking, the header is only a few bytes so they
00026   // should all be available on the socket, otherwise there is a
00027   // problem with the underlying transport, in which case we have more
00028   // problems than just this small loop.
00029   char *buf = input.rd_ptr ();
00030   ssize_t n = 0;
00031 
00032   for (CORBA::ULong t = read_size;
00033        t != 0;
00034        t -= n)
00035     {
00036       n = transport->recv (buf, t, value);
00037       if (n == -1)
00038         return -1;
00039       else if (n == 0) // @@ TODO && errno != EWOULDBLOCK)
00040         return -1;
00041       buf += n;
00042     }
00043 
00044   return 1;
00045 }
00046 
00047 
00048 ssize_t
00049 TAO_GIOP_Utils::read_buffer (TAO_Transport *transport,
00050                              char *buf,
00051                              size_t len,
00052                              ACE_Time_Value *max_wait_time)
00053 {
00054   ssize_t bytes_read = transport->recv (buf, len, max_wait_time);
00055 
00056   if (bytes_read <= 0 && TAO_debug_level > 0)
00057     ACE_DEBUG ((LM_DEBUG,
00058                 ACE_TEXT ("TAO (%P|%t|%N|%l) - %p,\n")
00059                 ACE_TEXT ("              transport = %d, ")
00060                 ACE_TEXT ("bytes = %d, len = %d\n"),
00061                 ACE_TEXT ("read_buffer"),
00062                 transport->id (),
00063                 bytes_read,
00064                 len));
00065 
00066   if (bytes_read == -1 && errno == ECONNRESET)
00067     {
00068       // @@ Is this OK??
00069 
00070       // We got a connection reset (TCP RSET) from the other side,
00071       // i.e., they didn't initiate a proper shutdown.
00072       //
00073       // Make it look like things are OK to the upper layer.
00074       bytes_read = 0;
00075       errno = 0;
00076     }
00077 
00078   return bytes_read;
00079 }
00080 
00081 TAO_END_VERSIONED_NAMESPACE_DECL

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