Fixed typos
[ACE_TAO.git] / ACE / ace / SPIPE_Stream.cpp
blobc9374c19b42bc54e6e0a279f1e8aaa6fe4e6ca30
1 #include "ace/SPIPE_Stream.h"
2 #include "ace/OS_Memory.h"
4 #if !defined (__ACE_INLINE__)
5 #include "ace/SPIPE_Stream.inl"
6 #endif /* __ACE_INLINE__ */
8 #if defined (ACE_HAS_ALLOC_HOOKS)
9 # include "ace/Malloc_Base.h"
10 #endif /* ACE_HAS_ALLOC_HOOKS */
13 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
15 ACE_ALLOC_HOOK_DEFINE(ACE_SPIPE_Stream)
17 void
18 ACE_SPIPE_Stream::dump (void) const
20 #if defined (ACE_HAS_DUMP)
21 ACE_TRACE ("ACE_SPIPE_Stream::dump");
22 #endif /* ACE_HAS_DUMP */
25 // Simple-minded do nothing constructor.
27 ACE_SPIPE_Stream::ACE_SPIPE_Stream (void)
29 // ACE_TRACE ("ACE_SPIPE_Stream::ACE_SPIPE_Stream");
32 // Send N char *ptrs and int lengths. Note that the char *'s precede
33 // the ints (basically, an varargs version of writev). The count N is
34 // the *total* number of trailing arguments, *not* a couple of the
35 // number of tuple pairs!
37 #ifndef ACE_LACKS_VA_FUNCTIONS
38 ssize_t
39 ACE_SPIPE_Stream::send (size_t n, ...) const
41 // ACE_TRACE ("ACE_SPIPE_Stream::send");
42 va_list argp;
43 int total_tuples = static_cast<int> (n / 2);
44 iovec *iovp;
45 #if defined (ACE_HAS_ALLOCA)
46 iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
47 #else
48 # ifdef ACE_HAS_ALLOC_HOOKS
49 ACE_ALLOCATOR_RETURN (iovp, (iovec *)
50 ACE_Allocator::instance ()->malloc (total_tuples *
51 sizeof (iovec)),
52 -1);
53 # else
54 ACE_NEW_RETURN (iovp,
55 iovec[total_tuples],
56 -1);
57 # endif /* ACE_HAS_ALLOC_HOOKS */
58 #endif /* !defined (ACE_HAS_ALLOCA) */
60 va_start (argp, n);
62 for (int i = 0; i < total_tuples; i++)
64 iovp[i].iov_base = va_arg (argp, char *);
65 iovp[i].iov_len = va_arg (argp, int);
68 ssize_t result = ACE_OS::writev (this->get_handle (), iovp, total_tuples);
69 #if !defined (ACE_HAS_ALLOCA)
70 # ifdef ACE_HAS_ALLOC_HOOKS
71 ACE_Allocator::instance ()->free (iovp);
72 # else
73 delete [] iovp;
74 # endif /* ACE_HAS_ALLOC_HOOKS */
75 #endif /* !defined (ACE_HAS_ALLOCA) */
76 va_end (argp);
77 return result;
80 // This is basically an interface to ACE_OS::readv, that doesn't use
81 // the struct iovec explicitly. The ... can be passed as an arbitrary
82 // number of (char *ptr, int len) tuples. However, the count N is the
83 // *total* number of trailing arguments, *not* a couple of the number
84 // of tuple pairs!
86 ssize_t
87 ACE_SPIPE_Stream::recv (size_t n, ...) const
89 ACE_TRACE ("ACE_SPIPE_Stream::recv");
90 va_list argp;
91 int total_tuples = static_cast<int> (n / 2);
92 iovec *iovp;
93 #if defined (ACE_HAS_ALLOCA)
94 iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
95 #else
96 # ifdef ACE_HAS_ALLOC_HOOKS
97 ACE_ALLOCATOR_RETURN (iovp, (iovec *)
98 ACE_Allocator::instance ()->malloc (total_tuples *
99 sizeof (iovec)),
100 -1);
101 # else
102 ACE_NEW_RETURN (iovp,
103 iovec[total_tuples],
104 -1);
105 # endif /* ACE_HAS_ALLOC_HOOKS */
106 #endif /* !defined (ACE_HAS_ALLOCA) */
108 va_start (argp, n);
110 for (int i = 0; i < total_tuples; i++)
112 iovp[i].iov_base = va_arg (argp, char *);
113 iovp[i].iov_len = va_arg (argp, int);
116 ssize_t result = ACE_OS::readv (this->get_handle (), iovp, total_tuples);
117 #if !defined (ACE_HAS_ALLOCA)
118 # ifdef ACE_HAS_ALLOC_HOOKS
119 ACE_Allocator::instance ()->free (iovp);
120 # else
121 delete [] iovp;
122 # endif /* ACE_HAS_ALLOC_HOOKS */
123 #endif /* !defined (ACE_HAS_ALLOCA) */
124 va_end (argp);
125 return result;
127 #endif // ACE_LACKS_VA_FUNCTIONS
129 ACE_END_VERSIONED_NAMESPACE_DECL