Single instance HTTP Server using new Ethernet Interface. Blocking mode only; this improved stability, but the HTTP server must be started from a separate thread.

Dependents:   SmartLight

Fork of HTTPServer by Henry Leinen

Revision:
17:d7186c696729
Parent:
14:011edcd33e86
--- a/HTTPServer.h	Sat Aug 17 16:17:55 2013 +0000
+++ b/HTTPServer.h	Thu May 15 16:09:51 2014 +0000
@@ -91,12 +91,12 @@
 *     HTTPServer svr;
 *     //    Initialize the ethernet interface
 *     if (eth.init() != 0) {
-*         printf("Initialization of EthernetInterface failed !");
+*         printf("Initialization of EthernetInterface failed!");
 *         exit(0);
 *     }
 *     //    Connect using DHCP
 *     if (eth.connect() !=0) {
-*         printf("Failed to connect using DHCP !");
+*         printf("Failed to connect using DHCP!");
 *         exit(0);
 *     }
 *     
@@ -118,8 +118,9 @@
 {
         TCPSocketServer         m_Svr;
         bool                    m_bServerListening;
+        int                     m_port;
         EthernetInterface*      m_pEthernet;
-       
+        
     public:
         /** Constructor for HTTPServer objects.
         */
@@ -163,24 +164,22 @@
         * @param hdlFunc: User specified handler function which will be used in error conditions.
         */
         void addErrorHandler(HTTPRequestHandlerFunction hdlFunc)
-        { m_pErrorHandler = hdlFunc!=NULL ?hdlFunc : StdErrorHandler; }    
+        { m_pErrorHandler = hdlFunc!=NULL ?hdlFunc : StdErrorHandler; }
 
-        /** Binds server to a specific port and starts listening. This member prepares the internal variables and the server socket
-        * and terminates after successfull initialization
+        /** Sets the port on which the HTTP server will listen
         * @param port : port on which to listen for incoming connections
+        */
+        void setPort(int port = 80);
+        
+        /** Sets the port on which the HTTP server will listen
         * @param pEthernet : a pointer to an existing EthernetInterface object or NULL if the HTTPServer shall allocate the object. _Please note that for compatibility reasons
         * your should consider to create the EthernetInterface as a static variable. Otherwise the the object will be created on the heap._
-        * @returns : false if an unrecoverable error occured or if the ethernet interface was not set or not initialized correctly, or true if everything was ok.
         */
-        bool start(int port = 80, EthernetInterface* pEthernet = NULL);
+        void setEthernetInterface(EthernetInterface* pEthernet = NULL);
         
-        /** Performs the regular polling of the server component. Needs to be called cyclically.
-        * The function will internally check whether new connections are requested by a client and will also poll all existing client connections.
-        * @param blocking : if true, 
-        * @returns -1 if there was a problem. If 0 is returned, the latest request was served successfully and the server is
-        * ready for processing the next request. Simply call \c poll as long as you want to serve new incoming requests.
+        /** Starts listening for incoming connections. This method blocks and should be invoked on a separate thread.
         */
-        int poll(bool blocking = true);
+        void start();
         
     private: