1 #include "ace/DEV_IO.h"
2 #include "ace/Log_Category.h"
3 #if defined (ACE_HAS_ALLOC_HOOKS)
4 # include "ace/Malloc_Base.h"
5 #endif /* ACE_HAS_ALLOC_HOOKS */
7 #if !defined (__ACE_INLINE__)
8 #include "ace/DEV_IO.inl"
9 #endif /* __ACE_INLINE__ */
11 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
13 ACE_ALLOC_HOOK_DEFINE(ACE_DEV_IO
)
15 // Return the local endpoint address.
18 ACE_DEV_IO::get_local_addr (ACE_DEV_Addr
&addr
) const
20 ACE_TRACE ("ACE_DEV_IO::get_local_addr");
26 // Return the address of the remotely connected peer (if there is
30 ACE_DEV_IO::get_remote_addr (ACE_DEV_Addr
&addr
) const
32 ACE_TRACE ("ACE_DEV_IO::get_remote_addr");
38 ACE_DEV_IO::dump () const
40 #if defined (ACE_HAS_DUMP)
41 ACE_TRACE ("ACE_DEV_IO::dump");
43 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
45 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
46 #endif /* ACE_HAS_DUMP */
49 // Simple-minded do nothing constructor.
51 ACE_DEV_IO::ACE_DEV_IO ()
53 ACE_TRACE ("ACE_DEV_IO::ACE_DEV_IO");
56 // Send N char *ptrs and int lengths. Note that the char *'s precede
57 // the ints (basically, an varargs version of writev). The count N is
58 // the *total* number of trailing arguments, *not* a couple of the
59 // number of tuple pairs!
62 ACE_DEV_IO::send (size_t n
, ...) const
64 ACE_TRACE ("ACE_DEV_IO::send");
65 #ifdef ACE_LACKS_VA_FUNCTIONS
67 ACE_NOTSUP_RETURN (-1);
70 int total_tuples
= static_cast<int> (n
/ 2);
72 #if defined (ACE_HAS_ALLOCA)
73 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
75 # ifdef ACE_HAS_ALLOC_HOOKS
76 ACE_ALLOCATOR_RETURN (iovp
, (iovec
*)
77 ACE_Allocator::instance ()->malloc (total_tuples
*
84 # endif /* ACE_HAS_ALLOC_HOOKS */
85 #endif /* !defined (ACE_HAS_ALLOCA) */
89 for (int i
= 0; i
< total_tuples
; i
++)
91 iovp
[i
].iov_base
= va_arg (argp
, char *);
92 iovp
[i
].iov_len
= va_arg (argp
, int);
95 ssize_t result
= ACE_OS::writev (this->get_handle (), iovp
, total_tuples
);
96 #if !defined (ACE_HAS_ALLOCA)
97 # ifdef ACE_HAS_ALLOC_HOOKS
98 ACE_Allocator::instance ()->free (iovp
);
101 # endif /* ACE_HAS_ALLOC_HOOKS */
102 #endif /* !defined (ACE_HAS_ALLOCA) */
105 #endif // ACE_LACKS_VA_FUNCTIONS
108 // This is basically an interface to ACE_OS::readv, that doesn't use the
109 // struct iovec explicitly. The ... can be passed as an arbitrary
110 // number of (char *ptr, int len) tuples. However, the count N is the
111 // *total* number of trailing arguments, *not* a couple of the number
115 ACE_DEV_IO::recv (size_t n
, ...) const
117 ACE_TRACE ("ACE_DEV_IO::recv");
118 #ifdef ACE_LACKS_VA_FUNCTIONS
120 ACE_NOTSUP_RETURN (-1);
123 int total_tuples
= static_cast<int> (n
/ 2);
125 #if defined (ACE_HAS_ALLOCA)
126 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
128 # ifdef ACE_HAS_ALLOC_HOOKS
129 ACE_ALLOCATOR_RETURN (iovp
, (iovec
*)
130 ACE_Allocator::instance ()->malloc (total_tuples
*
134 ACE_NEW_RETURN (iovp
,
137 # endif /* ACE_HAS_ALLOC_HOOKS */
138 #endif /* !defined (ACE_HAS_ALLOCA) */
142 for (int i
= 0; i
< total_tuples
; i
++)
144 iovp
[i
].iov_base
= va_arg (argp
, char *);
145 iovp
[i
].iov_len
= va_arg (argp
, int);
148 ssize_t result
= ACE_OS::readv (this->get_handle (), iovp
, total_tuples
);
149 #if !defined (ACE_HAS_ALLOCA)
150 # ifdef ACE_HAS_ALLOC_HOOKS
151 ACE_Allocator::instance ()->free (iovp
);
154 # endif /* ACE_HAS_ALLOC_HOOKS */
155 #endif /* !defined (ACE_HAS_ALLOCA) */
158 #endif // ACE_LACKS_VA_FUNCTIONS
161 ACE_END_VERSIONED_NAMESPACE_DECL