summaryrefslogtreecommitdiff
path: root/TAO/tao/GIOP_Utils.cpp
blob: 464eaa8430ea6a4a25dcde69787da71c5548fae4 (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
// $Id$

#include "tao/GIOP_Utils.h"
#include "tao/debug.h"
#include "tao/Transport.h"
#include "tao/CDR.h"

ACE_RCSID (tao,
           GIOP_Utils,
           "$Id$")

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->id (),
                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;
}