Loading examples/httpsysinfo.cpp +21 −7 Changes for examples/httpsysinfo.cpp: 21 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -222,10 +222,22 @@ public: }else if(curreq.getRequestURL()=="/images/header.png"){ curres.setContentType("image/png"); curres.setContentLength(header_png_size); /* Streaming an image body across multiple ResponseEvent * calls needs its own "bytes of the source buffer queued * so far" counter. SendData.pos belongs to the transport * (it tracks bytes already handed to the socket) and is * reset to 0 by it every time SendData drains -- reusing * it here would make freshly appended-but-unsent bytes * look already sent and they would never go out. Keep our * own counter in the per-connection extension slot instead. */ curreq.extension = std::unique_ptr<void, void(*)(void*)>( new size_t(0), +[](void *p){ delete static_cast<size_t*>(p); }); curres.send(curreq,"", -1); }else if(curreq.getRequestURL()=="/favicon.ico"){ curres.setContentType("image/x-icon"); curres.setContentLength(favicon_ico_size); curreq.extension = std::unique_ptr<void, void(*)(void*)>( new size_t(0), +[](void *p){ delete static_cast<size_t*>(p); }); curres.send(curreq,"", -1); }else{ curres.setState(HTTP404); Loading @@ -249,16 +261,18 @@ public: } void ResponseEvent(libhttppp::HttpRequest& curreq, const int /*tid*/,ULONG_PTR /*args*/){ size_t *sent = static_cast<size_t*>(curreq.extension.get()); if (!sent) return; if (curreq.getRequestURL()=="/images/header.png") { size_t rem = header_png_size - curreq.SendData.pos; size_t rem = header_png_size - *sent; size_t si = (rem > CHUNKSIZE) ? CHUNKSIZE : rem; curreq.SendData.append((const char*)header_png + curreq.SendData.pos, si); curreq.SendData.pos += si; curreq.SendData.append((const char*)header_png + *sent, si); *sent += si; } else if(curreq.getRequestURL()=="/favicon.ico"){ if(curreq.SendData.pos < favicon_ico_size){ size_t si = CHUNKSIZE < (favicon_ico_size-curreq.SendData.pos) ? CHUNKSIZE : (favicon_ico_size-curreq.SendData.pos); curreq.SendData.append((const char*)favicon_ico+curreq.SendData.pos, si); curreq.SendData.pos+=si; if(*sent < favicon_ico_size){ size_t si = CHUNKSIZE < (favicon_ico_size-*sent) ? CHUNKSIZE : (favicon_ico_size-*sent); curreq.SendData.append((const char*)favicon_ico+*sent, si); *sent+=si; } } } Loading Loading
examples/httpsysinfo.cpp +21 −7 Changes for examples/httpsysinfo.cpp: 21 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -222,10 +222,22 @@ public: }else if(curreq.getRequestURL()=="/images/header.png"){ curres.setContentType("image/png"); curres.setContentLength(header_png_size); /* Streaming an image body across multiple ResponseEvent * calls needs its own "bytes of the source buffer queued * so far" counter. SendData.pos belongs to the transport * (it tracks bytes already handed to the socket) and is * reset to 0 by it every time SendData drains -- reusing * it here would make freshly appended-but-unsent bytes * look already sent and they would never go out. Keep our * own counter in the per-connection extension slot instead. */ curreq.extension = std::unique_ptr<void, void(*)(void*)>( new size_t(0), +[](void *p){ delete static_cast<size_t*>(p); }); curres.send(curreq,"", -1); }else if(curreq.getRequestURL()=="/favicon.ico"){ curres.setContentType("image/x-icon"); curres.setContentLength(favicon_ico_size); curreq.extension = std::unique_ptr<void, void(*)(void*)>( new size_t(0), +[](void *p){ delete static_cast<size_t*>(p); }); curres.send(curreq,"", -1); }else{ curres.setState(HTTP404); Loading @@ -249,16 +261,18 @@ public: } void ResponseEvent(libhttppp::HttpRequest& curreq, const int /*tid*/,ULONG_PTR /*args*/){ size_t *sent = static_cast<size_t*>(curreq.extension.get()); if (!sent) return; if (curreq.getRequestURL()=="/images/header.png") { size_t rem = header_png_size - curreq.SendData.pos; size_t rem = header_png_size - *sent; size_t si = (rem > CHUNKSIZE) ? CHUNKSIZE : rem; curreq.SendData.append((const char*)header_png + curreq.SendData.pos, si); curreq.SendData.pos += si; curreq.SendData.append((const char*)header_png + *sent, si); *sent += si; } else if(curreq.getRequestURL()=="/favicon.ico"){ if(curreq.SendData.pos < favicon_ico_size){ size_t si = CHUNKSIZE < (favicon_ico_size-curreq.SendData.pos) ? CHUNKSIZE : (favicon_ico_size-curreq.SendData.pos); curreq.SendData.append((const char*)favicon_ico+curreq.SendData.pos, si); curreq.SendData.pos+=si; if(*sent < favicon_ico_size){ size_t si = CHUNKSIZE < (favicon_ico_size-*sent) ? CHUNKSIZE : (favicon_ico_size-*sent); curreq.SendData.append((const char*)favicon_ico+*sent, si); *sent+=si; } } } Loading