sslserversocket.h

Go to the documentation of this file.
00001 #ifndef DV_SSL_SSLSERVERSOCKET_H
00002 #define DV_SSL_SSLSERVERSOCKET_H
00003 
00004 // $Id: sslserversocket.h,v 1.11 2008/03/15 10:42:25 dvermeir Exp $
00005 
00006 #include <stdexcept>
00007 #include <dvssl/sslcontext.h>
00008 #include <dvssl/sslsocket.h>
00009 #include <dvnet/serversocket.h>
00010 
00011 namespace Dv { 
00012   namespace Ssl { 
00013     /** A class derived from Dv::Net::ServerSocket that uses SSL.
00014      * Example usage: 
00015      * @code
00016      * try { 
00017      *   Dv::Ssl::ContextV23 context("key.pem","cert.pem"); 
00018      *   Dv::Ssl::ServerSocket server(context,port); 
00019      *   
00020      *   std::cerr << "SSL echo server started.." << std::endl; 
00021      *   Dv::Util::ref<Dv::Ssl::Socket> client(server.accept()); 
00022      *   
00023      *   std::string line; 
00024      *   while (std::getline(*client, line)) 
00025      *     *client << line << std::endl; 
00026      *   std::cout << "client status: " << client->strerror() << std::endl;
00027      *   return server.error(); 
00028      * }
00029      * catch (std::exception& e) { 
00030      *   std::cerr << e.what() << std::endl;
00031      *   return 2; 
00032      * }
00033      * @endcode
00034      */ 
00035     class ServerSocket: public Dv::Net::ServerSocket { 
00036       public: 
00037         /** Constructor. 
00038          * @param context existing Dv::Ssl::Context object, this parameter must
00039          *   contain both a key file and a certificate file. 
00040          *   Note that the Dv::Ssl::ServerSocket does not own the context object.
00041          * @param port on which connections will be accepted
00042          * @param backlog number of connections allowed in backlog
00043          * @param address local address to bind to, this is useful
00044          *   if e.g. you want the server to listen to a specific
00045          *   network interface, the default (empty string)
00046          *   will bind to the localhost (INADDR_ANY) interface.
00047          * @param min_debug_level if a debug_master is connected, logging info
00048          *   will only be written if the master's level is at least @a min_debug_level
00049          * @param debug_master from where debug info will be taken
00050          * @sa Dv::DebugSlave
00051          * @sa Dv::Net::ServerSocket
00052          */ 
00053         ServerSocket(Context& context, int port, int backlog = 10, std::string address="",
00054             unsigned int min_debug_level = 0, Debugable* debug_master = 0) throw (std::runtime_error); 
00055 
00056         /** Accept a connection from an SSL client.  
00057          * Delay and bufsz are used for the resulting Socket.
00058          * The client Dv::Ssl::Socket will be a Dv::DebugSlave of the same debug_master as the
00059          * Dv::Ssl::ServerSocket.
00060          * @param delay number of millisecs resulting socket will wait for I/O.  
00061          * @param bufsz (input and output) buffer size of streambuf associated with resulting socket 
00062          * @param non_blocking ignored (for compatibility with Dv::Net::ServerSocket::accept)
00063          */ 
00064         shared_ptr<Dv::Net::Socket> accept(time_t delay = 0, size_t bufsz=1024,
00065             bool non_blocking=false);
00066       private: 
00067         Context&        context_; 
00068     }; 
00069   }
00070 }
00071 #endif
00072 

dvssl-0.6.1 [15 March, 2008]