more handlers
Dependents: bandwidth-meter-net mbedRail24v
Fork of Tiny-HTTPD by
Diff: HTTPD.cpp
- Revision:
- 1:5f009a651656
- Parent:
- 0:d18dff347122
diff -r d18dff347122 -r 5f009a651656 HTTPD.cpp --- a/HTTPD.cpp Wed Nov 13 01:58:04 2013 +0000 +++ b/HTTPD.cpp Sat Feb 01 15:46:26 2014 +0000 @@ -31,7 +31,7 @@ for (i = 0; i < HTTPD_MAX_CLIENTS; i ++) { _state[i].buf = new CircBuffer<char>(HTTPD_BUF_SIZE); - _state[i].thread = new Thread(child, (void*)i, osPriorityNormal, HTTPD_STACK_SIZE); + //_state[i].thread = new Thread(child, (void*)i, osPriorityNormal, HTTPD_STACK_SIZE); _state[i].client = new TCPSocketConnection; } #ifdef HTTPD_ENABLE_CLOSER @@ -41,20 +41,25 @@ _server.bind(port); _server.listen(); - _daemon = new Thread(daemon, NULL, osPriorityNormal, 256); + //_daemon = new Thread(daemon, NULL, osPriorityNormal, 256); return 0; } +void HTTPD::poll () { + HTTPD::daemon(NULL); +} + void HTTPD::daemon (void const *args) { HTTPD *httpd = HTTPD::getInstance(); int i, t = 0; INFO("Wait for new connection...\r\n"); - for (;;) { + //for (;;) { if (t >= 0) { if (httpd->_server.accept(*httpd->_state[t].client) == 0) { INFO("accept %d\r\n", t); - httpd->_state[t].thread->signal_set(1); + //httpd->_state[t].thread->signal_set(1); + httpd->child((void*)t); } } else { #ifdef HTTPD_ENABLE_CLOSER @@ -65,13 +70,16 @@ #endif } + t = 0; + /* t = -1; for (i = 0; i < HTTPD_MAX_CLIENTS; i ++) { if (httpd->_state[i].thread->get_state() == Thread::WaitingAnd) { if (t < 0) t = i; // next empty thread } } - } + */ + //} } void HTTPD::child (void const *arg) { @@ -80,8 +88,8 @@ int i, n; char buf[HTTPD_BUF_SIZE]; - for (;;) { - Thread::signal_wait(1); + //for (;;) { + // Thread::signal_wait(1); httpd->_state[id].mode = MODE_REQUEST; httpd->_state[id].buf->flush(); @@ -103,18 +111,18 @@ httpd->_state[id].client->close(); INFO("Close %s\r\n", httpd->_state[id].client->get_address()); - } + //} } void HTTPD::closer (void const *arg) { HTTPD *httpd = HTTPD::getInstance(); int id = (int)arg; - for (;;) { - Thread::signal_wait(1); + //for (;;) { + // Thread::signal_wait(1); httpd->_state[id].client->close(); INFO("Close %s\r\n", httpd->_state[id].client->get_address()); - } + //} }