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
)
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
39 ACE_SPIPE_Stream::send (size_t n
, ...) const
41 // ACE_TRACE ("ACE_SPIPE_Stream::send");
43 int total_tuples
= static_cast<int> (n
/ 2);
45 #if defined (ACE_HAS_ALLOCA)
46 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
48 # ifdef ACE_HAS_ALLOC_HOOKS
49 ACE_ALLOCATOR_RETURN (iovp
, (iovec
*)
50 ACE_Allocator::instance ()->malloc (total_tuples
*
57 # endif /* ACE_HAS_ALLOC_HOOKS */
58 #endif /* !defined (ACE_HAS_ALLOCA) */
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
);
74 # endif /* ACE_HAS_ALLOC_HOOKS */
75 #endif /* !defined (ACE_HAS_ALLOCA) */
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
87 ACE_SPIPE_Stream::recv (size_t n
, ...) const
89 ACE_TRACE ("ACE_SPIPE_Stream::recv");
91 int total_tuples
= static_cast<int> (n
/ 2);
93 #if defined (ACE_HAS_ALLOCA)
94 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
96 # ifdef ACE_HAS_ALLOC_HOOKS
97 ACE_ALLOCATOR_RETURN (iovp
, (iovec
*)
98 ACE_Allocator::instance ()->malloc (total_tuples
*
102 ACE_NEW_RETURN (iovp
,
105 # endif /* ACE_HAS_ALLOC_HOOKS */
106 #endif /* !defined (ACE_HAS_ALLOCA) */
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
);
122 # endif /* ACE_HAS_ALLOC_HOOKS */
123 #endif /* !defined (ACE_HAS_ALLOCA) */
127 #endif // ACE_LACKS_VA_FUNCTIONS
129 ACE_END_VERSIONED_NAMESPACE_DECL