Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

LSOCK_Stream.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // LSOCK_Stream.cpp
00003 // $Id: LSOCK_Stream.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:21 chad Exp $
00004 
00005 #include "ace/LSOCK_Stream.h"
00006 #if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS)
00007 
00008 #include "ace/Log_Msg.h"
00009 
00010 ACE_RCSID(ace, LSOCK_Stream, "$Id: LSOCK_Stream.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:21 chad Exp $")
00011 
00012 #if defined (ACE_LACKS_INLINE_FUNCTIONS)
00013 #include "ace/LSOCK_Stream.i"
00014 #endif
00015 
00016 ACE_ALLOC_HOOK_DEFINE(ACE_LSOCK_Stream)
00017 
00018 int
00019 ACE_LSOCK_Stream::get_local_addr (ACE_Addr &addr) const
00020 {
00021   ACE_TRACE ("ACE_LSOCK_Stream::get_local_addr");
00022 
00023   // Perform the downcast since <addr> had better be an
00024   // <ACE_UNIX_Addr>.
00025   ACE_UNIX_Addr *rhs_unix_addr = ACE_dynamic_cast (ACE_UNIX_Addr *, &addr);
00026   ACE_UNIX_Addr lhs_unix_addr;
00027 
00028   if (rhs_unix_addr == 0)
00029     return -1;
00030   else if (ACE_SOCK::get_local_addr (lhs_unix_addr) == -1)
00031     return -1;
00032   else
00033     {
00034       *rhs_unix_addr = lhs_unix_addr;
00035       return 0;
00036     }
00037 }
00038 
00039 int
00040 ACE_LSOCK_Stream::get_remote_addr (ACE_Addr &addr) const
00041 {
00042   ACE_TRACE ("ACE_LSOCK_Stream::get_remote_addr");
00043 
00044   return this->get_local_addr (addr);
00045 }
00046 
00047 void
00048 ACE_LSOCK_Stream::dump (void) const
00049 {
00050   ACE_TRACE ("ACE_LSOCK_Stream::dump");
00051 
00052   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00053   ACE_SOCK_Stream::dump ();
00054   ACE_LSOCK::dump ();
00055   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00056 }
00057 
00058 #if defined (ACE_HAS_MSG)
00059 
00060 // Send a readv-style vector of buffers, along with an open I/O
00061 // handle.
00062 
00063 ssize_t
00064 ACE_LSOCK_Stream::send_msg (const iovec iov[], 
00065                             size_t n, 
00066                             ACE_HANDLE handle)
00067 {
00068   ACE_TRACE ("ACE_LSOCK_Stream::send_msg");
00069   msghdr send_msg;
00070 #if defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
00071   char cmsgbuf[ACE_BSD_CONTROL_MSG_LEN];
00072   cmsghdr *cmsgptr = (cmsghdr *) cmsgbuf;
00073 #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
00074 
00075   send_msg.msg_iov = (iovec *) iov;
00076   send_msg.msg_iovlen = n;
00077   send_msg.msg_name = 0;
00078   send_msg.msg_namelen = 0;
00079 
00080 #if defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
00081   cmsgptr->cmsg_level = SOL_SOCKET;
00082   cmsgptr->cmsg_type = SCM_RIGHTS;
00083   cmsgptr->cmsg_len = sizeof cmsgbuf;
00084   send_msg.msg_control = cmsgbuf;
00085   send_msg.msg_controllen = sizeof cmsgbuf;
00086   *(ACE_HANDLE *) CMSG_DATA (cmsgptr) = handle;
00087   send_msg.msg_flags = 0 ;
00088 #else
00089   send_msg.msg_accrights    = (char *) &handle;
00090   send_msg.msg_accrightslen = sizeof handle;
00091 #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
00092 
00093   return ACE_OS::sendmsg (this->ACE_SOCK_Stream::get_handle (), 
00094                           &send_msg, 0);
00095 }
00096 
00097 // Read a readv-style vector of buffers, along with an open I/O
00098 // handle.
00099 
00100 ssize_t
00101 ACE_LSOCK_Stream::recv_msg (iovec iov[], 
00102                             size_t n, 
00103                             ACE_HANDLE &handle)
00104 {
00105   ACE_TRACE ("ACE_LSOCK_Stream::recv_msg");
00106   msghdr recv_msg;
00107 #if defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
00108   char cmsgbuf[ACE_BSD_CONTROL_MSG_LEN];
00109   cmsghdr *cmsgptr = (cmsghdr *) cmsgbuf;
00110 #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
00111   
00112   recv_msg.msg_iov = (iovec *) iov;
00113   recv_msg.msg_iovlen = n;
00114   recv_msg.msg_name = 0;
00115   recv_msg.msg_namelen = 0;
00116 
00117 #if defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG)
00118   recv_msg.msg_control = cmsgbuf;
00119   recv_msg.msg_controllen = sizeof cmsgbuf;
00120   ssize_t result = ACE_OS::recvmsg (this->ACE_SOCK_Stream::get_handle (), 
00121                                     &recv_msg, 0);
00122   handle = *(ACE_HANDLE*) CMSG_DATA (cmsgptr) ;
00123   return result;
00124 #else
00125   recv_msg.msg_accrights = (char *) &handle;
00126   recv_msg.msg_accrightslen = sizeof handle;
00127 
00128   return ACE_OS::recvmsg (this->ACE_SOCK_Stream::get_handle (), 
00129                           &recv_msg, 0);
00130 #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */
00131 }
00132 #endif /* ACE_HAS_MSG */
00133 #endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */

Generated on Mon Jun 16 11:20:03 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002