3 //=============================================================================
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 //=============================================================================
11 #ifndef ACE_SOCK_DGRAM_H
12 #define ACE_SOCK_DGRAM_H
13 #include /**/ "ace/pre.h"
16 #include "ace/INET_Addr.h"
18 // Included so users have access to ACE_RECVPKTINFO and ACE_RECVPKTINFO6 .
19 #include "ace/OS_NS_sys_socket.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
27 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
32 * @class ACE_SOCK_Dgram
34 * @brief Defines the member functions for the ACE_SOCK datagram
37 class ACE_Export ACE_SOCK_Dgram
: public ACE_SOCK
40 /// Default constructor.
43 /// This is a BSD-style method (i.e., no QoS) for initiating a socket
44 /// dgram that will accept datagrams at the <local> address.
45 ACE_SOCK_Dgram (const ACE_Addr
&local
,
46 int protocol_family
= ACE_PROTOCOL_FAMILY_INET
,
52 * This is a QoS-enabed method for initiating a socket dgram that
53 * will accept datagrams at the <local> address. The @a qos_params
54 * are passed to <ACE_OS::join_leaf>.
56 ACE_SOCK_Dgram (const ACE_Addr
&local
,
59 ACE_Protocol_Info
*protocolinfo
,
65 /// This is a BSD-style method (i.e., no QoS) for initiating a socket
66 /// dgram that will accept datagrams at the <local> address.
67 int open (const ACE_Addr
&local
,
68 int protocol_family
= ACE_PROTOCOL_FAMILY_INET
,
74 * This is a QoS-enabed method for initiating a socket dgram that
75 * will accept datagrams at the <local> address. The @a qos_params
76 * are passed to <ACE_OS::join_leaf>.
78 int open (const ACE_Addr
&local
,
81 ACE_Protocol_Info
*protocolinfo
,
90 // = Data transfer routines.
91 /// Send an @a n byte @a buf to the datagram socket (uses <sendto(3)>).
92 ssize_t
send (const void *buf
,
97 /// Receive an @a n byte @a buf from the datagram socket (uses
99 ssize_t
recv (void *buf
,
102 int flags
= 0) const;
105 * Allows a client to read from a socket without having to provide a
106 * buffer to read. This method determines how much data is in the
107 * socket, allocates a buffer of this size, reads in the data, and
108 * returns the number of bytes read. The caller is responsible for
109 * deleting the member in the <iov_base> field of <io_vec> using the
110 * ``delete []'' syntax.
112 ssize_t
recv (iovec
*io_vec
,
115 const ACE_Time_Value
*timeout
= 0) const;
117 /// Send an <iovec> of size @a n to the datagram socket (uses
119 ssize_t
send (const iovec iov
[],
121 const ACE_Addr
&addr
,
122 int flags
= 0) const;
124 /// Recv an <iovec> of size @a n to the datagram socket (uses
125 /// <recvmsg(3)>). The IP destination address will be placed in @a
126 /// *to_addr if it is not null and set_option has been called with
127 /// 1) level IPPROTO_IP, option ACE_RECVPKTINFO, and value 1 for
128 /// IPV4 addresses or 2) IPPROTO_IPV6, option ACE_RECVPKTINFO6, and
129 /// value 1 for IPV6 addresses.
130 ssize_t
recv (iovec iov
[],
134 ACE_INET_Addr
*to_addr
= 0) const;
137 * Wait up to @a timeout amount of time to receive a datagram into
138 * @a buf. The ACE_Time_Value indicates how long to blocking
139 * trying to receive. If @a timeout == 0, the caller will block
140 * until action is possible, else will wait until the relative time
141 * specified in *@a timeout elapses). If <recv> times out a -1 is
142 * returned with @c errno == ETIME. If it succeeds the number of
143 * bytes received is returned.
145 ssize_t
recv (void *buf
,
149 const ACE_Time_Value
*timeout
) const;
152 * Wait up to @a timeout amount of time to send a datagram to
153 * @a buf. The ACE_Time_Value indicates how long to blocking
154 * trying to receive. If @a timeout == 0, the caller will block
155 * until action is possible, else will wait until the relative time
156 * specified in *@a timeout elapses). If <send> times out a -1 is
157 * returned with @c errno == ETIME. If it succeeds the number of
158 * bytes sent is returned.
160 ssize_t
send (const void *buf
,
162 const ACE_Addr
&addr
,
164 const ACE_Time_Value
*timeout
) const;
166 /// Send <buffer_count> worth of @a buffers to @a addr using overlapped
167 /// I/O (uses <WSASendTo>). Returns 0 on success.
168 ssize_t
send (const iovec buffers
[],
170 size_t &number_of_bytes_sent
,
172 const ACE_Addr
&addr
,
173 ACE_OVERLAPPED
*overlapped
,
174 ACE_OVERLAPPED_COMPLETION_FUNC func
) const;
176 /// Recv <buffer_count> worth of @a buffers from @a addr using
177 /// overlapped I/O (uses <WSARecvFrom>). Returns 0 on success.
178 ssize_t
recv (iovec buffers
[],
180 size_t &number_of_bytes_recvd
,
183 ACE_OVERLAPPED
*overlapped
,
184 ACE_OVERLAPPED_COMPLETION_FUNC func
) const;
186 /// Send an @a n byte @a buf to the datagram socket (uses <WSASendTo>).
187 ssize_t
send (const void *buf
,
189 const ACE_Addr
&addr
,
191 ACE_OVERLAPPED
*overlapped
,
192 ACE_OVERLAPPED_COMPLETION_FUNC func
) const;
194 /// Receive an @a n byte @a buf from the datagram socket (uses
196 ssize_t
recv (void *buf
,
200 ACE_OVERLAPPED
*overlapped
,
201 ACE_OVERLAPPED_COMPLETION_FUNC func
) const;
204 typedef ACE_INET_Addr PEER_ADDR
;
206 /// Dump the state of an object.
209 /// Set NIC to use as multicast interface.
210 int set_nic (const ACE_TCHAR
*net_if
,
211 int addr_family
= AF_UNSPEC
);
213 /// Declare the dynamic allocation hooks.
214 ACE_ALLOC_HOOK_DECLARE
;
217 /// Open is shared by this and by <LSOCK_Dgram>.
218 int shared_open (const ACE_Addr
&local
,
222 /// Create a multicast addr/if pair, in format useful for system calls.
223 /// If mreq param is NULL, just verify the passed addr/interface specs.
224 int make_multicast_ifaddr (ip_mreq
*mreq
, // Put result here, if != NULL.
225 const ACE_INET_Addr
&mcast_addr
,
226 const ACE_TCHAR
*net_if
);
228 #if defined (ACE_HAS_IPV6)
229 /// Create a multicast addr/if pair, in format useful for system calls.
230 /// If mreq param is NULL, just verify the passed addr/interface specs.
231 int make_multicast_ifaddr6 (ipv6_mreq
*mreq
, // Put result here, if != NULL.
232 const ACE_INET_Addr
&mcast_addr
,
233 const ACE_TCHAR
*net_if
);
235 #endif /* ACE_HAS_IPV6 */
238 /// Do not allow this function to percolate up to this interface...
239 int get_remote_addr (ACE_Addr
&) const;
242 ACE_END_VERSIONED_NAMESPACE_DECL
244 #if defined (__ACE_INLINE__)
245 #include "ace/SOCK_Dgram.inl"
246 #endif /* __ACE_INLINE__ */
248 #include /**/ "ace/post.h"
249 #endif /* ACE_SOCK_DGRAM_H */