#include <SOCK_Dgram.h>
Inheritance diagram for ACE_SOCK_Dgram:


Public Types | |
| typedef ACE_INET_Addr | PEER_ADDR |
Public Member Functions | |
| ACE_SOCK_Dgram (void) | |
| Default constructor. | |
| ACE_SOCK_Dgram (const ACE_Addr &local, int protocol_family=ACE_PROTOCOL_FAMILY_INET, int protocol=0, int reuse_addr=0) | |
| ACE_SOCK_Dgram (const ACE_Addr &local, int protocol_family, int protocol, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g=0, u_long flags=0, int reuse_addr=0) | |
| int | open (const ACE_Addr &local, int protocol_family=ACE_PROTOCOL_FAMILY_INET, int protocol=0, int reuse_addr=0) |
| int | open (const ACE_Addr &local, int protocol_family, int protocol, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g=0, u_long flags=0, int reuse_addr=0) |
| ~ACE_SOCK_Dgram (void) | |
| Default dtor. | |
| ssize_t | send (const void *buf, size_t n, const ACE_Addr &addr, int flags=0) const |
| Send an n byte buf to the datagram socket (uses <sendto(3)>). | |
| ssize_t | recv (void *buf, size_t n, ACE_Addr &addr, int flags=0) const |
| ssize_t | recv (iovec *io_vec, ACE_Addr &addr, int flags=0, const ACE_Time_Value *timeout=0) const |
| ssize_t | send (const iovec iov[], int n, const ACE_Addr &addr, int flags=0) const |
| ssize_t | recv (iovec iov[], int n, ACE_Addr &addr, int flags=0) const |
| ssize_t | recv (void *buf, size_t n, ACE_Addr &addr, int flags, const ACE_Time_Value *timeout) const |
| ssize_t | send (const void *buf, size_t n, const ACE_Addr &addr, int flags, const ACE_Time_Value *timeout) const |
| ssize_t | send (const iovec buffers[], int buffer_count, size_t &number_of_bytes_sent, int flags, const ACE_Addr &addr, ACE_OVERLAPPED *overlapped, ACE_OVERLAPPED_COMPLETION_FUNC func) const |
| ssize_t | recv (iovec buffers[], int buffer_count, size_t &number_of_bytes_recvd, int &flags, ACE_Addr &addr, ACE_OVERLAPPED *overlapped, ACE_OVERLAPPED_COMPLETION_FUNC func) const |
| ssize_t | send (const void *buf, size_t n, const ACE_Addr &addr, int flags, ACE_OVERLAPPED *overlapped, ACE_OVERLAPPED_COMPLETION_FUNC func) const |
| Send an n byte buf to the datagram socket (uses ). | |
| ssize_t | recv (void *buf, size_t n, ACE_Addr &addr, int flags, ACE_OVERLAPPED *overlapped, ACE_OVERLAPPED_COMPLETION_FUNC func) const |
| void | dump (void) const |
| Dump the state of an object. | |
| int | set_nic (const ACE_TCHAR *net_if, int addr_family=AF_UNSPEC) |
| Set NIC to use as multicast interface. | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. | |
Protected Member Functions | |
| int | shared_open (const ACE_Addr &local, int protocol_family) |
| Open is shared by this and by . | |
| int | make_multicast_ifaddr (ip_mreq *mreq, const ACE_INET_Addr &mcast_addr, const ACE_TCHAR *net_if) |
| int | make_multicast_ifaddr6 (ipv6_mreq *mreq, const ACE_INET_Addr &mcast_addr, const ACE_TCHAR *net_if) |
Private Member Functions | |
| int | get_remote_addr (ACE_Addr &) const |
| Do not allow this function to percolate up to this interface... | |
Definition at line 36 of file SOCK_Dgram.h.
|
|
Definition at line 195 of file SOCK_Dgram.h. |
|
|
Default constructor.
Definition at line 14 of file SOCK_Dgram.inl. References ACE_TRACE.
00015 {
00016 ACE_TRACE ("ACE_SOCK_Dgram::ACE_SOCK_Dgram");
00017 }
|
|
||||||||||||||||||||
|
This is a BSD-style method (i.e., no QoS) for initiating a socket dgram that will accept datagrams at the address. Definition at line 225 of file SOCK_Dgram.cpp. References ACE_ERROR, ACE_TEXT, ACE_TRACE, LM_ERROR, and open().
|
|
||||||||||||||||||||||||||||||||
|
This is a QoS-enabed method for initiating a socket dgram that will accept datagrams at the address. The are passed to <ACE_OS::join_leaf>. Definition at line 241 of file SOCK_Dgram.cpp. References ACE_ERROR, ACE_SOCK_GROUP, ACE_TEXT, ACE_TRACE, LM_ERROR, and open().
|
|
|
Default dtor.
Definition at line 20 of file SOCK_Dgram.inl. References ACE_TRACE.
00021 {
00022 ACE_TRACE ("ACE_SOCK_Dgram::~ACE_SOCK_Dgram");
00023 }
|
|
|
Dump the state of an object.
Reimplemented from ACE_SOCK. Reimplemented in ACE_LSOCK_Dgram, ACE_SOCK_Dgram_Bcast, and ACE_SOCK_Dgram_Mcast. Definition at line 37 of file SOCK_Dgram.cpp. References ACE_TRACE. Referenced by ACE_LSOCK_Dgram::dump().
00038 {
00039 #if defined (ACE_HAS_DUMP)
00040 ACE_TRACE ("ACE_SOCK_Dgram::dump");
00041 #endif /* ACE_HAS_DUMP */
00042 }
|
|
|
Do not allow this function to percolate up to this interface...
Reimplemented from ACE_SOCK. Reimplemented in ACE_SOCK_Dgram_Bcast. |
|
||||||||||||||||
|
Create a multicast addr/if pair, in format useful for system calls. If mreq param is NULL, just verify the passed addr/interface specs. Definition at line 613 of file SOCK_Dgram.cpp. References ACE_HTONL, ACE_TCHAR, ACE_TEXT_ALWAYS_CHAR, ACE_TRACE, ACE_INET_Addr::get_ip_address(), ACE_INET_Addr::get_port_number(), INADDR_ANY, ACE_OS::ioctl(), ACE_INET_Addr::set(), SIOCGIFADDR, and ACE_OS::strcpy(). Referenced by ACE_SOCK_Dgram_Mcast::join(), ACE_SOCK_Dgram_Mcast::leave(), set_nic(), ACE_SOCK_Dgram_Mcast::subscribe_i(), ACE_SOCK_Dgram_Mcast::subscribe_ifs(), and ACE_SOCK_Dgram_Mcast::unsubscribe_i().
00616 {
00617 ACE_TRACE ("ACE_SOCK_Dgram_Mcast::make_multicast_ifaddr");
00618 ip_mreq lmreq; // Scratch copy.
00619 if (net_if != 0)
00620 {
00621 #if defined (ACE_WIN32) || defined(__INTERIX)
00622 // This port number is not necessary, just convenient
00623 ACE_INET_Addr interface_addr;
00624 if (interface_addr.set (mcast_addr.get_port_number (), net_if) == -1)
00625 return -1;
00626 lmreq.imr_interface.s_addr =
00627 ACE_HTONL (interface_addr.get_ip_address ());
00628 #else
00629 ifreq if_address;
00630
00631 ACE_OS::strcpy (if_address.ifr_name, ACE_TEXT_ALWAYS_CHAR (net_if));
00632
00633 if (ACE_OS::ioctl (this->get_handle (),
00634 SIOCGIFADDR,
00635 &if_address) == -1)
00636 return -1;
00637
00638 sockaddr_in *socket_address =
00639 reinterpret_cast<sockaddr_in*> (&if_address.ifr_addr);
00640 lmreq.imr_interface.s_addr = socket_address->sin_addr.s_addr;
00641 #endif /* ACE_WIN32 || __INTERIX */
00642 }
00643 else
00644 lmreq.imr_interface.s_addr = INADDR_ANY;
00645
00646 lmreq.IMR_MULTIADDR.s_addr = ACE_HTONL (mcast_addr.get_ip_address ());
00647
00648 // Set return info, if requested.
00649 if (ret_mreq)
00650 *ret_mreq = lmreq;
00651
00652 return 0;
00653 }
|
|
||||||||||||||||
|
Create a multicast addr/if pair, in format useful for system calls. If mreq param is NULL, just verify the passed addr/interface specs. Definition at line 659 of file SOCK_Dgram.cpp. References ACE_OS::ace_isdigit(), ACE_NEW_RETURN, ACE_TCHAR, ACE_TEXT_ALWAYS_CHAR, ACE_TRACE, ACE_OS::atoi(), ACE_INET_Addr::get_addr(), ACE_OS::memcpy(), ACE_OS::memset(), and ACE_OS::strcmp(). Referenced by set_nic(), ACE_SOCK_Dgram_Mcast::subscribe_i(), ACE_SOCK_Dgram_Mcast::subscribe_ifs(), and ACE_SOCK_Dgram_Mcast::unsubscribe_i().
00662 {
00663 ACE_TRACE ("ACE_SOCK_Dgram_Mcast::make_multicast_ifaddr6");
00664 ipv6_mreq lmreq; // Scratch copy.
00665
00666 ACE_OS::memset (&lmreq,
00667 0,
00668 sizeof (lmreq));
00669
00670 #if defined(__linux__)
00671 if (net_if != 0)
00672 {
00673 lmreq.ipv6mr_interface = ACE_OS::if_nametoindex (ACE_TEXT_ALWAYS_CHAR(net_if));
00674 }
00675 else
00676 #elif defined (ACE_WIN32)
00677 if (net_if != 0)
00678 {
00679 int if_ix = 0;
00680 bool num_if =
00681 ACE_OS::ace_isdigit (net_if[0]) &&
00682 (if_ix = ACE_OS::atoi (net_if)) > 0;
00683
00684 IP_ADAPTER_ADDRESSES tmp_addrs;
00685 // Initial call to determine actual memory size needed
00686 DWORD dwRetVal;
00687 ULONG bufLen = 0;
00688 if ((dwRetVal = ::GetAdaptersAddresses (AF_INET6,
00689 0,
00690 0,
00691 &tmp_addrs,
00692 &bufLen)) != ERROR_BUFFER_OVERFLOW)
00693 return -1; // With output bufferlength 0 this can't be right.
00694
00695 // Get required output buffer and retrieve info for real.
00696 PIP_ADAPTER_ADDRESSES pAddrs;
00697 char *buf;
00698 ACE_NEW_RETURN (buf,
00699 char[bufLen],
00700 -1);
00701 pAddrs = reinterpret_cast<PIP_ADAPTER_ADDRESSES> (buf);
00702 if ((dwRetVal = ::GetAdaptersAddresses (AF_INET6,
00703 0,
00704 0,
00705 pAddrs,
00706 &bufLen)) != NO_ERROR)
00707 {
00708 delete[] buf; // clean up
00709 return -1;
00710 }
00711
00712 lmreq.ipv6mr_interface = 0; // initialize
00713 while (pAddrs)
00714 {
00715 if ((num_if && pAddrs->Ipv6IfIndex == static_cast<unsigned int>(if_ix))
00716 || (!num_if &&
00717 (ACE_OS::strcmp (ACE_TEXT_ALWAYS_CHAR (net_if),
00718 pAddrs->AdapterName) == 0
00719 || ACE_OS::strcmp (ACE_TEXT_ALWAYS_CHAR (net_if),
00720 ACE_Wide_To_Ascii (pAddrs->FriendlyName).char_rep()) == 0)))
00721 {
00722 lmreq.ipv6mr_interface = pAddrs->Ipv6IfIndex;
00723 break;
00724 }
00725
00726 pAddrs = pAddrs->Next;
00727 }
00728
00729 delete[] buf; // clean up
00730 }
00731 else
00732 #else /* ACE_WIN32 */
00733 ACE_UNUSED_ARG(net_if);
00734 #endif /* ACE_WIN32 */
00735 lmreq.ipv6mr_interface = 0;
00736
00737 // now set the multicast address
00738 ACE_OS::memcpy (&lmreq.ipv6mr_multiaddr,
00739 &((sockaddr_in6 *) mcast_addr.get_addr ())->sin6_addr,
00740 sizeof (in6_addr));
00741
00742 // Set return info, if requested.
00743 if (ret_mreq)
00744 *ret_mreq = lmreq;
00745
00746 return 0;
00747 }
|
|
||||||||||||||||||||||||||||||||
|
This is a QoS-enabed method for initiating a socket dgram that will accept datagrams at the address. The are passed to <ACE_OS::join_leaf>. Definition at line 168 of file SOCK_Dgram.cpp. References ACE_SOCK_GROUP, ACE_SOCK::open(), shared_open(), and SOCK_DGRAM.
00175 {
00176 if (ACE_SOCK::open (SOCK_DGRAM,
00177 protocol_family,
00178 protocol,
00179 protocolinfo,
00180 g,
00181 flags,
00182 reuse_addr) == -1)
00183 return -1;
00184 else if (this->shared_open (local,
00185 protocol_family) == -1)
00186 return -1;
00187 else
00188 return 0;
00189 }
|
|
||||||||||||||||||||
|
This is a BSD-style method (i.e., no QoS) for initiating a socket dgram that will accept datagrams at the address. Definition at line 194 of file SOCK_Dgram.cpp. References ACE_TRACE, ACE_Addr::get_type(), ACE::ipv6_enabled(), ACE_SOCK::open(), PF_INET, PF_UNSPEC, shared_open(), and SOCK_DGRAM. Referenced by ACE_SOCK_Dgram(), ACE_SOCK_Dgram_Bcast::open(), and ACE_LSOCK_Dgram::open().
00198 {
00199 ACE_TRACE ("ACE_SOCK_Dgram::open");
00200
00201 if (local != ACE_Addr::sap_any)
00202 protocol_family = local.get_type ();
00203 else if (protocol_family == PF_UNSPEC)
00204 {
00205 #if defined (ACE_HAS_IPV6)
00206 protocol_family = ACE::ipv6_enabled () ? PF_INET6 : PF_INET;
00207 #else
00208 protocol_family = PF_INET;
00209 #endif /* ACE_HAS_IPV6 */
00210 }
00211
00212 if (ACE_SOCK::open (SOCK_DGRAM,
00213 protocol_family,
00214 protocol,
00215 reuse_addr) == -1)
00216 return -1;
00217 else
00218 return this->shared_open (local,
00219 protocol_family);
00220 }
|
|
||||||||||||||||||||||||||||
|
Receive an n byte buf from the datagram socket (uses ). Definition at line 145 of file SOCK_Dgram.inl. References ACE_OVERLAPPED, ACE_OVERLAPPED_COMPLETION_FUNC, ACE_TRACE, and recv().
00151 {
00152 ACE_TRACE ("ACE_SOCK_Dgram::recv");
00153
00154 iovec buffer[1];
00155 buffer[0].iov_len = static_cast<u_long> (n); // Betting on < 4G
00156 buffer[0].iov_base = (char *) buf;
00157 size_t number_of_bytes_recvd = 0;
00158 return this->recv (buffer,
00159 1,
00160 number_of_bytes_recvd,
00161 flags,
00162 addr,
00163 overlapped,
00164 func);
00165 }
|
|
||||||||||||||||||||||||||||||||
|
Recv worth of buffers from addr using overlapped I/O (uses ). Returns 0 on success. Definition at line 91 of file SOCK_Dgram.inl. References ACE_OVERLAPPED, ACE_OVERLAPPED_COMPLETION_FUNC, ACE_TRACE, ACE_Addr::get_addr(), ACE_Addr::get_size(), ACE_OS::recvfrom(), ACE_Addr::set_size(), ACE_Addr::set_type(), and ssize_t.
00098 {
00099 ACE_TRACE ("ACE_SOCK_Dgram::recv");
00100 sockaddr *saddr = (sockaddr *) addr.get_addr ();
00101 int addr_len = addr.get_size ();
00102
00103 ssize_t status = ACE_OS::recvfrom (this->get_handle (),
00104 buffers,
00105 buffer_count,
00106 number_of_bytes_recvd,
00107 flags,
00108 (sockaddr *) saddr,
00109 &addr_len,
00110 overlapped,
00111 func);
00112 addr.set_size (addr_len);
00113 addr.set_type (saddr->sa_family);
00114 return status;
00115 }
|
|
||||||||||||||||||||||||
|
Wait up to timeout amount of time to receive a datagram into buf. The ACE_Time_Value indicates how long to blocking trying to receive. If timeout == 0, the caller will block until action is possible, else will wait until the relative time specified in *timeout elapses). If times out a -1 is returned with <errno == ETIME>. If it succeeds the number of bytes received is returned. Definition at line 451 of file SOCK_Dgram.cpp. References ETIME, recv(), ACE_Handle_Set::reset(), ACE_OS::select(), and ACE_Handle_Set::set_bit().
00456 {
00457 ACE_Handle_Set handle_set;
00458 handle_set.reset ();
00459 handle_set.set_bit (this->get_handle ());
00460
00461 // Check the status of the current socket.
00462 int select_width;
00463 #if defined (ACE_WIN32)
00464 // This arg is ignored on Windows and causes pointer truncation
00465 // warnings on 64-bit compiles.
00466 select_width = 0;
00467 #else
00468 select_width = int (this->get_handle ()) + 1;
00469 #endif /* ACE_WIN32 */
00470 switch (ACE_OS::select (select_width,
00471 handle_set,
00472 0,
00473 0,
00474 timeout))
00475 {
00476 case -1:
00477 return -1;
00478 /* NOTREACHED */
00479 case 0:
00480 errno = ETIME;
00481 return -1;
00482 /* NOTREACHED */
00483 default:
00484 // Goes fine, call <recv> to get data
00485 return this->recv (buf, n, addr, flags);
00486 }
00487 }
|
|
||||||||||||||||||||
|
Recv an of size n to the datagram socket (uses <recvmsg(3)>). Definition at line 391 of file SOCK_Dgram.cpp. References ACE_NEW_RETURN, ACE_TRACE, ACE_OS::memcpy(), recv(), and ssize_t.
00395 {
00396 ACE_TRACE ("ACE_SOCK_Dgram::recv");
00397
00398 ssize_t length = 0;
00399 int i;
00400
00401 for (i = 0; i < n; i++)
00402 #if ! (defined(__BORLANDC__) || defined(linux) || defined(ACE_HAS_RTEMS))
00403 // The iov_len is unsigned on Linux, RTEMS and with Borland. If we go
00404 // ahead and try the if, it will emit a warning.
00405 if (iov[i].iov_len < 0)
00406 return -1;
00407 else
00408 #endif
00409 length += iov[i].iov_len;
00410
00411 char *buf = 0;
00412
00413 #if defined (ACE_HAS_ALLOCA)
00414 buf = alloca (length);
00415 #else
00416 ACE_NEW_RETURN (buf,
00417 char[length],
00418 -1);
00419 #endif /* !defined (ACE_HAS_ALLOCA) */
00420
00421 length = ACE_SOCK_Dgram::recv (buf, length, addr, flags);
00422
00423 if (length != -1)
00424 {
00425 char *ptr = buf;
00426 int copyn = length;
00427
00428 for (i = 0;
00429 i < n && copyn > 0;
00430 i++)
00431 {
00432 ACE_OS::memcpy (iov[i].iov_base, ptr,
00433 // iov_len is int on some platforms, size_t on others
00434 copyn > (int) iov[i].iov_len
00435 ? (size_t) iov[i].iov_len
00436 : (size_t) copyn);
00437 ptr += iov[i].iov_len;
00438 copyn -= iov[i].iov_len;
00439 }
00440 }
00441
00442 #if !defined (ACE_HAS_ALLOCA)
00443 delete [] buf;
00444 #endif /* !defined (ACE_HAS_ALLOCA) */
00445 return length;
00446 }
|
|
||||||||||||||||||||
|
Allows a client to read from a socket without having to provide a buffer to read. This method determines how much data is in the socket, allocates a buffer of this size, reads in the data, and returns the number of bytes read. The caller is responsible for deleting the member in the field of using the ``delete []'' syntax. Definition at line 50 of file SOCK_Dgram.cpp. References ACE_NEW_RETURN, ACE_NOTSUP_RETURN, ACE_TRACE, ETIME, ACE_Addr::get_addr(), ACE_Addr::get_size(), ACE_OS::ioctl(), ACE_OS::recvfrom(), ACE_Handle_Set::reset(), ACE_OS::select(), ACE_Handle_Set::set_bit(), ACE_Addr::set_size(), and ssize_t.
00054 {
00055 ACE_TRACE ("ACE_SOCK_Dgram::recv");
00056 #if defined (FIONREAD)
00057 ACE_Handle_Set handle_set;
00058 handle_set.reset ();
00059 handle_set.set_bit (this->get_handle ());
00060
00061 // Check the status of the current socket to make sure there's data
00062 // to recv (or time out).
00063 int select_width;
00064 # if defined (ACE_WIN32)
00065 // This arg is ignored on Windows and causes pointer truncation
00066 // warnings on 64-bit compiles.
00067 select_width = 0;
00068 # else
00069 select_width = int (this->get_handle ()) + 1;
00070 # endif /* ACE_WIN32 */
00071 switch (ACE_OS::select (select_width,
00072 handle_set,
00073 0, 0,
00074 timeout))
00075 {
00076 case -1:
00077 return -1;
00078 /* NOTREACHED */
00079 case 0:
00080 errno = ETIME;
00081 return -1;
00082 /* NOTREACHED */
00083 default:
00084 // Goes fine, fallthrough to get data
00085 break;
00086 }
00087
00088 sockaddr *saddr = (sockaddr *) addr.get_addr ();
00089 int addr_len = addr.get_size ();
00090 int inlen;
00091
00092 if (ACE_OS::ioctl (this->get_handle (),
00093 FIONREAD,
00094 &inlen) == -1)
00095 return -1;
00096 else if (inlen > 0)
00097 {
00098 ACE_NEW_RETURN (io_vec->iov_base,
00099 char[inlen],
00100 -1);
00101 ssize_t rcv_len = ACE_OS::recvfrom (this->get_handle (),
00102 (char *) io_vec->iov_base,
00103 inlen,
00104 flags,
00105 (sockaddr *) saddr,
00106 &addr_len);
00107 if (rcv_len < 0)
00108 {
00109 delete [] (char *)io_vec->iov_base;
00110 io_vec->iov_base = 0;
00111 }
00112 else
00113 {
00114 io_vec->iov_len = ACE_Utils::truncate_cast<size_t> (rcv_len);
00115 addr.set_size (addr_len);
00116 }
00117 return rcv_len;
00118 }
00119 else
00120 return 0;
00121 #else
00122 ACE_UNUSED_ARG (flags);
00123 ACE_UNUSED_ARG (addr);
00124 ACE_UNUSED_ARG (io_vec);
00125 ACE_UNUSED_ARG (timeout);
00126 ACE_NOTSUP_RETURN (-1);
00127 #endif /* FIONREAD */
00128 }
|
|
||||||||||||||||||||
|
Receive an n byte buf from the datagram socket (uses <recvfrom(3)>). Definition at line 47 of file SOCK_Dgram.inl. References ACE_TRACE, ACE_Addr::get_addr(), ACE_Addr::get_size(), ACE_OS::recvfrom(), ACE_Addr::set_size(), ACE_Addr::set_type(), and ssize_t. Referenced by recv().
00051 {
00052 ACE_TRACE ("ACE_SOCK_Dgram::recv");
00053 sockaddr *saddr = (sockaddr *) addr.get_addr ();
00054 int addr_len = addr.get_size ();
00055
00056 ssize_t const status = ACE_OS::recvfrom (this->get_handle (),
00057 (char *) buf,
00058 n,
00059 flags,
00060 (sockaddr *) saddr,
00061 &addr_len);
00062 addr.set_size (addr_len);
00063 addr.set_type (saddr->sa_family);
00064 return status;
00065 }
|
|
||||||||||||||||||||||||||||
|
Send an n byte buf to the datagram socket (uses ).
Definition at line 120 of file SOCK_Dgram.inl. References ACE_OVERLAPPED, ACE_OVERLAPPED_COMPLETION_FUNC, ACE_TRACE, and send().
00126 {
00127 ACE_TRACE ("ACE_SOCK_Dgram::send");
00128
00129 iovec buffer[1];
00130 buffer[0].iov_len = static_cast<u_long> (n); // Betting on < 4G
00131 buffer[0].iov_base = (char *) buf;
00132 size_t number_of_bytes_sent = 0;
00133 return this->send (buffer,
00134 1,
00135 number_of_bytes_sent,
00136 flags,
00137 addr,
00138 overlapped,
00139 func);
00140 }
|
|
||||||||||||||||||||||||||||||||
|
Send worth of buffers to addr using overlapped I/O (uses ). Returns 0 on success. Definition at line 68 of file SOCK_Dgram.inl. References ACE_OVERLAPPED, ACE_OVERLAPPED_COMPLETION_FUNC, ACE_TRACE, ACE_Addr::get_addr(), ACE_Addr::get_size(), and ACE_OS::sendto().
00075 {
00076 ACE_TRACE ("ACE_SOCK_Dgram::send");
00077 sockaddr *saddr = (sockaddr *) addr.get_addr ();
00078 int len = addr.get_size ();
00079 return ACE_OS::sendto (this->get_handle (),
00080 buffers,
00081 buffer_count,
00082 number_of_bytes_sent,
00083 flags,
00084 (const sockaddr *) saddr,
00085 len,
00086 overlapped,
00087 func);
00088 }
|
|
||||||||||||||||||||||||
|
Wait up to timeout amount of time to send a datagram to buf. The ACE_Time_Value indicates how long to blocking trying to receive. If timeout == 0, the caller will block until action is possible, else will wait until the relative time specified in *timeout elapses). If times out a -1 is returned with <errno == ETIME>. If it succeeds the number of bytes sent is returned. Definition at line 490 of file SOCK_Dgram.cpp. References ETIME, ACE_Handle_Set::reset(), ACE_OS::select(), send(), and ACE_Handle_Set::set_bit().
00495 {
00496 ACE_Handle_Set handle_set;
00497 handle_set.reset ();
00498 handle_set.set_bit (this->get_handle ());
00499
00500 // Check the status of the current socket.
00501 int select_width;
00502 #if defined (ACE_WIN32)
00503 // This arg is ignored on Windows and causes pointer truncation
00504 // warnings on 64-bit compiles.
00505 select_width = 0;
00506 #else
00507 select_width = int (this->get_handle ()) + 1;
00508 #endif /* ACE_WIN32 */
00509 switch (ACE_OS::select (select_width,
00510 0,
00511 handle_set,
00512 0,
00513 timeout))
00514 {
00515 case -1:
00516 return -1;
00517 /* NOTREACHED */
00518 case 0:
00519 errno = ETIME;
00520 return -1;
00521 /* NOTREACHED */
00522 default:
00523 // Goes fine, call <send> to transmit the data.
00524 return this->send (buf, n, addr, flags);
00525 }
00526 }
|
|
||||||||||||||||||||
|
Send an of size n to the datagram socket (uses <sendmsg(3)>). Reimplemented in ACE_SOCK_Dgram_Bcast. Definition at line 341 of file SOCK_Dgram.cpp. References ACE_NEW_RETURN, ACE_TRACE, ACE_OS::memcpy(), send(), and ssize_t.
00345 {
00346 ACE_TRACE ("ACE_SOCK_Dgram::send");
00347
00348 size_t length = 0;
00349 int i;
00350
00351 // Determine the total length of all the buffers in <iov>.
00352 for (i = 0; i < n; i++)
00353 #if ! (defined(__BORLANDC__) || defined(linux) || defined(ACE_HAS_RTEMS))
00354 // The iov_len is unsigned on Linux, RTEMS and with Borland. If we go
00355 // ahead and try the if, it will emit a warning.
00356 if (iov[i].iov_len < 0)
00357 return -1;
00358 else
00359 #endif
00360 length += iov[i].iov_len;
00361
00362 char *buf = 0;
00363
00364 #if defined (ACE_HAS_ALLOCA)
00365 buf = alloca (length);
00366 #else
00367 ACE_NEW_RETURN (buf,
00368 char[length],
00369 -1);
00370 #endif /* !defined (ACE_HAS_ALLOCA) */
00371
00372 char *ptr = buf;
00373
00374 for (i = 0; i < n; i++)
00375 {
00376 ACE_OS::memcpy (ptr, iov[i].iov_base, iov[i].iov_len);
00377 ptr += iov[i].iov_len;
00378 }
00379
00380 ssize_t result = ACE_SOCK_Dgram::send (buf, length, addr, flags);
00381 #if !defined (ACE_HAS_ALLOCA)
00382 delete [] buf;
00383 #endif /* !defined (ACE_HAS_ALLOCA) */
00384 return result;
00385 }
|
|
||||||||||||||||||||
|
Send an n byte buf to the datagram socket (uses <sendto(3)>).
Reimplemented in ACE_SOCK_Dgram_Bcast. Definition at line 28 of file SOCK_Dgram.inl. References ACE_TRACE, ACE_Addr::get_addr(), ACE_Addr::get_size(), and ACE_OS::sendto(). Referenced by ACE_SOCK_Dgram_Mcast::send(), ACE_SOCK_Dgram_Bcast::send(), and send().
00032 {
00033 ACE_TRACE ("ACE_SOCK_Dgram::send");
00034 sockaddr *saddr = (sockaddr *) addr.get_addr ();
00035 int len = addr.get_size ();
00036 return ACE_OS::sendto (this->get_handle (),
00037 (const char *) buf,
00038 n,
00039 flags,
00040 (struct sockaddr *) saddr,
00041 len);
00042 }
|
|
||||||||||||
|
Set NIC to use as multicast interface.
Definition at line 529 of file SOCK_Dgram.cpp. References ACE_DEBUG, ACE_TCHAR, ACE_TEXT, AF_INET, AF_UNSPEC, IP_MULTICAST_IF, IPPROTO_IP, LM_DEBUG, make_multicast_ifaddr(), make_multicast_ifaddr6(), ACE_INET_Addr::set(), and ACE_SOCK::set_option(). Referenced by ACE_SOCK_Dgram_Mcast::open_i().
00531 {
00532 #if defined (IP_MULTICAST_IF) && (IP_MULTICAST_IF != 0)
00533 # if defined (ACE_HAS_IPV6)
00534 bool ipv6_mif_set = false;
00535 if (addr_family == AF_INET6 || addr_family == AF_UNSPEC)
00536 {
00537 ACE_INET_Addr addr;
00538 addr.set (static_cast<u_short> (0), ACE_IPV6_ANY);
00539 ipv6_mreq send_mreq;
00540 if (this->make_multicast_ifaddr6 (&send_mreq,
00541 addr,
00542 net_if) == -1)
00543 return -1;
00544
00545 // Only let this attempt to set unknown interface when INET6 is
00546 // specifically requested. Otherwise we will just try INET.
00547 if (send_mreq.ipv6mr_interface != 0 || addr_family == AF_INET6)
00548 {
00549 if (this->ACE_SOCK::set_option
00550 (IPPROTO_IPV6, IPV6_MULTICAST_IF,
00551 &(send_mreq.ipv6mr_interface),
00552 sizeof send_mreq.ipv6mr_interface) == -1)
00553 return -1;
00554 }
00555 ipv6_mif_set = send_mreq.ipv6mr_interface != 0;
00556 }
00557
00558 # if defined (ACE_WIN32)
00559 // For Win32 net_if is distintly different between INET6 and INET
00560 // so it is always either an INET6 if or an INET if.
00561 if (!ipv6_mif_set && (addr_family == AF_INET || addr_family == AF_UNSPEC))
00562 # else
00563 if (addr_family == AF_INET || addr_family == AF_UNSPEC)
00564 # endif
00565 {
00566 ACE_INET_Addr addr (static_cast<u_short> (0));
00567 ip_mreq send_mreq;
00568 if (this->make_multicast_ifaddr (&send_mreq,
00569 addr,
00570 net_if) == -1)
00571 {
00572 if (!ipv6_mif_set)
00573 return -1;
00574 }
00575 else if (this->ACE_SOCK::set_option (IPPROTO_IP,
00576 IP_MULTICAST_IF,
00577 &(send_mreq.imr_interface),
00578 sizeof send_mreq.imr_interface) == -1)
00579 {
00580 if (!ipv6_mif_set)
00581 return -1;
00582 }
00583 }
00584 # else /* ACE_HAS_IPV6 */
00585 ACE_UNUSED_ARG (addr_family);
00586 ACE_INET_Addr addr (static_cast<u_short> (0));
00587 ip_mreq send_mreq;
00588 if (this->make_multicast_ifaddr (&send_mreq,
00589 addr,
00590 net_if) == -1)
00591 return -1;
00592 if (this->ACE_SOCK::set_option (IPPROTO_IP,
00593 IP_MULTICAST_IF,
00594 &(send_mreq.imr_interface),
00595 sizeof send_mreq.imr_interface) == -1)
00596 return -1;
00597 # endif /* !ACE_HAS_IPV6 */
00598 #else /* IP_MULTICAST_IF */
00599 // Send interface option not supported - ignore it.
00600 // (We may have been invoked by ::subscribe, so we have to allow
00601 // a non-null interface parameter in this function.)
00602 ACE_UNUSED_ARG (net_if);
00603 ACE_UNUSED_ARG (addr_family);
00604 ACE_DEBUG ((LM_DEBUG,
00605 ACE_TEXT ("Send interface specification not ")
00606 ACE_TEXT ("supported - IGNORED.\n")));
00607 #endif /* !IP_MULTICAST_IF */
00608
00609 return 0;
00610 }
|
|
||||||||||||
|
Open is shared by this and by .
Definition at line 136 of file SOCK_Dgram.cpp. References ACE_TRACE, ACE_OS::bind(), ACE::bind_port(), ACE_SOCK::close(), ACE_Addr::get_addr(), ACE_Addr::get_size(), INADDR_ANY, and PF_INET. Referenced by open(), and ACE_SOCK_Dgram_Mcast::open_i().
00138 {
00139 ACE_TRACE ("ACE_SOCK_Dgram::shared_open");
00140 int error = 0;
00141
00142 if (local == ACE_Addr::sap_any)
00143 {
00144 if (protocol_family == PF_INET
00145 #if defined (ACE_HAS_IPV6)
00146 || protocol_family == PF_INET6
00147 #endif /* ACE_HAS_IPV6 */
00148 )
00149 {
00150 if (ACE::bind_port (this->get_handle (),
00151 INADDR_ANY,
00152 protocol_family) == -1)
00153 error = 1;
00154 }
00155 }
00156 else if (ACE_OS::bind (this->get_handle (),
00157 reinterpret_cast<sockaddr *> (local.get_addr ()),
00158 local.get_size ()) == -1)
00159 error = 1;
00160
00161 if (error != 0)
00162 this->close ();
00163
00164 return error ? -1 : 0;
00165 }
|
|
|
Declare the dynamic allocation hooks.
Reimplemented from ACE_SOCK. Reimplemented in ACE_LSOCK_Dgram, ACE_SOCK_Dgram_Bcast, and ACE_SOCK_Dgram_Mcast. Definition at line 205 of file SOCK_Dgram.h. |
1.3.6