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

SSL_Asynch_Stream.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   SSL_Asynch_Stream.h
00006  *
00007  *  $Id: SSL_Asynch_Stream.h,v 1.1.1.2 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Alexander Libman <alibman@baltimore.com>
00010  *
00011  */
00012 //=============================================================================
00013 
00014 #ifndef ACE_SSL_ASYNCH_STREAM_H
00015 #define ACE_SSL_ASYNCH_STREAM_H
00016 
00017 #include "ace/pre.h"
00018 #include "SSL_Context.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 #pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #if OPENSSL_VERSION_NUMBER > 0x0090581fL && ((defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) || (defined (ACE_HAS_AIO_CALLS)))
00025 
00026 #include "ace/Asynch_IO_Impl.h"
00027 #include "ace/Message_Block.h"
00028 
00029 #include "SSL_Asynch_BIO.h"
00030 
00031 extern "C"
00032 {
00033   BIO_METHOD * BIO_s_ACE_Asynch (void);
00034   BIO * BIO_new_ACE_Asynch (void *ssl_asynch_stream);
00035 }
00036 
00037 
00038 /// Forward declarations
00039 class ACE_SSL_Asynch_Stream;
00040 class ACE_SSL_Asynch_Result;
00041 class ACE_SSL_Export ACE_SSL_Asynch_Read_Stream_Result;
00042 class ACE_SSL_Export ACE_SSL_Asynch_Write_Stream_Result;
00043 
00044 
00045 /**
00046  * @class ACE_SSL_Asynch_Stream
00047  *
00048  * @brief This class is a factory for starting off asynchronous reads
00049  * on a stream. This class forwards all methods to its
00050  * implementation class.
00051  * @par
00052  * Once open() is called, multiple asynchronous read()s can
00053  * started using this class.  An ACE_SSL_Asynch_Stream::Result
00054  * will be passed back to the @param handler when the asynchronous
00055  * reads completes through the ACE_Handler::handle_read_stream
00056  * callback.
00057  */
00058 class ACE_SSL_Export ACE_SSL_Asynch_Stream
00059   : public ACE_Asynch_Operation,
00060     public ACE_Service_Handler
00061 {
00062   friend int ACE_Asynch_BIO_read (BIO * pBIO, char * buf, int len);
00063   friend int ACE_Asynch_BIO_write (BIO * pBIO, const char * buf, int len);
00064 
00065 public:
00066 
00067   enum Stream_Type
00068     {
00069       ST_CLIENT = 0x0001,
00070       ST_SERVER = 0x0002
00071     };
00072 
00073 
00074   /// The constructor.
00075   ACE_SSL_Asynch_Stream (Stream_Type s_type = ST_SERVER,
00076                          ACE_SSL_Context * context = 0);
00077 
00078   /// Destructor
00079   virtual ~ACE_SSL_Asynch_Stream (void);
00080 
00081   int cancel(void);
00082 
00083   int close (void);
00084 
00085   int open (ACE_Handler &handler,
00086             ACE_HANDLE handle = ACE_INVALID_HANDLE,
00087             const void *completion_key = 0,
00088             ACE_Proactor *proactor = 0);
00089 
00090   /// NOTE: This method has been specifically put in place so that
00091   /// compilers like the borland doesnt get confused between the above
00092   /// open () call with the one in the ACE_Service_Handler, from which
00093   /// this class is derived from..
00094   void open (ACE_HANDLE new_handle,
00095              ACE_Message_Block &message_block);
00096 
00097   int read (ACE_Message_Block &message_block,
00098             size_t num_bytes_to_read,
00099             const void *act = 0,
00100             int priority = 0,
00101             int signal_number = ACE_SIGRTMIN);
00102 
00103   int write (ACE_Message_Block &message_block,
00104              size_t bytes_to_write,
00105              const void *act = 0,
00106              int priority = 0,
00107              int signal_number = ACE_SIGRTMIN);
00108 
00109 protected:
00110 
00111   /// virtual from ACE_Service_Handler
00112 
00113   /// This method is called when BIO write request is completed. It
00114   /// processes the IO completion and calls do_SSL_state_machine().
00115   virtual void handle_write_stream
00116                (const ACE_Asynch_Write_Stream::Result &result);
00117 
00118   /// This method is called when BIO read request is completed. It
00119   /// processes the IO completion and calls do_SSL_state_machine().
00120   virtual void handle_read_stream
00121                (const ACE_Asynch_Read_Stream::Result &result);
00122 
00123   /// This method is called when all SSL sessions are closed and no
00124   /// more pending AIOs exist.  It also calls users handle_wakeup().
00125   virtual void handle_wakeup (void);
00126 
00127   /**
00128    * @name SSL State Machine
00129    */
00130   //@{
00131   int do_SSL_state_machine (void);
00132   int do_SSL_handshake (void);
00133   int do_SSL_read (void);
00134   int do_SSL_write(void);
00135   int do_SSL_shutdown(void);
00136   //@}
00137 
00138   void print_error (int err_ssl,
00139                     const ACE_TCHAR *pText);
00140 
00141   int pending_BIO_count (void);
00142 
00143   /// This method is called to notify user handler when user's read in
00144   /// done.
00145   int notify_read (int bytes_transferred, int error);
00146 
00147   /// This method is called to notify user handler when user's write
00148   /// in done.
00149   int notify_write (int bytes_transferred, int error);
00150 
00151   /// This method is called to notify ourself that SSL session is
00152   /// shutdown and that there is no more I/O activity now and in the
00153   /// future.
00154   int notify_close(void);
00155 
00156   /**
00157    * @name BIO Helpers
00158    */
00159   //@{
00160   int ssl_bio_read (char * buf, size_t len, int & errval);
00161   int ssl_bio_write (const char * buf, size_t len, int & errval);
00162   //@}
00163 
00164 protected:
00165 
00166   /// Stream Type ST_CLIENT/ST_SERVER
00167   Stream_Type type_;
00168 
00169   /// The real file/socket handle
00170   ACE_HANDLE handle_;
00171 
00172   /// The proactor
00173   ACE_Proactor * proactor_;
00174 
00175   /// External,i.e user  handler
00176   ACE_Handler * ext_handler_;
00177 
00178   /// External, i.e. read result faked for user
00179   ACE_SSL_Asynch_Read_Stream_Result *  ext_read_result_ ;
00180 
00181   /// External, i.e. write result faked for user
00182   ACE_SSL_Asynch_Write_Stream_Result * ext_write_result_ ;
00183 
00184   /// Stream state/flags
00185   enum Stream_Flag
00186     {
00187       SF_STREAM_OPEN    = 0x0001, /// istream_ open OK
00188       SF_REQ_SHUTDOWN   = 0x0002, /// request to SSL shutdown
00189       SF_SHUTDOWN_DONE  = 0x0004, /// SSL shutdown finished
00190       SF_CLOSE_NTF_SENT = 0x0008, /// Close notification sent
00191       SF_DELETE_ENABLE  = 0x0010  /// Stream can be safely destroyed
00192     };
00193 
00194   int flags_;
00195 
00196   /// The SSL session.
00197   SSL * ssl_;
00198 
00199   /// The BIO implementation
00200   BIO * bio_;
00201 
00202   /// The real streams which work under the ssl connection.
00203   /// BIO performs I/O via this streams
00204 
00205   enum BIO_Flag  // internal IO flags
00206     {
00207       BF_EOS   = 0x01,  // end of stream
00208       BF_AIO   = 0x02   // real AIO in progress
00209     };
00210 
00211   /**
00212    * @name Internal stream, buffer and info for BIO read
00213    */
00214   //@{
00215   ACE_Asynch_Read_Stream  bio_istream_;
00216   ACE_Message_Block       bio_inp_msg_;
00217   int                     bio_inp_errno_;
00218   int                     bio_inp_flag_;
00219   //@}
00220 
00221   /**
00222    * @name Internal stream, buffer and info for BIO write
00223    */
00224   //@{
00225   ACE_Asynch_Write_Stream bio_ostream_;
00226   ACE_Message_Block       bio_out_msg_;
00227   int                     bio_out_errno_;
00228   int                     bio_out_flag_;
00229   //@}
00230 
00231   /// Mutex to protect work
00232   ACE_SYNCH_MUTEX mutex_;
00233 
00234 };
00235 
00236 
00237 #endif  /* OPENSSL_VERSION_NUMBER > 0x0090581fL && (ACE_WIN32 ||
00238            ACE_HAS_AIO_CALLS) */
00239 
00240 #include "ace/post.h"
00241 
00242 #endif  /* ACE_SSL_ASYNCH_STREAM_H */

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