SSL_SOCK_Connector.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    SSL_SOCK_Connector.h
00006  *
00007  *  SSL_SOCK_Connector.h,v 1.26 2005/10/28 16:14:56 ossama Exp
00008  *
00009  *  @author Ossama Othman <ossama@uci.edu>
00010  *  @author Carlos O'Ryan <coryan@uci.edu>
00011  *  @author John Heitmann
00012  *  @author Chris Zimman
00013  */
00014 //=============================================================================
00015 
00016 
00017 #ifndef ACE_SSL_SOCK_CONNECTOR_H
00018 #define ACE_SSL_SOCK_CONNECTOR_H
00019 
00020 #include /**/ "ace/pre.h"
00021 
00022 #include "SSL_Export.h"
00023 
00024 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00025 # pragma once
00026 #endif /* ACE_LACKS_PRAGMA_ONCE */
00027 
00028 #include "SSL_SOCK_Stream.h"
00029 
00030 #include "ace/SOCK_Connector.h"
00031 #include "ace/OS_QoS.h"
00032 
00033 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00034 
00035 /**
00036  * @class ACE_SSL_SOCK_Connector
00037  *
00038  * @brief Defines a factory that creates new <ACE_SSL_SOCK_Stream>s
00039  *        actively.
00040  *
00041  * The ACE_SSL_SOCK_Connector doesn't have a socket of its own,
00042  * i.e., it simply "borrows" the one from the ACE_SSL_SOCK_Stream
00043  * that's being connected.  The reason for this is that the
00044  * underlying socket API doesn't use a "factory" socket to connect
00045  * "data-mode" sockets.  Therefore, there's no need to inherit
00046  * ACE_SSL_SOCK_Connector from ACE_SSL_SOCK.
00047  *
00048  * Since SSL is record-oriented, some additional work is done after
00049  * the plain socket is connected.
00050  *
00051  * @note The user must currently ensure that only one thread services
00052  *       a given SSL session at any given time since some underlying
00053  *       SSL implementations, such as OpenSSL, are not entirely
00054  *       thread-safe or reentrant.
00055  */
00056 class ACE_SSL_Export ACE_SSL_SOCK_Connector
00057 {
00058 
00059 public:
00060 
00061   /// Default constructor.
00062   ACE_SSL_SOCK_Connector (void);
00063 
00064   /**
00065    * Actively connect to a peer, producing a connected @c ACE_SSL_SOCK_Stream
00066    * object if the connection succeeds. This method performs both the
00067    * initial socket connect and the SSL handshake.
00068    *
00069    * @param new_stream  The @c ACE_SSL_SOCK_Stream object that will be
00070    *                    connected to the peer.
00071    * @param remote_sap  The address that we are trying to connect to.
00072    *                    The protocol family of @c remote_sap is used for
00073    *                    the connected socket. That is, if @c remote_sap
00074    *                    contains an IPv6 address, a socket with family
00075    *                    PF_INET6 will be used, else it will be PF_INET.
00076    * @param timeout     Pointer to an @c ACE_Time_Value object with amount
00077    *                    of time to wait to connect. If the pointer is 0
00078    *                    then the call blocks until the connection attempt
00079    *                    is complete, whether it succeeds or fails.  If
00080    *                    *timeout == {0, 0} then the connection is done
00081    *                    using nonblocking mode.  In this case, if the
00082    *                    connection can't be made immediately, this method
00083    *                    returns -1 and errno == EWOULDBLOCK.
00084    *                    If *timeout > {0, 0} then this is the maximum amount
00085    *                    of time to wait before timing out; if the specified
00086    *                    amount of time passes before the connection is made,
00087    *                    this method returns -1 and errno == ETIME. Note
00088    *                    the difference between this case and when a blocking
00089    *                    connect is attmpted that TCP times out - in the latter
00090    *                    case, errno will be ETIMEDOUT.
00091    * @param local_sap   (optional) The local address to bind to.  If it's
00092    *                    the default value of @c ACE_Addr::sap_any then the
00093    *                    OS will choose an unused port.
00094    * @param reuse_addr  (optional) If the value is 1, the local address
00095    *                    (@c local_sap) is reused, even if it hasn't been
00096    *                    cleaned up yet.
00097    * @param flags       Ignored.
00098    * @param perms       Ignored.
00099    *
00100    * @return            Returns 0 if the connection succeeds. If it fails,
00101    *                    -1 is returned and errno contains a specific error
00102    *                    code.
00103    */
00104   ACE_SSL_SOCK_Connector (ACE_SSL_SOCK_Stream &new_stream,
00105                           const ACE_Addr &remote_sap,
00106                           const ACE_Time_Value *timeout = 0,
00107                           const ACE_Addr &local_sap = ACE_Addr::sap_any,
00108                           int reuse_addr = 0,
00109                           int flags = 0,
00110                           int perms = 0);
00111 
00112   /**
00113    * Actively connect to a peer, producing a connected @c ACE_SSL_SOCK_Stream
00114    * object if the connection succeeds. This method performs both the
00115    * initial socket connect and the SSL handshake.
00116    *
00117    * @param new_stream  The @c ACE_SSL_SOCK_Stream object that will be
00118    *                    connected to the peer.
00119    * @param remote_sap  The address that we are trying to connect to.
00120    *                    The protocol family of @c remote_sap is used for
00121    *                    the connected socket. That is, if @c remote_sap
00122    *                    contains an IPv6 address, a socket with family
00123    *                    PF_INET6 will be used, else it will be PF_INET.
00124    * @param qos_params  Contains QoS parameters that are passed to the
00125    *                    IntServ (RSVP) and DiffServ protocols.
00126    *                    @see ACE_QoS_Params.
00127    * @param timeout     Pointer to an @c ACE_Time_Value object with amount
00128    *                    of time to wait to connect. If the pointer is 0
00129    *                    then the call blocks until the connection attempt
00130    *                    is complete, whether it succeeds or fails.  If
00131    *                    *timeout == {0, 0} then the connection is done
00132    *                    using nonblocking mode.  In this case, if the
00133    *                    connection can't be made immediately, this method
00134    *                    returns -1 and errno == EWOULDBLOCK.
00135    *                    If *timeout > {0, 0} then this is the maximum amount
00136    *                    of time to wait before timing out; if the specified
00137    *                    amount of time passes before the connection is made,
00138    *                    this method returns -1 and errno == ETIME. Note
00139    *                    the difference between this case and when a blocking
00140    *                    connect is attmpted that TCP times out - in the latter
00141    *                    case, errno will be ETIMEDOUT.
00142    * @param local_sap   (optional) The local address to bind to.  If it's
00143    *                    the default value of @c ACE_Addr::sap_any then the
00144    *                    OS will choose an unused port.
00145    * @param reuse_addr  (optional) If the value is 1, the local address
00146    *                    (@c local_sap) is reused, even if it hasn't been
00147    *                    cleaned up yet.
00148    * @param flags       Ignored.
00149    * @param perms       Ignored.
00150    *
00151    * @return            Returns 0 if the connection succeeds. If it fails,
00152    *                    -1 is returned and errno contains a specific error
00153    *                    code.
00154    */
00155   ACE_SSL_SOCK_Connector (ACE_SSL_SOCK_Stream &new_stream,
00156                           const ACE_Addr &remote_sap,
00157                           ACE_QoS_Params qos_params,
00158                           const ACE_Time_Value *timeout = 0,
00159                           const ACE_Addr &local_sap = ACE_Addr::sap_any,
00160                           ACE_Protocol_Info *protocolinfo = 0,
00161                           ACE_SOCK_GROUP g = 0,
00162                           u_long flags = 0,
00163                           int reuse_addr = 0,
00164                           int perms = 0);
00165 
00166   /// Default dtor.
00167   ~ACE_SSL_SOCK_Connector (void);
00168 
00169   /**
00170    * Actively connect to a peer, producing a connected @c ACE_SSL_SOCK_Stream
00171    * object if the connection succeeds. This method performs both the
00172    * initial socket connect and the SSL handshake.
00173    *
00174    * @param new_stream  The @c ACE_SSL_SOCK_Stream object that will be
00175    *                    connected to the peer.
00176    * @param remote_sap  The address that we are trying to connect to.
00177    *                    The protocol family of @c remote_sap is used for
00178    *                    the connected socket. That is, if @c remote_sap
00179    *                    contains an IPv6 address, a socket with family
00180    *                    PF_INET6 will be used, else it will be PF_INET.
00181    * @param timeout     Pointer to an @c ACE_Time_Value object with amount
00182    *                    of time to wait to connect. If the pointer is 0
00183    *                    then the call blocks until the connection attempt
00184    *                    is complete, whether it succeeds or fails.  If
00185    *                    *timeout == {0, 0} then the connection is done
00186    *                    using nonblocking mode.  In this case, if the
00187    *                    connection can't be made immediately, this method
00188    *                    returns -1 and errno == EWOULDBLOCK.
00189    *                    If *timeout > {0, 0} then this is the maximum amount
00190    *                    of time to wait before timing out; if the specified
00191    *                    amount of time passes before the connection is made,
00192    *                    this method returns -1 and errno == ETIME. Note
00193    *                    the difference between this case and when a blocking
00194    *                    connect is attmpted that TCP times out - in the latter
00195    *                    case, errno will be ETIMEDOUT.
00196    * @param local_sap   (optional) The local address to bind to.  If it's
00197    *                    the default value of @c ACE_Addr::sap_any then the
00198    *                    OS will choose an unused port.
00199    * @param reuse_addr  (optional) If the value is 1, the local address
00200    *                    (@c local_sap) is reused, even if it hasn't been
00201    *                    cleaned up yet.
00202    * @param flags       Ignored.
00203    * @param perms       Ignored.
00204    *
00205    * @return            Returns 0 if the connection succeeds. If it fails,
00206    *                    -1 is returned and errno contains a specific error
00207    *                    code.
00208    */
00209   int connect (ACE_SSL_SOCK_Stream &new_stream,
00210                const ACE_Addr &remote_sap,
00211                const ACE_Time_Value *timeout = 0,
00212                const ACE_Addr &local_sap = ACE_Addr::sap_any,
00213                int reuse_addr = 0,
00214                int flags = 0,
00215                int perms = 0);
00216 
00217   /**
00218    * Actively connect to a peer, producing a connected @c ACE_SSL_SOCK_Stream
00219    * object if the connection succeeds. This method performs both the
00220    * initial socket connect and the SSL handshake.
00221    *
00222    * @param new_stream  The @c ACE_SSL_SOCK_Stream object that will be
00223    *                    connected to the peer.
00224    * @param remote_sap  The address that we are trying to connect to.
00225    *                    The protocol family of @c remote_sap is used for
00226    *                    the connected socket. That is, if @c remote_sap
00227    *                    contains an IPv6 address, a socket with family
00228    *                    PF_INET6 will be used, else it will be PF_INET.
00229    * @param qos_params  Contains QoS parameters that are passed to the
00230    *                    IntServ (RSVP) and DiffServ protocols.
00231    *                    @see ACE_QoS_Params.
00232    * @param timeout     Pointer to an @c ACE_Time_Value object with amount
00233    *                    of time to wait to connect. If the pointer is 0
00234    *                    then the call blocks until the connection attempt
00235    *                    is complete, whether it succeeds or fails.  If
00236    *                    *timeout == {0, 0} then the connection is done
00237    *                    using nonblocking mode.  In this case, if the
00238    *                    connection can't be made immediately, this method
00239    *                    returns -1 and errno == EWOULDBLOCK.
00240    *                    If *timeout > {0, 0} then this is the maximum amount
00241    *                    of time to wait before timing out; if the specified
00242    *                    amount of time passes before the connection is made,
00243    *                    this method returns -1 and errno == ETIME. Note
00244    *                    the difference between this case and when a blocking
00245    *                    connect is attmpted that TCP times out - in the latter
00246    *                    case, errno will be ETIMEDOUT.
00247    * @param local_sap   (optional) The local address to bind to.  If it's
00248    *                    the default value of @c ACE_Addr::sap_any then the
00249    *                    OS will choose an unused port.
00250    * @param reuse_addr  (optional) If the value is 1, the local address
00251    *                    (@c local_sap) is reused, even if it hasn't been
00252    *                    cleaned up yet.
00253    * @param flags       Ignored.
00254    * @param perms       Ignored.
00255    *
00256    * @return            Returns 0 if the connection succeeds. If it fails,
00257    *                    -1 is returned and errno contains a specific error
00258    *                    code.
00259    */
00260   int connect (ACE_SSL_SOCK_Stream &new_stream,
00261                const ACE_Addr &remote_sap,
00262                ACE_QoS_Params qos_params,
00263                const ACE_Time_Value *timeout = 0,
00264                const ACE_Addr &local_sap = ACE_Addr::sap_any,
00265                ACE_Protocol_Info *protocolinfo = 0,
00266                ACE_SOCK_GROUP g = 0,
00267                u_long flags = 0,
00268                int reuse_addr = 0,
00269                int perms = 0);
00270 
00271   /**
00272    * Try to complete a non-blocking connection.
00273    * If connection completion is successful then <new_stream> contains
00274    * the connected ACE_SSL_SOCK_Stream.  If <remote_sap> is non-NULL
00275    * then it will contain the address of the connected peer.
00276    */
00277   int complete (ACE_SSL_SOCK_Stream &new_stream,
00278                 ACE_Addr *remote_sap = 0,
00279                 const ACE_Time_Value *timeout = 0);
00280 
00281   /// Resets any event associations on this handle
00282   int reset_new_handle (ACE_HANDLE handle);
00283 
00284   /// Meta-type info
00285   //@{
00286   typedef ACE_INET_Addr PEER_ADDR;
00287   typedef ACE_SSL_SOCK_Stream PEER_STREAM;
00288   //@}
00289 
00290   /// Dump the state of an object.
00291   void dump (void) const;
00292 
00293   /// Declare the dynamic allocation hooks.
00294   ACE_ALLOC_HOOK_DECLARE;
00295 
00296 protected:
00297 
00298   /// Complete non-blocking SSL active connection.
00299   int ssl_connect (ACE_SSL_SOCK_Stream &new_stream,
00300                    const ACE_Time_Value *timeout);
00301 
00302 private:
00303 
00304   /// The class that does all of the non-secure socket connection.
00305   /// It is default contructed, and subsequently used by connect().
00306   ACE_SOCK_Connector connector_;
00307 
00308 };
00309 
00310 ACE_END_VERSIONED_NAMESPACE_DECL
00311 
00312 #if defined (__ACE_INLINE__)
00313 #include "SSL_SOCK_Connector.i"
00314 #endif /* __ACE_INLINE__ */
00315 
00316 #include /**/ "ace/post.h"
00317 
00318 #endif /* ACE_SSL_SOCK_CONNECTOR_H */

Generated on Thu Nov 9 11:41:56 2006 for ACE_SSL by doxygen 1.3.6