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