3 //=============================================================================
7 * $Id: SOCK_Dgram.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
11 //=============================================================================
13 #ifndef ACE_SOCK_DGRAM_H
14 #define ACE_SOCK_DGRAM_H
15 #include /**/ "ace/pre.h"
18 #include "ace/INET_Addr.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
26 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
31 * @class ACE_SOCK_Dgram
33 * @brief Defines the member functions for the ACE_SOCK datagram
36 class ACE_Export ACE_SOCK_Dgram
: public ACE_SOCK
39 // = Initialization and termination methods.
40 /// Default constructor.
41 ACE_SOCK_Dgram (void);
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
,
51 * This is a QoS-enabed method for initiating a socket dgram that
52 * will accept datagrams at the <local> address. The @a qos_params
53 * are passed to <ACE_OS::join_leaf>.
55 ACE_SOCK_Dgram (const ACE_Addr
&local
,
58 ACE_Protocol_Info
*protocolinfo
,
63 /// This is a BSD-style method (i.e., no QoS) for initiating a socket
64 /// dgram that will accept datagrams at the <local> address.
65 int open (const ACE_Addr
&local
,
66 int protocol_family
= ACE_PROTOCOL_FAMILY_INET
,
71 * This is a QoS-enabed method for initiating a socket dgram that
72 * will accept datagrams at the <local> address. The @a qos_params
73 * are passed to <ACE_OS::join_leaf>.
75 int open (const ACE_Addr
&local
,
78 ACE_Protocol_Info
*protocolinfo
,
84 ~ACE_SOCK_Dgram (void);
86 // = Data transfer routines.
87 /// Send an @a n byte @a buf to the datagram socket (uses <sendto(3)>).
88 ssize_t
send (const void *buf
,
93 /// Receive an @a n byte @a buf from the datagram socket (uses
95 ssize_t
recv (void *buf
,
101 * Allows a client to read from a socket without having to provide a
102 * buffer to read. This method determines how much data is in the
103 * socket, allocates a buffer of this size, reads in the data, and
104 * returns the number of bytes read. The caller is responsible for
105 * deleting the member in the <iov_base> field of <io_vec> using the
106 * ``delete []'' syntax.
108 ssize_t
recv (iovec
*io_vec
,
111 const ACE_Time_Value
*timeout
= 0) const;
113 /// Send an <iovec> of size @a n to the datagram socket (uses
115 ssize_t
send (const iovec iov
[],
117 const ACE_Addr
&addr
,
118 int flags
= 0) const;
120 /// Recv an <iovec> of size @a n to the datagram socket (uses
122 ssize_t
recv (iovec iov
[],
125 int flags
= 0) const;
128 * Wait up to @a timeout amount of time to receive a datagram into
129 * @a buf. The ACE_Time_Value indicates how long to blocking
130 * trying to receive. If @a timeout == 0, the caller will block
131 * until action is possible, else will wait until the relative time
132 * specified in *@a timeout elapses). If <recv> times out a -1 is
133 * returned with @c errno == ETIME. If it succeeds the number of
134 * bytes received is returned.
136 ssize_t
recv (void *buf
,
140 const ACE_Time_Value
*timeout
) const;
143 * Wait up to @a timeout amount of time to send a datagram to
144 * @a buf. The ACE_Time_Value indicates how long to blocking
145 * trying to receive. If @a timeout == 0, the caller will block
146 * until action is possible, else will wait until the relative time
147 * specified in *@a timeout elapses). If <send> times out a -1 is
148 * returned with @c errno == ETIME. If it succeeds the number of
149 * bytes sent is returned.
151 ssize_t
send (const void *buf
,
153 const ACE_Addr
&addr
,
155 const ACE_Time_Value
*timeout
) const;
157 /// Send <buffer_count> worth of @a buffers to @a addr using overlapped
158 /// I/O (uses <WSASendTo>). Returns 0 on success.
159 ssize_t
send (const iovec buffers
[],
161 size_t &number_of_bytes_sent
,
163 const ACE_Addr
&addr
,
164 ACE_OVERLAPPED
*overlapped
,
165 ACE_OVERLAPPED_COMPLETION_FUNC func
) const;
167 /// Recv <buffer_count> worth of @a buffers from @a addr using
168 /// overlapped I/O (uses <WSARecvFrom>). Returns 0 on success.
169 ssize_t
recv (iovec buffers
[],
171 size_t &number_of_bytes_recvd
,
174 ACE_OVERLAPPED
*overlapped
,
175 ACE_OVERLAPPED_COMPLETION_FUNC func
) const;
177 /// Send an @a n byte @a buf to the datagram socket (uses <WSASendTo>).
178 ssize_t
send (const void *buf
,
180 const ACE_Addr
&addr
,
182 ACE_OVERLAPPED
*overlapped
,
183 ACE_OVERLAPPED_COMPLETION_FUNC func
) const;
185 /// Receive an @a n byte @a buf from the datagram socket (uses
187 ssize_t
recv (void *buf
,
191 ACE_OVERLAPPED
*overlapped
,
192 ACE_OVERLAPPED_COMPLETION_FUNC func
) const;
195 typedef ACE_INET_Addr PEER_ADDR
;
197 /// Dump the state of an object.
198 void dump (void) const;
200 /// Set NIC to use as multicast interface.
201 int set_nic (const ACE_TCHAR
*net_if
,
202 int addr_family
= AF_UNSPEC
);
204 /// Declare the dynamic allocation hooks.
205 ACE_ALLOC_HOOK_DECLARE
;
208 /// Open is shared by this and by <LSOCK_Dgram>.
209 int shared_open (const ACE_Addr
&local
,
210 int protocol_family
);
212 /// Create a multicast addr/if pair, in format useful for system calls.
213 /// If mreq param is NULL, just verify the passed addr/interface specs.
214 int make_multicast_ifaddr (ip_mreq
*mreq
, // Put result here, if != NULL.
215 const ACE_INET_Addr
&mcast_addr
,
216 const ACE_TCHAR
*net_if
);
218 #if defined (ACE_HAS_IPV6)
219 /// Create a multicast addr/if pair, in format useful for system calls.
220 /// If mreq param is NULL, just verify the passed addr/interface specs.
221 int make_multicast_ifaddr6 (ipv6_mreq
*mreq
, // Put result here, if != NULL.
222 const ACE_INET_Addr
&mcast_addr
,
223 const ACE_TCHAR
*net_if
);
225 #endif /* ACE_HAS_IPV6 */
228 /// Do not allow this function to percolate up to this interface...
229 int get_remote_addr (ACE_Addr
&) const;
232 ACE_END_VERSIONED_NAMESPACE_DECL
234 #if defined (__ACE_INLINE__)
235 #include "ace/SOCK_Dgram.inl"
236 #endif /* __ACE_INLINE__ */
238 #include /**/ "ace/post.h"
239 #endif /* ACE_SOCK_DGRAM_H */