Fixed typos
[ACE_TAO.git] / ACE / ace / DEV_IO.cpp
blobf1dcda42978597d35c87de847c3cb13a9c4864eb
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.
20 int
21 ACE_DEV_IO::get_local_addr (ACE_DEV_Addr &addr) const
23 ACE_TRACE ("ACE_DEV_IO::get_local_addr");
25 addr = this->addr_;
26 return 0;
29 // Return the address of the remotely connected peer (if there is
30 // one).
32 int
33 ACE_DEV_IO::get_remote_addr (ACE_DEV_Addr &addr) const
35 ACE_TRACE ("ACE_DEV_IO::get_remote_addr");
36 addr = this->addr_;
37 return 0;
40 void
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));
47 this->addr_.dump ();
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!
64 ssize_t
65 ACE_DEV_IO::send (size_t n, ...) const
67 ACE_TRACE ("ACE_DEV_IO::send");
68 #ifdef ACE_LACKS_VA_FUNCTIONS
69 ACE_UNUSED_ARG (n);
70 ACE_NOTSUP_RETURN (-1);
71 #else
72 va_list argp;
73 int total_tuples = static_cast<int> (n / 2);
74 iovec *iovp;
75 #if defined (ACE_HAS_ALLOCA)
76 iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
77 #else
78 # ifdef ACE_HAS_ALLOC_HOOKS
79 ACE_ALLOCATOR_RETURN (iovp, (iovec *)
80 ACE_Allocator::instance ()->malloc (total_tuples *
81 sizeof (iovec)),
82 -1);
83 # else
84 ACE_NEW_RETURN (iovp,
85 iovec[total_tuples],
86 -1);
87 # endif /* ACE_HAS_ALLOC_HOOKS */
88 #endif /* !defined (ACE_HAS_ALLOCA) */
90 va_start (argp, n);
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);
102 # else
103 delete [] iovp;
104 # endif /* ACE_HAS_ALLOC_HOOKS */
105 #endif /* !defined (ACE_HAS_ALLOCA) */
106 va_end (argp);
107 return result;
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
115 // of tuple pairs!
117 ssize_t
118 ACE_DEV_IO::recv (size_t n, ...) const
120 ACE_TRACE ("ACE_DEV_IO::recv");
121 #ifdef ACE_LACKS_VA_FUNCTIONS
122 ACE_UNUSED_ARG (n);
123 ACE_NOTSUP_RETURN (-1);
124 #else
125 va_list argp;
126 int total_tuples = static_cast<int> (n / 2);
127 iovec *iovp;
128 #if defined (ACE_HAS_ALLOCA)
129 iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
130 #else
131 # ifdef ACE_HAS_ALLOC_HOOKS
132 ACE_ALLOCATOR_RETURN (iovp, (iovec *)
133 ACE_Allocator::instance ()->malloc (total_tuples *
134 sizeof (iovec)),
135 -1);
136 # else
137 ACE_NEW_RETURN (iovp,
138 iovec[total_tuples],
139 -1);
140 # endif /* ACE_HAS_ALLOC_HOOKS */
141 #endif /* !defined (ACE_HAS_ALLOCA) */
143 va_start (argp, n);
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);
155 # else
156 delete [] iovp;
157 # endif /* ACE_HAS_ALLOC_HOOKS */
158 #endif /* !defined (ACE_HAS_ALLOCA) */
159 va_end (argp);
160 return result;
161 #endif // ACE_LACKS_VA_FUNCTIONS
164 ACE_END_VERSIONED_NAMESPACE_DECL