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__ */
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 ACE_ALLOC_HOOK_DEFINE(ACE_DEV_IO
)
18 // Return the local endpoint address.
21 ACE_DEV_IO::get_local_addr (ACE_DEV_Addr
&addr
) const
23 ACE_TRACE ("ACE_DEV_IO::get_local_addr");
29 // Return the address of the remotely connected peer (if there is
33 ACE_DEV_IO::get_remote_addr (ACE_DEV_Addr
&addr
) const
35 ACE_TRACE ("ACE_DEV_IO::get_remote_addr");
41 ACE_DEV_IO::dump (void) const
43 #if defined (ACE_HAS_DUMP)
44 ACE_TRACE ("ACE_DEV_IO::dump");
46 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
48 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
49 #endif /* ACE_HAS_DUMP */
52 // Simple-minded do nothing constructor.
54 ACE_DEV_IO::ACE_DEV_IO (void)
56 ACE_TRACE ("ACE_DEV_IO::ACE_DEV_IO");
59 // Send N char *ptrs and int lengths. Note that the char *'s precede
60 // the ints (basically, an varargs version of writev). The count N is
61 // the *total* number of trailing arguments, *not* a couple of the
62 // number of tuple pairs!
65 ACE_DEV_IO::send (size_t n
, ...) const
67 ACE_TRACE ("ACE_DEV_IO::send");
68 #ifdef ACE_LACKS_VA_FUNCTIONS
70 ACE_NOTSUP_RETURN (-1);
73 int total_tuples
= static_cast<int> (n
/ 2);
75 #if defined (ACE_HAS_ALLOCA)
76 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
78 # ifdef ACE_HAS_ALLOC_HOOKS
79 ACE_ALLOCATOR_RETURN (iovp
, (iovec
*)
80 ACE_Allocator::instance ()->malloc (total_tuples
*
87 # endif /* ACE_HAS_ALLOC_HOOKS */
88 #endif /* !defined (ACE_HAS_ALLOCA) */
92 for (int i
= 0; i
< total_tuples
; i
++)
94 iovp
[i
].iov_base
= va_arg (argp
, char *);
95 iovp
[i
].iov_len
= va_arg (argp
, int);
98 ssize_t result
= ACE_OS::writev (this->get_handle (), iovp
, total_tuples
);
99 #if !defined (ACE_HAS_ALLOCA)
100 # ifdef ACE_HAS_ALLOC_HOOKS
101 ACE_Allocator::instance ()->free (iovp
);
104 # endif /* ACE_HAS_ALLOC_HOOKS */
105 #endif /* !defined (ACE_HAS_ALLOCA) */
108 #endif // ACE_LACKS_VA_FUNCTIONS
111 // This is basically an interface to ACE_OS::readv, that doesn't use the
112 // struct iovec explicitly. The ... can be passed as an arbitrary
113 // number of (char *ptr, int len) tuples. However, the count N is the
114 // *total* number of trailing arguments, *not* a couple of the number
118 ACE_DEV_IO::recv (size_t n
, ...) const
120 ACE_TRACE ("ACE_DEV_IO::recv");
121 #ifdef ACE_LACKS_VA_FUNCTIONS
123 ACE_NOTSUP_RETURN (-1);
126 int total_tuples
= static_cast<int> (n
/ 2);
128 #if defined (ACE_HAS_ALLOCA)
129 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
131 # ifdef ACE_HAS_ALLOC_HOOKS
132 ACE_ALLOCATOR_RETURN (iovp
, (iovec
*)
133 ACE_Allocator::instance ()->malloc (total_tuples
*
137 ACE_NEW_RETURN (iovp
,
140 # endif /* ACE_HAS_ALLOC_HOOKS */
141 #endif /* !defined (ACE_HAS_ALLOCA) */
145 for (int i
= 0; i
< total_tuples
; i
++)
147 iovp
[i
].iov_base
= va_arg (argp
, char *);
148 iovp
[i
].iov_len
= va_arg (argp
, int);
151 ssize_t result
= ACE_OS::readv (this->get_handle (), iovp
, total_tuples
);
152 #if !defined (ACE_HAS_ALLOCA)
153 # ifdef ACE_HAS_ALLOC_HOOKS
154 ACE_Allocator::instance ()->free (iovp
);
157 # endif /* ACE_HAS_ALLOC_HOOKS */
158 #endif /* !defined (ACE_HAS_ALLOCA) */
161 #endif // ACE_LACKS_VA_FUNCTIONS
164 ACE_END_VERSIONED_NAMESPACE_DECL