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 */
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 ACE_ALLOC_HOOK_DEFINE(ACE_SPIPE_Stream
)
17 ACE_SPIPE_Stream::dump () const
19 #if defined (ACE_HAS_DUMP)
20 ACE_TRACE ("ACE_SPIPE_Stream::dump");
21 #endif /* ACE_HAS_DUMP */
24 // Simple-minded do nothing constructor.
26 ACE_SPIPE_Stream::ACE_SPIPE_Stream ()
28 // ACE_TRACE ("ACE_SPIPE_Stream::ACE_SPIPE_Stream");
31 // Send N char *ptrs and int lengths. Note that the char *'s precede
32 // the ints (basically, an varargs version of writev). The count N is
33 // the *total* number of trailing arguments, *not* a couple of the
34 // number of tuple pairs!
36 #ifndef ACE_LACKS_VA_FUNCTIONS
38 ACE_SPIPE_Stream::send (size_t n
, ...) const
40 // ACE_TRACE ("ACE_SPIPE_Stream::send");
42 int total_tuples
= static_cast<int> (n
/ 2);
44 #if defined (ACE_HAS_ALLOCA)
45 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
47 # ifdef ACE_HAS_ALLOC_HOOKS
48 ACE_ALLOCATOR_RETURN (iovp
, (iovec
*)
49 ACE_Allocator::instance ()->malloc (total_tuples
*
56 # endif /* ACE_HAS_ALLOC_HOOKS */
57 #endif /* !defined (ACE_HAS_ALLOCA) */
61 for (int i
= 0; i
< total_tuples
; i
++)
63 iovp
[i
].iov_base
= va_arg (argp
, char *);
64 iovp
[i
].iov_len
= va_arg (argp
, int);
67 ssize_t result
= ACE_OS::writev (this->get_handle (), iovp
, total_tuples
);
68 #if !defined (ACE_HAS_ALLOCA)
69 # ifdef ACE_HAS_ALLOC_HOOKS
70 ACE_Allocator::instance ()->free (iovp
);
73 # endif /* ACE_HAS_ALLOC_HOOKS */
74 #endif /* !defined (ACE_HAS_ALLOCA) */
79 // This is basically an interface to ACE_OS::readv, that doesn't use
80 // the struct iovec explicitly. The ... can be passed as an arbitrary
81 // number of (char *ptr, int len) tuples. However, the count N is the
82 // *total* number of trailing arguments, *not* a couple of the number
86 ACE_SPIPE_Stream::recv (size_t n
, ...) const
88 ACE_TRACE ("ACE_SPIPE_Stream::recv");
90 int total_tuples
= static_cast<int> (n
/ 2);
92 #if defined (ACE_HAS_ALLOCA)
93 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
95 # ifdef ACE_HAS_ALLOC_HOOKS
96 ACE_ALLOCATOR_RETURN (iovp
, (iovec
*)
97 ACE_Allocator::instance ()->malloc (total_tuples
*
101 ACE_NEW_RETURN (iovp
,
104 # endif /* ACE_HAS_ALLOC_HOOKS */
105 #endif /* !defined (ACE_HAS_ALLOCA) */
109 for (int i
= 0; i
< total_tuples
; i
++)
111 iovp
[i
].iov_base
= va_arg (argp
, char *);
112 iovp
[i
].iov_len
= va_arg (argp
, int);
115 ssize_t result
= ACE_OS::readv (this->get_handle (), iovp
, total_tuples
);
116 #if !defined (ACE_HAS_ALLOCA)
117 # ifdef ACE_HAS_ALLOC_HOOKS
118 ACE_Allocator::instance ()->free (iovp
);
121 # endif /* ACE_HAS_ALLOC_HOOKS */
122 #endif /* !defined (ACE_HAS_ALLOCA) */
126 #endif // ACE_LACKS_VA_FUNCTIONS
128 ACE_END_VERSIONED_NAMESPACE_DECL