Adaptation of the HttpServer by user yueee_yt. This version has improved handling of the HTTP headers (**NOTE**: There are limitations with this implementation and it is not fully functional. Use it only as a starting point.)
Dependents: DMSupport DMSupport DMSupport DMSupport
Fork of DM_HttpServer by
HTTPRequestHandler.cpp@9:10b4d4075fbb, 2015-01-26 (annotated)
- Committer:
- embeddedartists
- Date:
- Mon Jan 26 10:10:46 2015 +0100
- Revision:
- 9:10b4d4075fbb
- Parent:
- 8:5779cee2e94a
- Child:
- 10:c1c8276af541
- Fixed compiler error in LPCXpresso IDE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yueee_yt | 0:fdf9c2c5200f | 1 | /* |
yueee_yt | 0:fdf9c2c5200f | 2 | Permission is hereby granted, free of charge, to any person obtaining a copy |
yueee_yt | 0:fdf9c2c5200f | 3 | of this software and associated documentation files (the "Software"), to deal |
yueee_yt | 0:fdf9c2c5200f | 4 | in the Software without restriction, including without limitation the rights |
yueee_yt | 0:fdf9c2c5200f | 5 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
yueee_yt | 0:fdf9c2c5200f | 6 | copies of the Software, and to permit persons to whom the Software is |
yueee_yt | 0:fdf9c2c5200f | 7 | furnished to do so, subject to the following conditions: |
yueee_yt | 0:fdf9c2c5200f | 8 | |
yueee_yt | 0:fdf9c2c5200f | 9 | The above copyright notice and this permission notice shall be included in |
yueee_yt | 0:fdf9c2c5200f | 10 | all copies or substantial portions of the Software. |
yueee_yt | 0:fdf9c2c5200f | 11 | |
yueee_yt | 0:fdf9c2c5200f | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
yueee_yt | 0:fdf9c2c5200f | 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
yueee_yt | 0:fdf9c2c5200f | 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
yueee_yt | 0:fdf9c2c5200f | 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
yueee_yt | 0:fdf9c2c5200f | 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
yueee_yt | 0:fdf9c2c5200f | 17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
yueee_yt | 0:fdf9c2c5200f | 18 | THE SOFTWARE. |
yueee_yt | 0:fdf9c2c5200f | 19 | */ |
yueee_yt | 4:1b6b021ee21d | 20 | #ifdef _DEBUG_ALL |
yueee_yt | 4:1b6b021ee21d | 21 | #define _DEBUG_REQUEST_HANDLER |
yueee_yt | 4:1b6b021ee21d | 22 | #endif |
yueee_yt | 0:fdf9c2c5200f | 23 | |
yueee_yt | 0:fdf9c2c5200f | 24 | #include "HTTPRequestHandler.h" |
embeddedartists | 6:7b3320c34654 | 25 | #include "DMBoard.h" |
yueee_yt | 0:fdf9c2c5200f | 26 | |
yueee_yt | 0:fdf9c2c5200f | 27 | #include <string.h> |
yueee_yt | 0:fdf9c2c5200f | 28 | |
yueee_yt | 0:fdf9c2c5200f | 29 | #define HTTP_REQUEST_TIMEOUT 5000 |
yueee_yt | 0:fdf9c2c5200f | 30 | |
yueee_yt | 0:fdf9c2c5200f | 31 | //HTTPRequestHandler::HTTPRequestHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket) : NetService(), |
yueee_yt | 0:fdf9c2c5200f | 32 | // m_pTCPSocketConnection(pTCPSocketConnection), m_reqHeaders(), m_respHeaders(), |
yueee_yt | 0:fdf9c2c5200f | 33 | // m_rootPath(rootPath), m_path(path), m_errc(200), |
yueee_yt | 0:fdf9c2c5200f | 34 | // m_watchdog(), m_timeout(0),**/ m_closed(false), m_headersSent(false) //OK |
yueee_yt | 0:fdf9c2c5200f | 35 | HTTPRequestHandler::HTTPRequestHandler(const char* rootPath, const char* path, TCPSocketConnection* pTCPSocketConnection) : |
yueee_yt | 0:fdf9c2c5200f | 36 | m_pTCPSocketConnection(pTCPSocketConnection), m_reqHeaders(), m_respHeaders(), |
yueee_yt | 0:fdf9c2c5200f | 37 | m_rootPath(rootPath), m_path(path), m_errc(200), m_closed(false), m_headersSent(false) |
yueee_yt | 0:fdf9c2c5200f | 38 | { |
yueee_yt | 4:1b6b021ee21d | 39 | #ifdef _DEBUG_REQUEST_HANDLER |
embeddedartists | 6:7b3320c34654 | 40 | DMBoard::instance().logger()->printf("+++(HTTPRequestHandler) init \r\n"); |
yueee_yt | 4:1b6b021ee21d | 41 | #endif |
yueee_yt | 0:fdf9c2c5200f | 42 | //Read & parse headers |
yueee_yt | 0:fdf9c2c5200f | 43 | readHeaders(); |
yueee_yt | 0:fdf9c2c5200f | 44 | //* m_pTCPSocket->setOnEvent(this, &HTTPRequestHandler::onTCPSocketEvent); |
yueee_yt | 0:fdf9c2c5200f | 45 | //* setTimeout(HTTP_REQUEST_TIMEOUT); |
yueee_yt | 4:1b6b021ee21d | 46 | #ifdef _DEBUG_REQUEST_HANDLER |
embeddedartists | 6:7b3320c34654 | 47 | DMBoard::instance().logger()->printf("+++(HTTPRequestHandler) init end \r\n"); |
yueee_yt | 4:1b6b021ee21d | 48 | #endif |
yueee_yt | 0:fdf9c2c5200f | 49 | } |
yueee_yt | 0:fdf9c2c5200f | 50 | |
yueee_yt | 0:fdf9c2c5200f | 51 | HTTPRequestHandler::~HTTPRequestHandler() |
yueee_yt | 0:fdf9c2c5200f | 52 | { |
yueee_yt | 0:fdf9c2c5200f | 53 | close(); |
yueee_yt | 4:1b6b021ee21d | 54 | #ifdef _DEBUG_REQUEST_HANDLER |
embeddedartists | 6:7b3320c34654 | 55 | DMBoard::instance().logger()->printf("+++(HTTPRequestHandler) Destroy end\r\n"); |
yueee_yt | 4:1b6b021ee21d | 56 | #endif |
yueee_yt | 0:fdf9c2c5200f | 57 | } |
yueee_yt | 0:fdf9c2c5200f | 58 | |
yueee_yt | 0:fdf9c2c5200f | 59 | void HTTPRequestHandler::onTimeout() //Connection has timed out |
yueee_yt | 0:fdf9c2c5200f | 60 | { |
yueee_yt | 0:fdf9c2c5200f | 61 | close(); |
yueee_yt | 0:fdf9c2c5200f | 62 | } |
yueee_yt | 0:fdf9c2c5200f | 63 | |
yueee_yt | 0:fdf9c2c5200f | 64 | void HTTPRequestHandler::close() //Close socket and destroy data |
yueee_yt | 0:fdf9c2c5200f | 65 | { |
yueee_yt | 0:fdf9c2c5200f | 66 | if(m_closed) |
yueee_yt | 0:fdf9c2c5200f | 67 | return; |
yueee_yt | 0:fdf9c2c5200f | 68 | m_closed = true; //Prevent recursive calling or calling on an object being destructed by someone else |
yueee_yt | 0:fdf9c2c5200f | 69 | /** m_watchdog.detach(); **/ |
yueee_yt | 0:fdf9c2c5200f | 70 | //* onClose(); |
yueee_yt | 0:fdf9c2c5200f | 71 | //* m_pTCPSocket->resetOnEvent(); |
yueee_yt | 0:fdf9c2c5200f | 72 | //* m_pTCPSocket->close(); |
yueee_yt | 0:fdf9c2c5200f | 73 | //* delete m_pTCPSocket; //Can safely destroy socket |
yueee_yt | 0:fdf9c2c5200f | 74 | //* NetService::close(); |
yueee_yt | 0:fdf9c2c5200f | 75 | } |
yueee_yt | 0:fdf9c2c5200f | 76 | |
yueee_yt | 0:fdf9c2c5200f | 77 | map<string, string>& HTTPRequestHandler::reqHeaders() //const |
yueee_yt | 0:fdf9c2c5200f | 78 | { |
yueee_yt | 0:fdf9c2c5200f | 79 | return m_reqHeaders; |
yueee_yt | 0:fdf9c2c5200f | 80 | } |
yueee_yt | 0:fdf9c2c5200f | 81 | |
yueee_yt | 0:fdf9c2c5200f | 82 | string& HTTPRequestHandler::path() //const |
yueee_yt | 0:fdf9c2c5200f | 83 | { |
yueee_yt | 0:fdf9c2c5200f | 84 | return m_path; |
yueee_yt | 0:fdf9c2c5200f | 85 | } |
yueee_yt | 0:fdf9c2c5200f | 86 | |
yueee_yt | 0:fdf9c2c5200f | 87 | int HTTPRequestHandler::dataLen() const |
yueee_yt | 0:fdf9c2c5200f | 88 | { |
embeddedartists | 9:10b4d4075fbb | 89 | map<string,string>::const_iterator it; |
yueee_yt | 0:fdf9c2c5200f | 90 | it = m_reqHeaders.find("Content-Length"); |
yueee_yt | 0:fdf9c2c5200f | 91 | if( it == m_reqHeaders.end() ) { |
yueee_yt | 0:fdf9c2c5200f | 92 | return 0; |
yueee_yt | 0:fdf9c2c5200f | 93 | } |
yueee_yt | 0:fdf9c2c5200f | 94 | return atoi((*it).second.c_str()); //return 0 if parse fails, so that's fine |
yueee_yt | 0:fdf9c2c5200f | 95 | } |
yueee_yt | 0:fdf9c2c5200f | 96 | |
yueee_yt | 0:fdf9c2c5200f | 97 | int HTTPRequestHandler::readData(char* buf, int len) |
yueee_yt | 0:fdf9c2c5200f | 98 | { |
yueee_yt | 0:fdf9c2c5200f | 99 | return m_pTCPSocketConnection->receive(buf, len); |
yueee_yt | 0:fdf9c2c5200f | 100 | } |
yueee_yt | 0:fdf9c2c5200f | 101 | |
yueee_yt | 0:fdf9c2c5200f | 102 | string& HTTPRequestHandler::rootPath() //const |
yueee_yt | 0:fdf9c2c5200f | 103 | { |
yueee_yt | 0:fdf9c2c5200f | 104 | return m_rootPath; |
yueee_yt | 0:fdf9c2c5200f | 105 | } |
yueee_yt | 0:fdf9c2c5200f | 106 | |
yueee_yt | 0:fdf9c2c5200f | 107 | void HTTPRequestHandler::setErrCode(int errc) |
yueee_yt | 0:fdf9c2c5200f | 108 | { |
yueee_yt | 0:fdf9c2c5200f | 109 | m_errc = errc; |
yueee_yt | 0:fdf9c2c5200f | 110 | } |
yueee_yt | 0:fdf9c2c5200f | 111 | |
yueee_yt | 0:fdf9c2c5200f | 112 | void HTTPRequestHandler::setContentLen(int len) |
yueee_yt | 0:fdf9c2c5200f | 113 | { |
yueee_yt | 0:fdf9c2c5200f | 114 | char len_str[6] = {0}; |
embeddedartists | 6:7b3320c34654 | 115 | snprintf(len_str, 6, "%d", len); |
yueee_yt | 0:fdf9c2c5200f | 116 | respHeaders()["Content-Length"] = len_str; |
yueee_yt | 0:fdf9c2c5200f | 117 | } |
yueee_yt | 0:fdf9c2c5200f | 118 | |
yueee_yt | 0:fdf9c2c5200f | 119 | map<string, string>& HTTPRequestHandler::respHeaders() |
yueee_yt | 0:fdf9c2c5200f | 120 | { |
yueee_yt | 0:fdf9c2c5200f | 121 | return m_respHeaders; |
yueee_yt | 0:fdf9c2c5200f | 122 | } |
yueee_yt | 0:fdf9c2c5200f | 123 | |
yueee_yt | 0:fdf9c2c5200f | 124 | int HTTPRequestHandler::writeData(const char* buf, int len) |
yueee_yt | 0:fdf9c2c5200f | 125 | { |
yueee_yt | 0:fdf9c2c5200f | 126 | if(!m_headersSent) { |
yueee_yt | 0:fdf9c2c5200f | 127 | m_headersSent = true; |
yueee_yt | 0:fdf9c2c5200f | 128 | writeHeaders(); |
yueee_yt | 0:fdf9c2c5200f | 129 | } |
yueee_yt | 0:fdf9c2c5200f | 130 | return m_pTCPSocketConnection->send((char *)buf, len); |
yueee_yt | 0:fdf9c2c5200f | 131 | } |
yueee_yt | 0:fdf9c2c5200f | 132 | /** |
yueee_yt | 0:fdf9c2c5200f | 133 | void HTTPRequestHandler::setTimeout(int ms) |
yueee_yt | 0:fdf9c2c5200f | 134 | { |
yueee_yt | 0:fdf9c2c5200f | 135 | m_timeout = 1000*ms; |
yueee_yt | 0:fdf9c2c5200f | 136 | resetTimeout(); |
yueee_yt | 0:fdf9c2c5200f | 137 | } |
yueee_yt | 0:fdf9c2c5200f | 138 | **/ |
yueee_yt | 0:fdf9c2c5200f | 139 | /** |
yueee_yt | 0:fdf9c2c5200f | 140 | void HTTPRequestHandler::resetTimeout() |
yueee_yt | 0:fdf9c2c5200f | 141 | { |
yueee_yt | 0:fdf9c2c5200f | 142 | m_watchdog.detach(); |
yueee_yt | 0:fdf9c2c5200f | 143 | m_watchdog.attach_us<HTTPRequestHandler>(this, &HTTPRequestHandler::onTimeout, m_timeout); |
yueee_yt | 0:fdf9c2c5200f | 144 | } |
yueee_yt | 0:fdf9c2c5200f | 145 | **/ |
yueee_yt | 0:fdf9c2c5200f | 146 | |
yueee_yt | 0:fdf9c2c5200f | 147 | void HTTPRequestHandler::readHeaders() |
yueee_yt | 0:fdf9c2c5200f | 148 | { |
yueee_yt | 0:fdf9c2c5200f | 149 | static char line[128]; |
yueee_yt | 0:fdf9c2c5200f | 150 | static char key[128]; |
yueee_yt | 0:fdf9c2c5200f | 151 | static char value[128]; |
embeddedartists | 8:5779cee2e94a | 152 | |
embeddedartists | 8:5779cee2e94a | 153 | // Prepare cache |
embeddedartists | 8:5779cee2e94a | 154 | read_cache_t* cache = (read_cache_t*)malloc(sizeof(read_cache_t)); |
embeddedartists | 8:5779cee2e94a | 155 | cache->size = 1024; |
embeddedartists | 8:5779cee2e94a | 156 | cache->num = cache->pos = 0; |
embeddedartists | 8:5779cee2e94a | 157 | |
embeddedartists | 8:5779cee2e94a | 158 | while( readLineCached(line, 128, cache) > 0) { //if == 0, it is an empty line = end of headers |
yueee_yt | 0:fdf9c2c5200f | 159 | int n = sscanf(line, "%[^:]: %[^\n]", key, value); |
yueee_yt | 0:fdf9c2c5200f | 160 | if ( n == 2 ) { |
yueee_yt | 4:1b6b021ee21d | 161 | #ifdef _DEBUG_REQUEST_HANDLER |
embeddedartists | 6:7b3320c34654 | 162 | DMBoard::instance().logger()->printf("\r\n+++(HTTPRequestHandler)Read header : %s : %s\r\n", key, value); |
yueee_yt | 4:1b6b021ee21d | 163 | #endif |
yueee_yt | 0:fdf9c2c5200f | 164 | m_reqHeaders[key] = value; |
yueee_yt | 0:fdf9c2c5200f | 165 | } |
yueee_yt | 0:fdf9c2c5200f | 166 | //TODO: Impl n==1 case (part 2 of previous header) |
yueee_yt | 0:fdf9c2c5200f | 167 | } |
embeddedartists | 8:5779cee2e94a | 168 | free(cache); |
yueee_yt | 0:fdf9c2c5200f | 169 | } |
yueee_yt | 0:fdf9c2c5200f | 170 | |
yueee_yt | 0:fdf9c2c5200f | 171 | void HTTPRequestHandler::writeHeaders() //Called at the first writeData call |
yueee_yt | 0:fdf9c2c5200f | 172 | { |
yueee_yt | 0:fdf9c2c5200f | 173 | static char line[128]; |
yueee_yt | 0:fdf9c2c5200f | 174 | |
yueee_yt | 0:fdf9c2c5200f | 175 | //Response line |
embeddedartists | 6:7b3320c34654 | 176 | snprintf(line, 128, "HTTP/1.1 %d MbedInfo\r\n", m_errc); //Not a violation of the standard not to include the descriptive text |
yueee_yt | 0:fdf9c2c5200f | 177 | m_pTCPSocketConnection->send(line, strlen(line)); |
yueee_yt | 0:fdf9c2c5200f | 178 | |
yueee_yt | 0:fdf9c2c5200f | 179 | map<string,string>::iterator it; |
yueee_yt | 0:fdf9c2c5200f | 180 | while( !m_respHeaders.empty() ) { |
yueee_yt | 0:fdf9c2c5200f | 181 | it = m_respHeaders.begin(); |
embeddedartists | 6:7b3320c34654 | 182 | snprintf(line, 128, "%s: %s\r\n", (*it).first.c_str(), (*it).second.c_str() ); |
yueee_yt | 4:1b6b021ee21d | 183 | #ifdef _DEBUG_REQUEST_HANDLER |
embeddedartists | 6:7b3320c34654 | 184 | DMBoard::instance().logger()->printf("\r\n+++(HTTPRequestHandler)%s", line); |
yueee_yt | 4:1b6b021ee21d | 185 | #endif |
yueee_yt | 0:fdf9c2c5200f | 186 | m_pTCPSocketConnection->send(line, strlen(line)); |
yueee_yt | 0:fdf9c2c5200f | 187 | m_respHeaders.erase(it); |
yueee_yt | 0:fdf9c2c5200f | 188 | } |
yueee_yt | 0:fdf9c2c5200f | 189 | m_pTCPSocketConnection->send("\r\n",2); //End of head |
yueee_yt | 0:fdf9c2c5200f | 190 | } |
yueee_yt | 0:fdf9c2c5200f | 191 | |
yueee_yt | 0:fdf9c2c5200f | 192 | int HTTPRequestHandler::readLine(char* str, int maxLen) |
yueee_yt | 0:fdf9c2c5200f | 193 | { |
yueee_yt | 0:fdf9c2c5200f | 194 | int ret; |
yueee_yt | 0:fdf9c2c5200f | 195 | int len = 0; |
yueee_yt | 0:fdf9c2c5200f | 196 | for(int i = 0; i < maxLen - 1; i++) { |
yueee_yt | 0:fdf9c2c5200f | 197 | ret = m_pTCPSocketConnection->receive(str, 1); |
yueee_yt | 0:fdf9c2c5200f | 198 | if(!ret) { |
yueee_yt | 0:fdf9c2c5200f | 199 | break; |
yueee_yt | 0:fdf9c2c5200f | 200 | } |
yueee_yt | 0:fdf9c2c5200f | 201 | if( (len > 1) && *(str-1)=='\r' && *str=='\n' ) { |
yueee_yt | 0:fdf9c2c5200f | 202 | str--; |
yueee_yt | 0:fdf9c2c5200f | 203 | len-=2; |
yueee_yt | 0:fdf9c2c5200f | 204 | break; |
yueee_yt | 0:fdf9c2c5200f | 205 | } else if( *str=='\n' ) { |
yueee_yt | 0:fdf9c2c5200f | 206 | len--; |
yueee_yt | 0:fdf9c2c5200f | 207 | break; |
yueee_yt | 0:fdf9c2c5200f | 208 | } |
yueee_yt | 0:fdf9c2c5200f | 209 | str++; |
yueee_yt | 0:fdf9c2c5200f | 210 | len++; |
yueee_yt | 0:fdf9c2c5200f | 211 | } |
yueee_yt | 0:fdf9c2c5200f | 212 | *str = 0; |
yueee_yt | 0:fdf9c2c5200f | 213 | return len; |
yueee_yt | 0:fdf9c2c5200f | 214 | } |
embeddedartists | 8:5779cee2e94a | 215 | |
embeddedartists | 8:5779cee2e94a | 216 | |
embeddedartists | 8:5779cee2e94a | 217 | int HTTPRequestHandler::readLineCached(char* str, int maxLen, read_cache_t* cache) |
embeddedartists | 8:5779cee2e94a | 218 | { |
embeddedartists | 8:5779cee2e94a | 219 | maxLen--; // leave room for null termination |
embeddedartists | 8:5779cee2e94a | 220 | |
embeddedartists | 8:5779cee2e94a | 221 | int len = 0; |
embeddedartists | 8:5779cee2e94a | 222 | int i = 0; |
embeddedartists | 8:5779cee2e94a | 223 | bool found = false; |
embeddedartists | 8:5779cee2e94a | 224 | while (i < maxLen && !found) { |
embeddedartists | 8:5779cee2e94a | 225 | if (cache->num <= cache->pos) { |
embeddedartists | 8:5779cee2e94a | 226 | // get something to process |
embeddedartists | 8:5779cee2e94a | 227 | int ret = m_pTCPSocketConnection->receive(cache->buff, cache->size); |
embeddedartists | 8:5779cee2e94a | 228 | if(ret == -1) { |
embeddedartists | 8:5779cee2e94a | 229 | // error |
embeddedartists | 8:5779cee2e94a | 230 | break; |
embeddedartists | 8:5779cee2e94a | 231 | } else if (ret == 0) { |
embeddedartists | 8:5779cee2e94a | 232 | // didn't get anything to process, try again |
embeddedartists | 8:5779cee2e94a | 233 | continue; |
embeddedartists | 8:5779cee2e94a | 234 | } |
embeddedartists | 8:5779cee2e94a | 235 | cache->num = ret; |
embeddedartists | 8:5779cee2e94a | 236 | cache->pos = 0; |
embeddedartists | 8:5779cee2e94a | 237 | } |
embeddedartists | 8:5779cee2e94a | 238 | |
embeddedartists | 8:5779cee2e94a | 239 | // have >0 bytes to process |
embeddedartists | 8:5779cee2e94a | 240 | while ((cache->pos < cache->num) && (i < maxLen)) { |
embeddedartists | 8:5779cee2e94a | 241 | *str = cache->buff[cache->pos++]; |
embeddedartists | 8:5779cee2e94a | 242 | if( (len > 1) && *(str-1)=='\r' && *str=='\n' ) { |
embeddedartists | 8:5779cee2e94a | 243 | str--; |
embeddedartists | 8:5779cee2e94a | 244 | len-=2; |
embeddedartists | 8:5779cee2e94a | 245 | found = true; |
embeddedartists | 8:5779cee2e94a | 246 | break; |
embeddedartists | 8:5779cee2e94a | 247 | } else if( *str=='\n' ) { |
embeddedartists | 8:5779cee2e94a | 248 | len--; |
embeddedartists | 8:5779cee2e94a | 249 | found = true; |
embeddedartists | 8:5779cee2e94a | 250 | break; |
embeddedartists | 8:5779cee2e94a | 251 | } |
embeddedartists | 8:5779cee2e94a | 252 | str++; |
embeddedartists | 8:5779cee2e94a | 253 | len++; |
embeddedartists | 8:5779cee2e94a | 254 | } |
embeddedartists | 8:5779cee2e94a | 255 | } |
embeddedartists | 8:5779cee2e94a | 256 | *str = 0; |
embeddedartists | 8:5779cee2e94a | 257 | return len; |
embeddedartists | 8:5779cee2e94a | 258 | } |
embeddedartists | 8:5779cee2e94a | 259 | |
yueee_yt | 0:fdf9c2c5200f | 260 | /** |
yueee_yt | 0:fdf9c2c5200f | 261 | void HTTPRequestHandler::onTCPSocketEvent(TCPSocketEvent e) |
yueee_yt | 0:fdf9c2c5200f | 262 | { |
yueee_yt | 0:fdf9c2c5200f | 263 | //printf("\r\nEvent %d in HTTPRequestHandler\r\n", e); |
yueee_yt | 0:fdf9c2c5200f | 264 | printf("\r\n+++(HTTPRequestHandler)Event in HTTPRequestHandler\r\n"); |
yueee_yt | 0:fdf9c2c5200f | 265 | |
yueee_yt | 0:fdf9c2c5200f | 266 | if(m_closed) |
yueee_yt | 0:fdf9c2c5200f | 267 | { |
yueee_yt | 0:fdf9c2c5200f | 268 | printf("\r\n+++(HTTPRequestHandler)WARN: Discarded\r\n"); |
yueee_yt | 0:fdf9c2c5200f | 269 | return; |
yueee_yt | 0:fdf9c2c5200f | 270 | } |
yueee_yt | 0:fdf9c2c5200f | 271 | |
yueee_yt | 0:fdf9c2c5200f | 272 | switch(e) |
yueee_yt | 0:fdf9c2c5200f | 273 | { |
yueee_yt | 0:fdf9c2c5200f | 274 | case TCPSOCKET_READABLE: |
yueee_yt | 0:fdf9c2c5200f | 275 | resetTimeout(); |
yueee_yt | 0:fdf9c2c5200f | 276 | onReadable(); |
yueee_yt | 0:fdf9c2c5200f | 277 | break; |
yueee_yt | 0:fdf9c2c5200f | 278 | case TCPSOCKET_WRITEABLE: |
yueee_yt | 0:fdf9c2c5200f | 279 | resetTimeout(); |
yueee_yt | 0:fdf9c2c5200f | 280 | onWriteable(); |
yueee_yt | 0:fdf9c2c5200f | 281 | break; |
yueee_yt | 0:fdf9c2c5200f | 282 | case TCPSOCKET_CONTIMEOUT: |
yueee_yt | 0:fdf9c2c5200f | 283 | case TCPSOCKET_CONRST: |
yueee_yt | 0:fdf9c2c5200f | 284 | case TCPSOCKET_CONABRT: |
yueee_yt | 0:fdf9c2c5200f | 285 | case TCPSOCKET_ERROR: |
yueee_yt | 0:fdf9c2c5200f | 286 | case TCPSOCKET_DISCONNECTED: |
yueee_yt | 0:fdf9c2c5200f | 287 | DBG("\r\nConnection error in handler\r\n"); |
yueee_yt | 0:fdf9c2c5200f | 288 | close(); |
yueee_yt | 0:fdf9c2c5200f | 289 | break; |
yueee_yt | 0:fdf9c2c5200f | 290 | } |
yueee_yt | 0:fdf9c2c5200f | 291 | } |
embeddedartists | 6:7b3320c34654 | 292 | **/ |