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

SSL_Asynch_BIO.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 #include "SSL_Asynch_BIO.h"
00004 #include "SSL_Asynch_Stream.h"
00005 
00006 ACE_RCSID (ACE_SSL,
00007            SSL_Asynch_BIO,
00008            "$Id: SSL_Asynch_BIO.cpp,v 1.1.1.1 2001/12/04 14:33:14 chad Exp $")
00009 
00010 #if OPENSSL_VERSION_NUMBER > 0x0090581fL && ((defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) || (defined (ACE_HAS_AIO_CALLS)))
00011 
00012 #define BIO_TYPE_ACE  ( 21 | BIO_TYPE_SOURCE_SINK )
00013 
00014 static BIO_METHOD methods_ACE =
00015   {
00016     BIO_TYPE_ACE, // BIO_TYPE_PROXY_SERVER,
00017     "ACE_Asynch_BIO",
00018     ACE_Asynch_BIO_write,
00019     ACE_Asynch_BIO_read,
00020     ACE_Asynch_BIO_puts,
00021     NULL, /* ACE_Asynch_BIO_gets, */
00022     ACE_Asynch_BIO_ctrl,
00023     ACE_Asynch_BIO_new,
00024     ACE_Asynch_BIO_free,
00025     NULL
00026   };
00027 
00028 BIO_METHOD *
00029 BIO_s_ACE_Asynch (void)
00030 {
00031   return (&methods_ACE);
00032 }
00033 
00034 BIO *
00035 BIO_new_ACE_Asynch (void *ssl_asynch_stream)
00036 {
00037   BIO * pBIO = BIO_new (BIO_s_ACE_Asynch ());
00038 
00039   if (pBIO)
00040     BIO_ctrl (pBIO,
00041               BIO_C_SET_FILE_PTR,
00042               0,
00043               ssl_asynch_stream);
00044 
00045   return pBIO;
00046 }
00047 
00048 int
00049 ACE_Asynch_BIO_new (BIO *pBIO)
00050 {
00051   pBIO->init  = 0;    // not initialized
00052   pBIO->num   = 0;    // still zero ( we can use it )
00053   pBIO->ptr   = 0;    // will be pointer to ACE_SSL_Asynch_Stream
00054   pBIO->flags = 0;    //
00055 
00056   return 1;
00057 }
00058 
00059 int
00060 ACE_Asynch_BIO_free (BIO *pBIO)
00061 {
00062   if (pBIO == 0)
00063     return 0;
00064 
00065   if (pBIO->shutdown)
00066     {
00067       pBIO->ptr   = 0;
00068       pBIO->init  = 0;
00069       pBIO->num   = 0;
00070       pBIO->flags = 0;
00071     }
00072 
00073   return 1;
00074 }
00075 
00076 int
00077 ACE_Asynch_BIO_read (BIO * pBIO, char * buf, int len)
00078 {
00079   BIO_clear_retry_flags (pBIO);
00080 
00081   ACE_SSL_Asynch_Stream * p_stream =
00082     ACE_static_cast (ACE_SSL_Asynch_Stream *, pBIO->ptr);
00083 
00084   if (pBIO->init == 0 || p_stream == 0)
00085     return -1;
00086 
00087   if (buf == 0)
00088     return -1;
00089 
00090   if (len <= 0 )
00091     return -1;
00092 
00093   BIO_clear_retry_flags (pBIO);
00094 
00095   int errval = 0;
00096 
00097   int retval =
00098     p_stream->ssl_bio_read (buf,
00099                             ACE_static_cast (size_t, len),
00100                             errval);
00101 
00102   if (retval >= 0)
00103     return retval;
00104 
00105   if (errval == EINPROGRESS)
00106     BIO_set_retry_read (pBIO);
00107 
00108   return -1;
00109 }
00110 
00111 int
00112 ACE_Asynch_BIO_write (BIO * pBIO, const char * buf, int len)
00113 {
00114   BIO_clear_retry_flags (pBIO);
00115 
00116   ACE_SSL_Asynch_Stream * p_stream =
00117     ACE_static_cast (ACE_SSL_Asynch_Stream *, pBIO->ptr);
00118 
00119   if (pBIO->init == 0 || p_stream == 0)
00120     return -1;
00121 
00122   if (buf == 0)
00123     return -1;
00124 
00125   if (len <= 0)
00126     return -1;
00127 
00128   BIO_clear_retry_flags (pBIO);
00129 
00130   int errval = 0;
00131 
00132   int retval =
00133     p_stream->ssl_bio_write (buf,
00134                              ACE_static_cast (size_t, len),
00135                              errval);
00136 
00137   if (retval >= 0)
00138     return retval;
00139 
00140   if (errval == EINPROGRESS)
00141     BIO_set_retry_write (pBIO);
00142 
00143   return -1;
00144 }
00145 
00146 long
00147 ACE_Asynch_BIO_ctrl (BIO * pBIO, int cmd, long num, void *ptr)
00148 {
00149   long ret = 1;
00150 
00151   switch (cmd)
00152     {
00153     case BIO_C_SET_FILE_PTR:
00154       pBIO->shutdown = ACE_static_cast (int, num);
00155       pBIO->ptr = ptr;
00156       pBIO->init = 1;
00157       break;
00158 
00159     case BIO_CTRL_INFO:
00160       ret = 0;
00161       break;
00162 
00163     case BIO_CTRL_GET_CLOSE:
00164       ret = pBIO->shutdown;
00165       break;
00166 
00167     case BIO_CTRL_SET_CLOSE:
00168       pBIO->shutdown = ACE_static_cast (int, num);
00169       break;
00170 
00171     case BIO_CTRL_PENDING:
00172     case BIO_CTRL_WPENDING:
00173       ret = 0;
00174       break;
00175 
00176     case BIO_CTRL_DUP:
00177     case BIO_CTRL_FLUSH:
00178       ret = 1;
00179       break;
00180 
00181     default:
00182       ret = 0;
00183       break;
00184   }
00185 
00186   return ret;
00187 }
00188 
00189 
00190 int
00191 ACE_Asynch_BIO_puts (BIO *pBIO, const char *str)
00192 {
00193   int n = ACE_OS::strlen (str);
00194 
00195   return ACE_Asynch_BIO_write (pBIO, str, n);
00196 }
00197 
00198 #endif  /* OPENSSL_VERSION_NUMBER > 0x0090581fL && (ACE_WIN32 ||
00199            ACE_HAS_AIO_CALLS) */

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