summaryrefslogtreecommitdiff
path: root/ace/SOCK_Dgram.cpp
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1997-03-22 19:12:24 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1997-03-22 19:12:24 +0000
commite23366181cb87e4bbbb90c9fb15cf1ef41618f93 (patch)
tree8223fe34197cbcaf6cc056367109d59b91802b68 /ace/SOCK_Dgram.cpp
parent67058e37923cba59203be9b005a84082099ac0f0 (diff)
downloadATCD-e23366181cb87e4bbbb90c9fb15cf1ef41618f93.tar.gz
es
Diffstat (limited to 'ace/SOCK_Dgram.cpp')
-rw-r--r--ace/SOCK_Dgram.cpp136
1 files changed, 114 insertions, 22 deletions
diff --git a/ace/SOCK_Dgram.cpp b/ace/SOCK_Dgram.cpp
index f8b1e07d813..d52b30d3063 100644
--- a/ace/SOCK_Dgram.cpp
+++ b/ace/SOCK_Dgram.cpp
@@ -4,6 +4,7 @@
#define ACE_BUILD_DLL
#include "ace/SOCK_Dgram.h"
+#include "ace/Synch.h"
ACE_ALLOC_HOOK_DEFINE(ACE_SOCK_Dgram)
@@ -28,18 +29,18 @@ ACE_SOCK_Dgram::recv (iovec *io_vec, ACE_Addr &addr, int flags) const
u_long inlen;
if (ACE_OS::ioctl (this->get_handle (),
- FIONREAD, (u_long *) &inlen) == -1)
+ FIONREAD, (u_long *) &inlen) == -1)
return -1;
else if (inlen > 0)
{
ACE_NEW_RETURN (io_vec->iov_base, char[inlen], -1);
io_vec->iov_len = ACE_OS::recvfrom (this->get_handle (),
- (char *) io_vec->iov_base,
- inlen,
- flags,
- (sockaddr *) saddr,
- &addr_len);
+ (char *) io_vec->iov_base,
+ inlen,
+ flags,
+ (sockaddr *) saddr,
+ &addr_len);
addr.set_size (addr_len);
return io_vec->iov_len;
}
@@ -67,10 +68,10 @@ ACE_SOCK_Dgram::shared_open (const ACE_Addr &local, int protocol_family)
if (&local == &ACE_Addr::sap_any && protocol_family == PF_INET)
{
if (ACE::bind_port (this->get_handle ()) == -1)
- error = 1;
+ error = 1;
}
else if (ACE_OS::bind (this->get_handle (), (sockaddr *) local.get_addr (),
- local.get_size ()) == -1)
+ local.get_size ()) == -1)
error = 1;
if (error)
@@ -83,9 +84,9 @@ ACE_SOCK_Dgram::shared_open (const ACE_Addr &local, int protocol_family)
// datagram ``server''...
ACE_SOCK_Dgram::ACE_SOCK_Dgram (const ACE_Addr &local,
- int protocol_family,
- int protocol,
- int reuse_addr)
+ int protocol_family,
+ int protocol,
+ int reuse_addr)
: ACE_SOCK (SOCK_DGRAM, protocol_family, protocol, reuse_addr)
{
ACE_TRACE ("ACE_SOCK_Dgram::ACE_SOCK_Dgram");
@@ -97,13 +98,13 @@ ACE_SOCK_Dgram::ACE_SOCK_Dgram (const ACE_Addr &local,
int
ACE_SOCK_Dgram::open (const ACE_Addr &local,
- int protocol_family,
- int protocol,
- int reuse_addr)
+ int protocol_family,
+ int protocol,
+ int reuse_addr)
{
ACE_TRACE ("ACE_SOCK_Dgram::open");
if (ACE_SOCK::open (SOCK_DGRAM, protocol_family,
- protocol, reuse_addr) == -1)
+ protocol, reuse_addr) == -1)
return -1;
else
return this->shared_open (local, protocol_family);
@@ -115,9 +116,9 @@ ACE_SOCK_Dgram::open (const ACE_Addr &local,
ssize_t
ACE_SOCK_Dgram::send (const iovec iov[],
- size_t n,
- const ACE_Addr &addr,
- int flags) const
+ size_t n,
+ const ACE_Addr &addr,
+ int flags) const
{
ACE_TRACE ("ACE_SOCK_Dgram::send");
msghdr send_msg;
@@ -140,9 +141,9 @@ ACE_SOCK_Dgram::send (const iovec iov[],
ssize_t
ACE_SOCK_Dgram::recv (iovec iov[],
- size_t n,
- ACE_Addr &addr,
- int flags) const
+ size_t n,
+ ACE_Addr &addr,
+ int flags) const
{
ACE_TRACE ("ACE_SOCK_Dgram::recv");
msghdr recv_msg;
@@ -159,9 +160,100 @@ ACE_SOCK_Dgram::recv (iovec iov[],
recv_msg.msg_accrightslen = 0;
ssize_t status = ACE_OS::recvmsg (this->get_handle (),
- &recv_msg, flags);
+ &recv_msg, flags);
addr.set_size (recv_msg.msg_namelen);
return status;
}
+#else /* ACE_HAS_MSG */
+
+// Send an iovec of size N to ADDR as a datagram (connectionless
+// version).
+
+ssize_t
+ACE_SOCK_Dgram::send (const iovec iov[],
+ size_t n,
+ const ACE_Addr &addr,
+ int flags) const
+{
+ ACE_TRACE ("ACE_SOCK_Dgram::send");
+
+ size_t length = 0;
+ size_t i;
+
+ // Determine the total length of all the buffers in <iov>.
+ for (i = 0; i < n; i++)
+ if (iov[i].iov_len < 0)
+ return -1;
+ else
+ length += iov[i].iov_len;
+
+ char *buf;
+
+#if defined (ACE_HAS_ALLOCA)
+ buf = (iovec *) alloca (length);
+#else
+ ACE_NEW_RETURN (buf, length, -1);
+#endif /* !defined (ACE_HAS_ALLOCA) */
+
+ char *ptr = buf;
+
+ for (i = 0; i < n; i++)
+ {
+ ACE_OS::memcpy (ptr, iov[i].iov_base, iov[i].iov_len);
+ ptr += iov[i].iov_len;
+ }
+
+ ssize_t result = ACE_SOCK_Dgram::send (buf, length, addr, flags);
+#if !defined (ACE_HAS_ALLOCA)
+ delete [] buf;
+#endif /* !defined (ACE_HAS_ALLOCA) */
+ return result;
+}
+
+// Recv an iovec of size N to ADDR as a datagram (connectionless
+// version).
+
+ssize_t
+ACE_SOCK_Dgram::recv (iovec iov[],
+ size_t n,
+ ACE_Addr &addr,
+ int flags) const
+{
+ ACE_TRACE ("ACE_SOCK_Dgram::recv");
+
+ ssize_t length = 0;
+ size_t i;
+
+ for (i = 0; i < n; i++)
+ if (iov[i].iov_len < 0)
+ return -1;
+ else
+ length += iov[i].iov_len;
+
+#if defined (ACE_HAS_ALLOCA)
+ buf = (iovec *) alloca (length);
+#else
+ ACE_NEW_RETURN (buf, length, -1);
+#endif /* !defined (ACE_HAS_ALLOCA) */
+
+ length = ACE_SOCK_Dgram::recv (buf, length, addr, flags);
+
+ if (length != -1)
+ {
+ char *ptr = buf;
+
+ for (i = 0; i < n; i++)
+ {
+ ACE_OS::memcpy (iov[i].iov_base, ptr, iov[i].iov_len);
+ ptr += iov[i].iov_len;
+ }
+ }
+
+#if !defined (ACE_HAS_ALLOCA)
+ delete [] buf;
+#endif /* !defined (ACE_HAS_ALLOCA) */
+ return length;
+}
+
#endif /* ACE_HAS_MSG */