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

SSL_SOCK_Connector.h

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

Generated on Mon Jun 16 13:15:55 2003 for ACE_SSL by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002