~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to ace/SOCK_IO.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// SOCK_IO.cpp
2
 
// SOCK_IO.cpp,v 4.25 2003/11/01 11:15:17 dhinton Exp
3
 
 
4
 
#include "ace/SOCK_IO.h"
5
 
 
6
 
#if defined (ACE_LACKS_INLINE_FUNCTIONS)
7
 
#include "ace/SOCK_IO.i"
8
 
#endif /* ACE_LACKS_INLINE_FUNCTIONS */
9
 
 
10
 
#include "ace/Handle_Set.h"
11
 
#include "ace/OS_NS_sys_select.h"
12
 
 
13
 
ACE_RCSID(ace, SOCK_IO, "SOCK_IO.cpp,v 4.25 2003/11/01 11:15:17 dhinton Exp")
14
 
 
15
 
ACE_ALLOC_HOOK_DEFINE(ACE_SOCK_IO)
16
 
 
17
 
void
18
 
ACE_SOCK_IO::dump (void) const
19
 
{
20
 
#if defined (ACE_HAS_DUMP)
21
 
  ACE_TRACE ("ACE_SOCK_IO::dump");
22
 
#endif /* ACE_HAS_DUMP */
23
 
}
24
 
 
25
 
// Allows a client to read from a socket without having to provide
26
 
// a buffer to read.  This method determines how much data is in the
27
 
// socket, allocates a buffer of this size, reads in the data, and
28
 
// returns the number of bytes read.
29
 
 
30
 
ssize_t
31
 
ACE_SOCK_IO::recvv (iovec *io_vec,
32
 
                    const ACE_Time_Value *timeout) const
33
 
{
34
 
  ACE_TRACE ("ACE_SOCK_IO::recvv");
35
 
#if defined (FIONREAD)
36
 
  ACE_Handle_Set handle_set;
37
 
  handle_set.reset ();
38
 
  handle_set.set_bit (this->get_handle ());
39
 
 
40
 
  io_vec->iov_base = 0;
41
 
 
42
 
  // Check the status of the current socket.
43
 
  int select_width;
44
 
#  if defined (ACE_WIN64)
45
 
  // This arg is ignored on Windows and causes pointer truncation
46
 
  // warnings on 64-bit compiles.
47
 
  select_width = 0;
48
 
#  else
49
 
  select_width = int (this->get_handle ()) + 1;
50
 
#  endif /* ACE_WIN64 */
51
 
  switch (ACE_OS::select (select_width,
52
 
                          handle_set,
53
 
                          0, 0,
54
 
                          timeout))
55
 
    {
56
 
    case -1:
57
 
      return -1;
58
 
      /* NOTREACHED */
59
 
    case 0:
60
 
      errno = ETIME;
61
 
      return -1;
62
 
      /* NOTREACHED */
63
 
    default:
64
 
      // Goes fine, fallthrough to get data
65
 
      break;
66
 
    }
67
 
 
68
 
  u_long inlen;
69
 
 
70
 
  if (ACE_OS::ioctl (this->get_handle (),
71
 
                     FIONREAD,
72
 
                     (u_long *) &inlen) == -1)
73
 
    return -1;
74
 
  else if (inlen > 0)
75
 
    {
76
 
      ACE_NEW_RETURN (io_vec->iov_base,
77
 
                      char[inlen],
78
 
                      -1);
79
 
      io_vec->iov_len = this->recv (io_vec->iov_base,
80
 
                                    inlen);
81
 
      return io_vec->iov_len;
82
 
    }
83
 
  else
84
 
    return 0;
85
 
#else
86
 
  ACE_UNUSED_ARG (io_vec);
87
 
  ACE_UNUSED_ARG (timeout);
88
 
  ACE_NOTSUP_RETURN (-1);
89
 
#endif /* FIONREAD */
90
 
}
91
 
 
92
 
// Send N char *ptrs and int lengths.  Note that the char *'s precede
93
 
// the ints (basically, an varargs version of writev).  The count N is
94
 
// the *total* number of trailing arguments, *not* a couple of the
95
 
// number of tuple pairs!
96
 
 
97
 
ssize_t
98
 
ACE_SOCK_IO::send (size_t n, ...) const
99
 
{
100
 
  ACE_TRACE ("ACE_SOCK_IO::send");
101
 
 
102
 
  va_list argp;
103
 
  int total_tuples = ACE_static_cast (int, n) / 2;
104
 
  iovec *iovp;
105
 
#if defined (ACE_HAS_ALLOCA)
106
 
  iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
107
 
#else
108
 
  ACE_NEW_RETURN (iovp,
109
 
                  iovec[total_tuples],
110
 
                  -1);
111
 
#endif /* !defined (ACE_HAS_ALLOCA) */
112
 
 
113
 
  va_start (argp, n);
114
 
 
115
 
  for (int i = 0; i < total_tuples; i++)
116
 
    {
117
 
      iovp[i].iov_base = va_arg (argp, char *);
118
 
      iovp[i].iov_len = va_arg (argp, int);
119
 
    }
120
 
 
121
 
  ssize_t result = ACE_OS::sendv (this->get_handle (),
122
 
                                  iovp,
123
 
                                  total_tuples);
124
 
#if !defined (ACE_HAS_ALLOCA)
125
 
  delete [] iovp;
126
 
#endif /* !defined (ACE_HAS_ALLOCA) */
127
 
  va_end (argp);
128
 
  return result;
129
 
}
130
 
 
131
 
// This is basically an interface to ACE_OS::readv, that doesn't use
132
 
// the struct iovec_Base explicitly.  The ... can be passed as an arbitrary
133
 
// number of (char *ptr, int len) tuples.  However, the count N is the
134
 
// *total* number of trailing arguments, *not* a couple of the number
135
 
// of tuple pairs!
136
 
 
137
 
ssize_t
138
 
ACE_SOCK_IO::recv (size_t n, ...) const
139
 
{
140
 
  ACE_TRACE ("ACE_SOCK_IO::recv");
141
 
 
142
 
  va_list argp;
143
 
  int total_tuples = ACE_static_cast (int, (n / 2));
144
 
  iovec *iovp;
145
 
#if defined (ACE_HAS_ALLOCA)
146
 
  iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
147
 
#else
148
 
  ACE_NEW_RETURN (iovp,
149
 
                  iovec[total_tuples],
150
 
                  -1);
151
 
#endif /* !defined (ACE_HAS_ALLOCA) */
152
 
 
153
 
  va_start (argp, n);
154
 
 
155
 
  for (int i = 0; i < total_tuples; i++)
156
 
    {
157
 
      iovp[i].iov_base = va_arg (argp, char *);
158
 
      iovp[i].iov_len = va_arg (argp, int);
159
 
    }
160
 
 
161
 
  ssize_t result = ACE_OS::recvv (this->get_handle (),
162
 
                                  iovp,
163
 
                                  total_tuples);
164
 
#if !defined (ACE_HAS_ALLOCA)
165
 
  delete [] iovp;
166
 
#endif /* !defined (ACE_HAS_ALLOCA) */
167
 
  va_end (argp);
168
 
  return result;
169
 
}