]> Git Repo - VerusCoin.git/blobdiff - src/httpserver.h
Catch mined PoS lookalike blocks
[VerusCoin.git] / src / httpserver.h
index 648e8b6f8648c320645d7e6db7d15f24fc259fce..93fb5d8d60dc8fc7a6c190e95a1ae5ec59ef0e39 100644 (file)
 #include <boost/scoped_ptr.hpp>
 #include <boost/function.hpp>
 
+static const int DEFAULT_HTTP_THREADS=4;
+static const int DEFAULT_HTTP_WORKQUEUE=16;
+static const int DEFAULT_HTTP_SERVER_TIMEOUT=30;
+
 struct evhttp_request;
 struct event_base;
 class CService;
 class HTTPRequest;
 
-/** Start HTTP server */
-bool StartHTTPServer(boost::thread_group& threadGroup);
+/** Initialize HTTP server.
+ * Call this before RegisterHTTPHandler or EventBase().
+ */
+bool InitHTTPServer();
+/** Start HTTP server.
+ * This is separate from InitHTTPServer to give users race-condition-free time
+ * to register their handlers between InitHTTPServer and StartHTTPServer.
+ */
+bool StartHTTPServer();
 /** Interrupt HTTP server threads */
 void InterruptHTTPServer();
 /** Stop HTTP server */
@@ -45,11 +56,14 @@ class HTTPRequest
 {
 private:
     struct evhttp_request* req;
+
+    // For test access
+protected:
     bool replySent;
 
 public:
     HTTPRequest(struct evhttp_request* req);
-    ~HTTPRequest();
+    virtual ~HTTPRequest();
 
     enum RequestMethod {
         UNKNOWN,
@@ -65,17 +79,17 @@ public:
 
     /** Get CService (address:ip) for the origin of the http request.
      */
-    CService GetPeer();
+    virtual CService GetPeer();
 
     /** Get request method.
      */
-    RequestMethod GetRequestMethod();
+    virtual RequestMethod GetRequestMethod();
 
     /**
      * Get the request header specified by hdr, or an empty string.
      * Return an pair (isPresent,string).
      */
-    std::pair<bool, std::string> GetHeader(const std::string& hdr);
+    virtual std::pair<bool, std::string> GetHeader(const std::string& hdr);
 
     /**
      * Read request body.
@@ -90,7 +104,7 @@ public:
      *
      * @note call this before calling WriteErrorReply or Reply.
      */
-    void WriteHeader(const std::string& hdr, const std::string& value);
+    virtual void WriteHeader(const std::string& hdr, const std::string& value);
 
     /**
      * Write HTTP reply.
@@ -100,7 +114,7 @@ public:
      * @note Can be called only once. As this will give the request back to the
      * main thread, do not call any other HTTPRequest methods after calling this.
      */
-    void WriteReply(int nStatus, const std::string& strReply = "");
+    virtual void WriteReply(int nStatus, const std::string& strReply = "");
 };
 
 /** Event handler closure.
This page took 0.022409 seconds and 4 git commands to generate.