Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

SOCK_Acceptor.h

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

Generated on Mon Jun 16 11:21:18 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002