00001 #ifndef DVSSL_SSLBUFFER_H 00002 #define DVSSL_SSLBUFFER_H 00003 // $Id: sslbuffer.h,v 1.7 2008/03/15 10:15:25 dvermeir Exp $ 00004 00005 #include <dvutil/fdstreambuf.h> 00006 #include <dvssl/sslcontext.h> 00007 00008 /** @file 00009 * This file defined Dv::Ssl::Buffer, which is derived from Dv::Ssl::fdstreambuf. 00010 */ 00011 namespace Dv { 00012 namespace Ssl { 00013 /** A streambuf class for use with Dv::Ssl::Socket iostream objects. */ 00014 class Buffer: public Dv::Util::fdstreambuf { 00015 public: 00016 /** Constructor. 00017 * @param context @sa Dv::Ssl::Context 00018 * @param fd underlying filedescriptor 00019 * @param inbufsize size of input buffer 00020 * @param outbufsize size of input buffer 00021 * @param msecs max timeout value in millisecs. 00022 * @param min_debug_level if a debug_master is connected, logging info 00023 * will only be written if the master's level is at least @a min_debug_level 00024 * @param debug_master from where debug info will be taken 00025 * @see Dv::DebugSlave 00026 */ 00027 Buffer(Context& context, int fd, size_t inbufsize=1024, 00028 size_t outbufsize=1024, int msecs = 0, unsigned int min_debug_level = 0, 00029 Debugable* debug_master = 0); 00030 /** Destructor. */ 00031 ~Buffer(); 00032 /** Return pointer to SSL object. 00033 * The return type is declared as @a void* to avoid inclusion of the openssl h 00034 * header files. 00035 * @return (opaque) pointer to SSL object with which this buffer communicates. 00036 */ 00037 void* ssl() const { return ssl_; } 00038 /** Return string representation of cypher. 00039 * @return string representation of cypher used by this buffer. 00040 */ 00041 const char* cipher() const; 00042 /** Wait for input to become available. 00043 * This function is a specialisation of Dv::Util::fdstreambuf::iwait which 00044 * first uses @a SSL_pending to check whether bytes for reading are available in the 00045 * underlying SSL object. Only if this fails does it call Dv::Util::fdstreambuf::iwait. 00046 * @return 1 if input is available 00047 * @return 0 if a timeout occurred 00048 * @return -1 if an error condition exists (e.g. underlying fd not set) 00049 * @sa Dv::Util::fdstreambuf::iwait 00050 */ 00051 int iwait() const; 00052 protected: 00053 /** Raw read implementation. 00054 * @param buf to read into 00055 * @param len number of bytes to read 00056 * @return number of chars read 00057 * @return 0 on EOF 00058 * @return -1 on error 00059 * @sa Dv::Util::fdstreambuf:rread 00060 */ 00061 virtual int rread(char* buf, size_t len); 00062 /** Raw write implementation, see Dv::Util::fdstreambuf. 00063 * @param buf to write from 00064 * @param len number of bytes to write 00065 * @return number of chars written 00066 * @return -1 on error 00067 * @sa Dv::Util::fdstreambuf:rwrite 00068 */ 00069 virtual int rwrite(char* buf, size_t len); 00070 private: 00071 /** Opaque pointer to @a SSL object */ 00072 void *ssl_; 00073 }; 00074 } 00075 } 00076 #endif