Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / LSOCK_Stream.cpp
blobfa2e0c48a3777fee0d4fe360d927a646f9cae0f7
1 #include "ace/LSOCK_Stream.h"
2 #if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS)
4 #include "ace/Log_Category.h"
5 #include "ace/OS_NS_sys_socket.h"
6 #if defined (ACE_HAS_ALLOC_HOOKS)
7 # include "ace/Malloc_Base.h"
8 #endif /* ACE_HAS_ALLOC_HOOKS */
10 #if !defined (__ACE_INLINE__)
11 #include "ace/LSOCK_Stream.inl"
12 #endif /* __ACE_INLINE__ */
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 ACE_ALLOC_HOOK_DEFINE(ACE_LSOCK_Stream)
18 int
19 ACE_LSOCK_Stream::get_local_addr (ACE_Addr &addr) const
21 ACE_TRACE ("ACE_LSOCK_Stream::get_local_addr");
23 // Perform the downcast since <addr> had better be an
24 // <ACE_UNIX_Addr>.
25 ACE_UNIX_Addr *rhs_unix_addr = dynamic_cast<ACE_UNIX_Addr *> (&addr);
26 ACE_UNIX_Addr lhs_unix_addr;
28 if (rhs_unix_addr == 0)
29 return -1;
30 else if (ACE_SOCK::get_local_addr (lhs_unix_addr) == -1)
31 return -1;
32 else
34 *rhs_unix_addr = lhs_unix_addr;
35 return 0;
39 int
40 ACE_LSOCK_Stream::get_remote_addr (ACE_Addr &addr) const
42 ACE_TRACE ("ACE_LSOCK_Stream::get_remote_addr");
44 return this->get_local_addr (addr);
47 void
48 ACE_LSOCK_Stream::dump () const
50 ACE_TRACE ("ACE_LSOCK_Stream::dump");
52 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
53 ACE_SOCK_Stream::dump ();
54 ACE_LSOCK::dump ();
55 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
58 #if defined (ACE_HAS_MSG)
60 // Send a readv-style vector of buffers, along with an open I/O
61 // handle.
63 ssize_t
64 ACE_LSOCK_Stream::send_msg (const iovec iov[],
65 size_t n,
66 ACE_HANDLE handle)
68 ACE_TRACE ("ACE_LSOCK_Stream::send_msg");
69 msghdr send_msg;
70 #if !defined (ACE_LACKS_SENDMSG) && defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
71 char cmsgbuf[ACE_BSD_CONTROL_MSG_LEN];
72 cmsghdr *cmsgptr = (cmsghdr *) cmsgbuf;
73 #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
75 send_msg.msg_iov = const_cast <iovec *> (iov);
76 send_msg.msg_iovlen = n;
77 send_msg.msg_name = 0;
78 send_msg.msg_namelen = 0;
80 #if defined (ACE_LACKS_SENDMSG)
81 ACE_UNUSED_ARG (handle);
82 #else
83 # if defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
84 cmsgptr->cmsg_level = SOL_SOCKET;
85 cmsgptr->cmsg_type = SCM_RIGHTS;
86 cmsgptr->cmsg_len = sizeof cmsgbuf;
87 send_msg.msg_control = cmsgbuf;
88 send_msg.msg_controllen = sizeof cmsgbuf;
89 *(ACE_HANDLE *) CMSG_DATA (cmsgptr) = handle;
90 send_msg.msg_flags = 0 ;
91 # else
92 send_msg.msg_accrights = (char *) &handle;
93 send_msg.msg_accrightslen = sizeof handle;
94 # endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
95 #endif /* ACE_LACKS_SENDMSG */
97 return ACE_OS::sendmsg (this->ACE_SOCK_Stream::get_handle (),
98 &send_msg, 0);
101 // Read a readv-style vector of buffers, along with an open I/O
102 // handle.
104 ssize_t
105 ACE_LSOCK_Stream::recv_msg (iovec iov[],
106 size_t n,
107 ACE_HANDLE &handle)
109 ACE_TRACE ("ACE_LSOCK_Stream::recv_msg");
110 msghdr recv_msg;
111 #if !defined (ACE_LACKS_SENDMSG) && defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
112 char cmsgbuf[ACE_BSD_CONTROL_MSG_LEN];
113 cmsghdr *cmsgptr = (cmsghdr *) cmsgbuf;
114 #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
116 recv_msg.msg_iov = (iovec *) iov;
117 recv_msg.msg_iovlen = n;
118 recv_msg.msg_name = 0;
119 recv_msg.msg_namelen = 0;
121 #if defined (ACE_LACKS_SENDMSG)
122 ACE_UNUSED_ARG (handle);
123 #elif defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
124 recv_msg.msg_control = cmsgbuf;
125 recv_msg.msg_controllen = sizeof cmsgbuf;
126 ssize_t result = ACE_OS::recvmsg (this->ACE_SOCK_Stream::get_handle (),
127 &recv_msg, 0);
128 handle = *(ACE_HANDLE*) CMSG_DATA (cmsgptr) ;
129 return result;
130 #else
131 recv_msg.msg_accrights = (char *) &handle;
132 recv_msg.msg_accrightslen = sizeof handle;
133 #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */ /* ACE_LACKS_SENDMSG */
135 #if defined ACE_LACKS_SENDMSG || !defined ACE_HAS_4_4BSD_SENDMSG_RECVMSG
136 return ACE_OS::recvmsg (this->ACE_SOCK_Stream::get_handle (),
137 &recv_msg, 0);
138 #endif
140 #endif /* ACE_HAS_MSG */
142 ACE_END_VERSIONED_NAMESPACE_DECL
144 #endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */