SOCK_Acceptor.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    SOCK_Acceptor.h
00006  *
00007  *  SOCK_Acceptor.h,v 4.28 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_ACCEPTOR_H
00014 #define ACE_SOCK_ACCEPTOR_H
00015 #include /**/ "ace/pre.h"
00016 
00017 #include "ace/SOCK_Stream.h"
00018 
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 # pragma once
00021 #endif /* ACE_LACKS_PRAGMA_ONCE */
00022 
00023 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00024 
00025 class ACE_Time_Value;
00026 class ACE_Accept_QoS_Params;
00027 
00028 /**
00029  * @class ACE_SOCK_Acceptor
00030  *
00031  * @brief Defines a factory that creates new <ACE_Stream>s passively.
00032  *
00033  * The ACE_SOCK_Acceptor has its own "passive-mode" socket.
00034  * This serves as a factory to create so-called "data-mode"
00035  * sockets, which are what the ACE_SOCK_Stream encapsulates.
00036  * Therefore, by inheriting from ACE_SOCK, ACE_SOCK_Acceptor
00037  * gets its very own socket.
00038  */
00039 class ACE_Export ACE_SOCK_Acceptor : public ACE_SOCK
00040 {
00041 public:
00042   // = Initialization and termination methods.
00043   /// Default constructor.
00044   ACE_SOCK_Acceptor (void);
00045 
00046   /**
00047    * Initialize a passive-mode BSD-style acceptor socket (no QoS).
00048    * @a local_sap is the address that we're going to listen for
00049    * connections on.  If @a reuse_addr is 1 then we'll use the
00050    * @c SO_REUSEADDR to reuse this address.
00051    */
00052   ACE_SOCK_Acceptor (const ACE_Addr &local_sap,
00053                      int reuse_addr = 0,
00054                      int protocol_family = PF_UNSPEC,
00055                      int backlog = ACE_DEFAULT_BACKLOG,
00056                      int protocol = 0);
00057 
00058   /// Initialize a passive-mode QoS-enabled acceptor socket.  Returns 0
00059   /// on success and -1 on failure.
00060   ACE_SOCK_Acceptor (const ACE_Addr &local_sap,
00061                      ACE_Protocol_Info *protocolinfo,
00062                      ACE_SOCK_GROUP g,
00063                      u_long flags,
00064                      int reuse_addr,
00065                      int protocol_family = PF_UNSPEC,
00066                      int backlog = ACE_DEFAULT_BACKLOG,
00067                      int protocol = 0);
00068 
00069   /**
00070    * Initialize a passive-mode BSD-style acceptor socket (no QoS).
00071    * <local_sap> is the address that we're going to listen for
00072    * connections on.  If <reuse_addr> is 1 then we'll use the
00073    * <SO_REUSEADDR> to reuse this address.  Returns 0 on success and
00074    * -1 on failure.
00075    */
00076   int open (const ACE_Addr &local_sap,
00077             int reuse_addr = 0,
00078             int protocol_family = PF_UNSPEC,
00079             int backlog = ACE_DEFAULT_BACKLOG,
00080             int protocol = 0);
00081 
00082   /// Initialize a passive-mode QoS-enabled acceptor socket.  Returns 0
00083   /// on success and -1 on failure.
00084   int open (const ACE_Addr &local_sap,
00085             ACE_Protocol_Info *protocolinfo,
00086             ACE_SOCK_GROUP g,
00087             u_long flags,
00088             int reuse_addr,
00089             int protocol_family = PF_UNSPEC,
00090             int backlog = ACE_DEFAULT_BACKLOG,
00091             int protocol = 0);
00092 
00093   /// Close the socket.  Returns 0 on success and -1 on failure.
00094   int close (void);
00095 
00096   /// Default dtor.
00097   ~ACE_SOCK_Acceptor (void);
00098 
00099   // = Passive connection <accept> methods.
00100   /**
00101    * Accept a new <ACE_SOCK_Stream> connection.  A <timeout> of 0
00102    * means block forever, a <timeout> of {0, 0} means poll.  <restart>
00103    * == 1 means "restart if interrupted," i.e., if errno == EINTR.
00104    * Note that <new_stream> inherits the "blocking mode" of <this>
00105    * <ACE_SOCK_Acceptor>, i.e., if <this> acceptor factory is in
00106    * non-blocking mode, the <net_stream> will be in non-blocking mode
00107    * and vice versa.
00108    */
00109   int accept (ACE_SOCK_Stream &new_stream,
00110               ACE_Addr *remote_addr = 0,
00111               ACE_Time_Value *timeout = 0,
00112               int restart = 1,
00113               int reset_new_handle = 0) const;
00114 
00115 #if !defined (ACE_HAS_WINCE)
00116   /**
00117    * Accept a new <ACE_SOCK_Stream> connection using the QoS
00118    * information in <qos_params>.  A <timeout> of 0 means block
00119    * forever, a <timeout> of {0, 0} means poll.  <restart> == 1 means
00120    * "restart if interrupted," i.e., if errno == EINTR.  Note that
00121    * <new_stream> inherits the "blocking mode" of <this>
00122    * <ACE_SOCK_Acceptor>, i.e., if <this> acceptor factory is in
00123    * non-blocking mode, the <net_stream> will be in non-blocking mode
00124    * and vice versa.
00125    */
00126   int accept (ACE_SOCK_Stream &new_stream,
00127               ACE_Accept_QoS_Params qos_params,
00128               ACE_Addr *remote_addr = 0,
00129               ACE_Time_Value *timeout = 0,
00130               int restart = 1,
00131               int reset_new_handle = 0) const;
00132 #endif  // ACE_HAS_WINCE
00133 
00134   // = Meta-type info
00135   typedef ACE_INET_Addr PEER_ADDR;
00136   typedef ACE_SOCK_Stream PEER_STREAM;
00137 
00138   /// Dump the state of an object.
00139   void dump (void) const;
00140 
00141   /// Declare the dynamic allocation hooks.
00142   ACE_ALLOC_HOOK_DECLARE;
00143 
00144 protected:
00145   /// Perform operations that must occur before <ACE_OS::accept> is
00146   /// called.
00147   int shared_accept_start (ACE_Time_Value *timeout,
00148                            int restart,
00149                            int &in_blocking_mode) const;
00150 
00151   /// Perform operations that must occur after <ACE_OS::accept> is
00152   /// called.
00153   int shared_accept_finish (ACE_SOCK_Stream new_stream,
00154                             int in_blocking_mode,
00155                             int reset_new_handle) const;
00156 
00157   /**
00158    * This method factors out the common <open> code and is called by
00159    * both the QoS-enabled <open> method and the BSD-style <open>
00160    * method.
00161    */
00162   int shared_open (const ACE_Addr &local_sap,
00163                    int protocol_family,
00164                    int backlog);
00165 
00166 private:
00167   /// Do not allow this function to percolate up to this interface...
00168   int get_remote_addr (ACE_Addr &) const;
00169 };
00170 
00171 ACE_END_VERSIONED_NAMESPACE_DECL
00172 
00173 #if defined (__ACE_INLINE__)
00174 #include "ace/SOCK_Acceptor.inl"
00175 #endif /* __ACE_INLINE__ */
00176 
00177 #include /**/ "ace/post.h"
00178 #endif /* ACE_SOCK_ACCEPTOR_H */

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