00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file SSL_SOCK_Acceptor.h 00006 * 00007 * $Id: SSL_SOCK_Acceptor.h 73790 2006-07-27 20:43:46Z wotte $ 00008 * 00009 * @author John Heitmann 00010 * @author Chris Zimman 00011 * @author Ossama Othman <ossama@uci.edu> 00012 */ 00013 //============================================================================= 00014 00015 00016 #ifndef ACE_SSL_SOCK_ACCEPTOR_H 00017 #define ACE_SSL_SOCK_ACCEPTOR_H 00018 00019 #include /**/ "ace/pre.h" 00020 00021 #include "SSL_Export.h" 00022 00023 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00024 # pragma once 00025 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00026 00027 #include "SSL_SOCK_Stream.h" 00028 00029 #include "ace/SOCK_Acceptor.h" 00030 #include "ace/OS_QoS.h" 00031 00032 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00033 00034 /** 00035 * @class ACE_SSL_SOCK_Acceptor 00036 * 00037 * @brief Defines a factory that creates new @c ACE_SSL_SOCK_Stream 00038 * objects passively. 00039 * 00040 * The ACE_SSL_SOCK_Acceptor has its own @c ACE_SOCK_Acceptor 00041 * which handles the basic socket acceptance. This class is a 00042 * wrapper which adds the SSL acceptance handshake handling. 00043 * Since SSL is record oriented, some additional steps must be taken 00044 * after the basic socket acceptance to complete the SSL handshake that 00045 * takes place at session establishment. 00046 * 00047 * @note The user must currently ensure that only one thread services 00048 * a given SSL session at any given time since some underlying 00049 * SSL implementations, such as OpenSSL, are not entirely 00050 * thread-safe or reentrant. 00051 */ 00052 class ACE_SSL_Export ACE_SSL_SOCK_Acceptor : public ACE_SSL_SOCK 00053 { 00054 public: 00055 00056 /// Default constructor. 00057 ACE_SSL_SOCK_Acceptor (void); 00058 00059 /// Default destructor. 00060 ~ACE_SSL_SOCK_Acceptor (void); 00061 00062 /** 00063 * Initiate a passive mode SSL/BSD-style acceptor socket. 00064 * @param local_sap The address that we're going to listen for 00065 * connections on. If this is @c ACE_Addr::sap_any, 00066 * this socket listens on an the "any" IP address 00067 * and selects an unused port. To find out what port 00068 * was selected, call this object's 00069 * @c ACE_SOCK::get_local_addr(ACE_Addr&) method 00070 * upon return. 00071 */ 00072 ACE_SSL_SOCK_Acceptor (const ACE_Addr &local_sap, 00073 int reuse_addr = 0, 00074 int protocol_family = PF_UNSPEC, 00075 int backlog = ACE_DEFAULT_BACKLOG, 00076 int protocol = 0); 00077 00078 /** 00079 * Initiate a passive-mode QoS-enabled acceptor socket. 00080 * @param local_sap The address that we're going to listen for 00081 * connections on. If this is @c ACE_Addr::sap_any, 00082 * this socket listens on an the "any" IP address 00083 * and selects an unused port. To find out what port 00084 * was selected, call this object's 00085 * @c ACE_SOCK::get_local_addr(ACE_Addr&) method 00086 * upon return. 00087 */ 00088 ACE_SSL_SOCK_Acceptor (const ACE_Addr &local_sap, 00089 ACE_Protocol_Info *protocolinfo, 00090 ACE_SOCK_GROUP g, 00091 u_long flags, 00092 int reuse_addr, 00093 int protocol_family = PF_UNSPEC, 00094 int backlog = ACE_DEFAULT_BACKLOG, 00095 int protocol = 0); 00096 00097 /** 00098 * Initiate a passive mode SSL/BSD-style acceptor socket. 00099 * @param local_sap The address that we're going to listen for 00100 * connections on. If this is @c ACE_Addr::sap_any, 00101 * this socket listens on an the "any" IP address 00102 * and selects an unused port. To find out what port 00103 * was selected, call this object's 00104 * @c ACE_SOCK::get_local_addr(ACE_Addr&) method 00105 * upon return. 00106 * 00107 * @return 0 if success; -1 for failure (errno contains error code). 00108 */ 00109 int open (const ACE_Addr &local_sap, 00110 int reuse_addr = 0, 00111 int protocol_family = PF_UNSPEC, 00112 int backlog = ACE_DEFAULT_BACKLOG, 00113 int protocol = 0); 00114 00115 /// Close the listening socket. 00116 int close (void); 00117 00118 /** 00119 * @name Passive Connection "accept" Methods 00120 * 00121 * These are the canonical methods exposed by the Acceptor pattern. 00122 */ 00123 //@{ 00124 /** 00125 * Accept a new ACE_SSL_SOCK_Stream connection. On successful return, 00126 * the socket has been accepted and the SSL handshake has been completed. 00127 * @param new_stream The @c ACE_SSL_SOCK_Stream object that will receive 00128 * the new SSL socket. 00129 * @param remote_addr Pointer to an @c ACE_INET_Addr object that will 00130 * receive the address of the peer that connected. 00131 * @param timeout The maximum time to wait for the combined socket 00132 * acceptance and handshake completion. 0 means 00133 * block forever, a timeout of {0, 0} means poll. 00134 * @param restart 1 means "restart if interrupted," that is, 00135 * if errno == EINTR. 00136 * 00137 * @return 0 if success; -1 for failure (errno contains error code). 00138 */ 00139 int accept (ACE_SSL_SOCK_Stream &new_stream, 00140 ACE_Addr *remote_addr = 0, 00141 ACE_Time_Value *timeout = 0, 00142 int restart = 1, 00143 int reset_new_handle = 0) const; 00144 00145 /** 00146 * Accept a new ACE_SSL_SOCK_Stream connection using the RVSP QoS 00147 * information in qos_params. 00148 * @param new_stream The @c ACE_SSL_SOCK_Stream object that will receive 00149 * the new SSL socket. 00150 * @param remote_addr Pointer to an @c ACE_INET_Addr object that will 00151 * receive the address of the peer that connected. 00152 * @param timeout The maximum time to wait for the combined socket 00153 * acceptance and handshake completion. 0 means 00154 * block forever, a timeout of {0, 0} means poll. 00155 * @param restart 1 means "restart if interrupted," that is, 00156 * if errno == EINTR. 00157 * 00158 * @return 0 if success; -1 for failure (errno contains error code). 00159 */ 00160 int accept (ACE_SSL_SOCK_Stream &new_stream, 00161 ACE_Accept_QoS_Params qos_params, 00162 ACE_Addr *remote_addr = 0, 00163 ACE_Time_Value *timeout = 0, 00164 int restart = 1, 00165 int reset_new_handle = 0) const; 00166 //@} 00167 00168 /// Meta-type info 00169 //@{ 00170 typedef ACE_INET_Addr PEER_ADDR; 00171 typedef ACE_SSL_SOCK_Stream PEER_STREAM; 00172 //@} 00173 00174 /// Declare the dynamic allocation hooks. 00175 ACE_ALLOC_HOOK_DECLARE; 00176 00177 protected: 00178 00179 /// Complete SSL passive connection establishment. 00180 int ssl_accept (ACE_SSL_SOCK_Stream &new_stream, 00181 ACE_Time_Value *timeout) const; 00182 00183 private: 00184 00185 /// The BSD-socket workhorse 00186 ACE_SOCK_Acceptor acceptor_; 00187 00188 }; 00189 00190 ACE_END_VERSIONED_NAMESPACE_DECL 00191 00192 #if defined (__ACE_INLINE__) 00193 #include "SSL_SOCK_Acceptor.inl" 00194 #endif /* __ACE_INLINE__ */ 00195 00196 #include /**/ "ace/post.h" 00197 00198 #endif /* ACE_SSL_SOCK_ACCEPTOR_H */