summaryrefslogtreecommitdiff
path: root/TAO/tao/GIOP_Utils.cpp
blob: 8b130d3ec10e37a99ca14a2e08403183e38502d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//$Id$
#include "tao/debug.h"
#include "tao/GIOP_Utils.h"
#include "tao/ORB_Core.h"


#if !defined (__ACE_INLINE__)
# include "tao/GIOP_Utils.i"
#endif /* __ACE_INLINE__ */

// @@ Bala: what happened to the RCSID macro?

int
TAO_GIOP_Utils::
  read_bytes_input (TAO_Transport *transport,
                    TAO_InputCDR &input,
                    CORBA::ULong read_size,
                    ACE_Time_Value *value)
{
  // Grow the size of CDR stream
  if (input.grow (read_size) == -1)
    return -1;

  // Read until all the header is received.  There should be no
  // problems with locking, the header is only a few bytes so they
  // should all be available on the socket, otherwise there is a
  // problem with the underlying transport, in which case we have more
  // problems than just this small loop.
  char *buf = input.rd_ptr ();
  ssize_t n = 0;

  for (int t = read_size;
       t != 0;
       t -= n)
    {
      n = transport->recv (buf, t, value);
      if (n == -1)
        return -1;
      else if (n == 0) // @@ TODO && errno != EWOULDBLOCK)
        return -1;
      buf += n;
    }

  return 1;
}


ssize_t
TAO_GIOP_Utils::read_buffer (TAO_Transport *transport,
                             char *buf,
                             size_t len,
                             ACE_Time_Value *max_wait_time)
{
  ssize_t bytes_read = transport->recv (buf, len, max_wait_time);

  if (bytes_read <= 0 && TAO_debug_level > 0)
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("TAO (%P|%t|%N|%l) - %p,\n")
                ACE_TEXT ("              transport = %d, ")
                ACE_TEXT ("bytes = %d, len = %d\n"),
                ACE_TEXT ("read_buffer"),
                transport->handle (),
                bytes_read,
                len));

  if (bytes_read == -1 && errno == ECONNRESET)
    {
      // @@ Is this OK??

      // We got a connection reset (TCP RSET) from the other side,
      // i.e., they didn't initiate a proper shutdown.
      //
      // Make it look like things are OK to the upper layer.
      bytes_read = 0;
      errno = 0;
    }

  return bytes_read;
}


TAO_Pluggable_Message_Exception_Type
TAO_GIOP_Utils::
  convert_CORBA_to_GIOP_exception (CORBA::exception_type corba_type)
{

  switch (corba_type)
    {
    case CORBA::NO_EXCEPTION:
      return TAO_PLUGGABLE_MESSAGE_NO_EXCEPTION;

    case CORBA::SYSTEM_EXCEPTION:
      return TAO_PLUGGABLE_MESSAGE_SYSTEM_EXCEPTION;

    case CORBA::USER_EXCEPTION:
      return TAO_PLUGGABLE_MESSAGE_USER_EXCEPTION;

    default:
      // Don't know what to do here??
      return TAO_PLUGGABLE_MESSAGE_SYSTEM_EXCEPTION;
    }
}