SOCK_Dgram.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    SOCK_Dgram.h
00006  *
00007  *  SOCK_Dgram.h,v 4.42 2005/10/28 16:14:55 ossama Exp
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_SOCK_DGRAM_H
00014 #define ACE_SOCK_DGRAM_H
00015 #include /**/ "ace/pre.h"
00016 
00017 #include "ace/SOCK.h"
00018 #include "ace/INET_Addr.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #include "ace/Addr.h"
00025 
00026 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00027 
00028 class ACE_Time_Value;
00029 
00030 /**
00031  * @class ACE_SOCK_Dgram
00032  *
00033  * @brief Defines the member functions for the ACE_SOCK datagram
00034  * abstraction.
00035  */
00036 class ACE_Export ACE_SOCK_Dgram : public ACE_SOCK
00037 {
00038 public:
00039   // = Initialization and termination methods.
00040   /// Default constructor.
00041   ACE_SOCK_Dgram (void);
00042 
00043   /// This is a BSD-style method (i.e., no QoS) for initiating a socket
00044   /// dgram that will accept datagrams at the <local> address.
00045   ACE_SOCK_Dgram (const ACE_Addr &local,
00046                   int protocol_family = ACE_PROTOCOL_FAMILY_INET,
00047                   int protocol = 0,
00048                   int reuse_addr = 0);
00049 
00050   /**
00051    * This is a QoS-enabed method for initiating a socket dgram that
00052    * will accept datagrams at the <local> address.  The <qos_params>
00053    * are passed to <ACE_OS::join_leaf>.
00054    */
00055   ACE_SOCK_Dgram (const ACE_Addr &local,
00056                   int protocol_family,
00057                   int protocol,
00058                   ACE_Protocol_Info *protocolinfo,
00059                   ACE_SOCK_GROUP g = 0,
00060                   u_long flags = 0,
00061                   int reuse_addr = 0);
00062 
00063   /// This is a BSD-style method (i.e., no QoS) for initiating a socket
00064   /// dgram that will accept datagrams at the <local> address.
00065   int open (const ACE_Addr &local,
00066             int protocol_family = ACE_PROTOCOL_FAMILY_INET,
00067             int protocol = 0,
00068             int reuse_addr = 0);
00069 
00070   /**
00071    * This is a QoS-enabed method for initiating a socket dgram that
00072    * will accept datagrams at the <local> address.  The <qos_params>
00073    * are passed to <ACE_OS::join_leaf>.
00074    */
00075   int open (const ACE_Addr &local,
00076             int protocol_family,
00077             int protocol,
00078             ACE_Protocol_Info *protocolinfo,
00079             ACE_SOCK_GROUP g = 0,
00080             u_long flags = 0,
00081             int reuse_addr = 0);
00082 
00083   /// Default dtor.
00084   ~ACE_SOCK_Dgram (void);
00085 
00086   // = Data transfer routines.
00087   /// Send an <n> byte <buf> to the datagram socket (uses <sendto(3)>).
00088   ssize_t send (const void *buf,
00089                 size_t n,
00090                 const ACE_Addr &addr,
00091                 int flags = 0) const;
00092 
00093   /// Receive an <n> byte <buf> from the datagram socket (uses
00094   /// <recvfrom(3)>).
00095   ssize_t recv (void *buf,
00096                 size_t n,
00097                 ACE_Addr &addr,
00098                 int flags = 0) const;
00099 
00100   /**
00101    * Allows a client to read from a socket without having to provide a
00102    * buffer to read.  This method determines how much data is in the
00103    * socket, allocates a buffer of this size, reads in the data, and
00104    * returns the number of bytes read.  The caller is responsible for
00105    * deleting the member in the <iov_base> field of <io_vec> using the
00106    * ``delete []'' syntax.
00107    */
00108   ssize_t recv (iovec *io_vec,
00109                 ACE_Addr &addr,
00110                 int flags = 0,
00111                 const ACE_Time_Value *timeout = 0) const;
00112 
00113   /// Send an <iovec> of size <n> to the datagram socket (uses
00114   /// <sendmsg(3)>).
00115   ssize_t send (const iovec iov[],
00116                 int n,
00117                 const ACE_Addr &addr,
00118                 int flags = 0) const;
00119 
00120   /// Recv an <iovec> of size <n> to the datagram socket (uses
00121   /// <recvmsg(3)>).
00122   ssize_t recv (iovec iov[],
00123                 int n,
00124                 ACE_Addr &addr,
00125                 int flags = 0) const;
00126 
00127   /**
00128    * Wait up to <timeout> amount of time to receive a datagram into
00129    * <buf>.  The <ACE_Time_Value> indicates how long to blocking
00130    * trying to receive.  If <timeout> == 0, the caller will block
00131    * until action is possible, else will wait until the relative time
00132    * specified in *<timeout> elapses).  If <recv> times out a -1 is
00133    * returned with <errno == ETIME>.  If it succeeds the number of
00134    * bytes received is returned.
00135    */
00136   ssize_t recv (void *buf,
00137                 size_t n,
00138                 ACE_Addr &addr,
00139                 int flags,
00140                 const ACE_Time_Value *timeout) const;
00141 
00142   /**
00143    * Wait up to <timeout> amount of time to send a datagram to
00144    * <buf>.  The <ACE_Time_Value> indicates how long to blocking
00145    * trying to receive.  If <timeout> == 0, the caller will block
00146    * until action is possible, else will wait until the relative time
00147    * specified in *<timeout> elapses).  If <send> times out a -1 is
00148    * returned with <errno == ETIME>.  If it succeeds the number of
00149    * bytes sent is returned.
00150    */
00151   ssize_t send (const void *buf,
00152                 size_t n,
00153                 const ACE_Addr &addr,
00154                 int flags,
00155                 const ACE_Time_Value *timeout) const;
00156 
00157   /// Send <buffer_count> worth of <buffers> to <addr> using overlapped
00158   /// I/O (uses <WSASendTo>).  Returns 0 on success.
00159   ssize_t send (const iovec buffers[],
00160                 int buffer_count,
00161                 size_t &number_of_bytes_sent,
00162                 int flags,
00163                 const ACE_Addr &addr,
00164                 ACE_OVERLAPPED *overlapped,
00165                 ACE_OVERLAPPED_COMPLETION_FUNC func) const;
00166 
00167   /// Recv <buffer_count> worth of <buffers> from <addr> using
00168   /// overlapped I/O (uses <WSARecvFrom>).  Returns 0 on success.
00169   ssize_t recv (iovec buffers[],
00170                 int buffer_count,
00171                 size_t &number_of_bytes_recvd,
00172                 int &flags,
00173                 ACE_Addr &addr,
00174                 ACE_OVERLAPPED *overlapped,
00175                 ACE_OVERLAPPED_COMPLETION_FUNC func) const;
00176 
00177   /// Send an <n> byte <buf> to the datagram socket (uses <WSASendTo>).
00178   ssize_t send (const void *buf,
00179                 size_t n,
00180                 const ACE_Addr &addr,
00181                 int flags,
00182                 ACE_OVERLAPPED *overlapped,
00183                 ACE_OVERLAPPED_COMPLETION_FUNC func) const;
00184 
00185   /// Receive an <n> byte <buf> from the datagram socket (uses
00186   /// <WSARecvFrom>).
00187   ssize_t recv (void *buf,
00188                 size_t n,
00189                 ACE_Addr &addr,
00190                 int flags,
00191                 ACE_OVERLAPPED *overlapped,
00192                 ACE_OVERLAPPED_COMPLETION_FUNC func) const;
00193 
00194   // = Meta-type info.
00195   typedef ACE_INET_Addr PEER_ADDR;
00196 
00197   /// Dump the state of an object.
00198   void dump (void) const;
00199 
00200   /// Set NIC to use as multicast interface.
00201   int set_nic (const ACE_TCHAR *net_if,
00202                int addr_family = AF_UNSPEC);
00203 
00204   /// Declare the dynamic allocation hooks.
00205   ACE_ALLOC_HOOK_DECLARE;
00206 
00207 protected:
00208   /// Open is shared by this and by <LSOCK_Dgram>.
00209   int shared_open (const ACE_Addr &local,
00210                    int protocol_family);
00211 
00212   /// Create a multicast addr/if pair, in format useful for system calls.
00213   /// If mreq param is NULL, just verify the passed addr/interface specs.
00214   int make_multicast_ifaddr (ip_mreq *mreq,     // Put result here, if != NULL.
00215                              const ACE_INET_Addr &mcast_addr,
00216                              const ACE_TCHAR *net_if);
00217 
00218 #if defined (ACE_HAS_IPV6)
00219   /// Create a multicast addr/if pair, in format useful for system calls.
00220   /// If mreq param is NULL, just verify the passed addr/interface specs.
00221   int make_multicast_ifaddr6 (ipv6_mreq *mreq,   // Put result here, if != NULL.
00222                               const ACE_INET_Addr &mcast_addr,
00223                               const ACE_TCHAR *net_if);
00224 
00225 #endif /* ACE_HAS_IPV6 */
00226 
00227 private:
00228   /// Do not allow this function to percolate up to this interface...
00229   int  get_remote_addr (ACE_Addr &) const;
00230 };
00231 
00232 ACE_END_VERSIONED_NAMESPACE_DECL
00233 
00234 #if defined (__ACE_INLINE__)
00235 #include "ace/SOCK_Dgram.inl"
00236 #endif /* __ACE_INLINE__ */
00237 
00238 #include /**/ "ace/post.h"
00239 #endif /* ACE_SOCK_DGRAM_H */

Generated on Thu Nov 9 09:42:04 2006 for ACE by doxygen 1.3.6