3 #if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS)
5 #include "ace/Log_Category.h"
6 #include "ace/OS_NS_sys_socket.h"
7 #if defined (ACE_HAS_ALLOC_HOOKS)
8 # include "ace/Malloc_Base.h"
9 #endif /* ACE_HAS_ALLOC_HOOKS */
11 #if !defined (__ACE_INLINE__)
12 #include "ace/LSOCK.inl"
13 #endif /* __ACE_INLINE__ */
15 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
17 ACE_ALLOC_HOOK_DEFINE(ACE_LSOCK
)
20 ACE_LSOCK::dump () const
22 #if defined (ACE_HAS_DUMP)
23 ACE_TRACE ("ACE_LSOCK::dump");
25 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
26 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("aux_handle_ = %d"), this->aux_handle_
));
27 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
28 #endif /* ACE_HAS_DUMP */
31 #if defined (ACE_HAS_MSG)
32 // This routine sends an open file descriptor to <this->handle_>.
35 ACE_LSOCK::send_handle (const ACE_HANDLE handle
) const
37 ACE_TRACE ("ACE_LSOCK::send_handle");
41 #if !defined (ACE_LACKS_SENDMSG) && defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
42 char cmsgbuf
[ACE_BSD_CONTROL_MSG_LEN
];
43 cmsghdr
*cmsgptr
= (cmsghdr
*) cmsgbuf
;
44 #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
48 iov
.iov_base
= (char *) a
;
49 iov
.iov_len
= sizeof a
;
50 send_msg
.msg_iov
= &iov
;
51 send_msg
.msg_iovlen
= 1;
52 send_msg
.msg_name
= 0;
53 send_msg
.msg_namelen
= 0;
55 #if defined (ACE_LACKS_SENDMSG)
56 ACE_UNUSED_ARG(handle
);
58 # if defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
59 cmsgptr
->cmsg_level
= SOL_SOCKET
;
60 cmsgptr
->cmsg_type
= SCM_RIGHTS
;
61 cmsgptr
->cmsg_len
= sizeof cmsgbuf
;
62 send_msg
.msg_control
= cmsgbuf
;
63 send_msg
.msg_controllen
= sizeof cmsgbuf
;
64 ACE_HANDLE
*ph
= (ACE_HANDLE
*) CMSG_DATA (cmsgptr
);
66 send_msg
.msg_flags
= 0;
68 send_msg
.msg_accrights
= (char *) &handle
;
69 send_msg
.msg_accrightslen
= sizeof handle
;
70 # endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
71 #endif /* ACE_LACKS_SENDMSG */
73 return ACE_OS::sendmsg (this->get_handle (), &send_msg
, 0);
76 // This file receives an open file descriptor from <this->handle_>.
77 // Note, this routine returns -1 if problems occur, 0 if we recv a
78 // message that does not have file descriptor in it, and 1 otherwise.
81 ACE_LSOCK::recv_handle (ACE_HANDLE
&handle
, char *pbuf
, ssize_t
*len
) const
83 ACE_TRACE ("ACE_LSOCK::recv_handle");
88 #if defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
89 char cmsgbuf
[ACE_BSD_CONTROL_MSG_LEN
];
90 #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
92 if (pbuf
!= 0 && len
!= 0)
99 iov
.iov_base
= (char *) a
;
100 iov
.iov_len
= sizeof a
;
103 recv_msg
.msg_iov
= &iov
;
104 recv_msg
.msg_iovlen
= 1;
105 recv_msg
.msg_name
= 0;
106 recv_msg
.msg_namelen
= 0;
108 #ifndef ACE_LACKS_SENDMSG
109 #if defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
110 recv_msg
.msg_control
= cmsgbuf
;
111 recv_msg
.msg_controllen
= sizeof cmsgbuf
;
113 recv_msg
.msg_accrights
= (char *) &handle
;
114 recv_msg
.msg_accrightslen
= sizeof handle
;
115 #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
116 #endif /* ACE_LACKS_SENDMSG */
118 #if defined (ACE_HAS_STREAMS)
120 ssize_t nbytes
= ACE_OS::recvmsg (this->get_handle (), &recv_msg
, 0);
122 if (nbytes
!= ACE_INVALID_HANDLE
)
127 if (nbytes
== sizeof a
128 && ((u_char
*) iov
.iov_base
)[0] == 0xab
129 && ((u_char
*) iov
.iov_base
)[1] == 0xcd)
131 #if defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
132 cmsghdr
*cmsgptr
= (cmsghdr
*) cmsgbuf
;
133 handle
= *(ACE_HANDLE
*) CMSG_DATA (cmsgptr
);
134 #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
141 ssize_t nbytes
= ACE_OS::recvmsg (this->get_handle (),
145 if (nbytes
!= ACE_INVALID_HANDLE
)
147 if (nbytes
== sizeof a
148 && ((u_char
*) iov
.iov_base
)[0] == 0xab
149 && ((u_char
*) iov
.iov_base
)[1] == 0xcd)
151 #ifndef ACE_LACKS_SENDMSG
152 #if defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
153 // Close down the socket that was returned by the MSG_PEEK.
154 cmsghdr
*cmsgptr
= (cmsghdr
*) cmsgbuf
;
155 ACE_HANDLE
* ph
= (ACE_HANDLE
*) CMSG_DATA (cmsgptr
);
156 ACE_OS::closesocket (*ph
);
157 recv_msg
.msg_control
= cmsgbuf
;
158 recv_msg
.msg_controllen
= sizeof cmsgbuf
;
160 recv_msg
.msg_accrights
= (char *) &handle
;
161 recv_msg
.msg_accrightslen
= sizeof handle
;
162 #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
163 #endif /* ACE_LACKS_SENDMSG */
164 if (ACE_OS::recvmsg (this->get_handle (),
165 &recv_msg
, 0) == ACE_INVALID_HANDLE
)
166 return ACE_INVALID_HANDLE
;
169 #if defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
170 cmsghdr
*cmsgptr
= (cmsghdr
*) cmsgbuf
;
171 ACE_HANDLE
* ph
= (ACE_HANDLE
*) CMSG_DATA (cmsgptr
);
173 #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
184 #endif /* ACE_HAS_STREAMS */
186 return ACE_INVALID_HANDLE
;
188 #endif /* ACE_HAS_MSG */
190 ACE_END_VERSIONED_NAMESPACE_DECL
192 #endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */