Commit 2a513bef authored by jan.koester's avatar jan.koester
Browse files

test

parent ce819512
Loading
Loading
Loading
Loading
+18 −9
Original line number Diff line number Diff line
@@ -403,7 +403,11 @@ bool blogi::Theme::Controller(const int tid,libhttppp::HttpRequest &req){
                resp.send(req,"",-1);
            }

            req.SendData.pos=0; // Reset position for streaming in the Response function
            // Store streaming state in per-connection extension
            // (SendData.pos is managed by the epoll send loop — using it
            //  as a source-read cursor prevents EPOLLOUT from being armed)
            struct ThemeStreamState { size_t srcPos = 0; };
            req.extension = {new ThemeStreamState{}, +[](void* p){ delete static_cast<ThemeStreamState*>(p); }};
            return true;
    }
}
@@ -449,21 +453,26 @@ bool blogi::Theme::Response(const int tid, libhttppp::HttpRequest &req){
        }
    }

    // Retrieve per-connection streaming state (set up in Controller)
    struct ThemeStreamState { size_t srcPos = 0; };
    auto* state = static_cast<ThemeStreamState*>(req.extension.get());
    if (!state) return false;

    // Stream data using direct pointer access instead of substr copies
    if( curfile.Compressed.length() > 0 && acpt_bz){
        if(req.SendData.pos < curfile.Compressed.length()){
            size_t remaining = curfile.Compressed.length() - req.SendData.pos;
        if(state->srcPos < curfile.Compressed.length()){
            size_t remaining = curfile.Compressed.length() - state->srcPos;
            size_t len = BLOCKSIZE < remaining ? BLOCKSIZE : remaining;
            req.SendData.append(curfile.Compressed.c_str() + req.SendData.pos, len);
            req.SendData.pos += len;
            req.SendData.append(curfile.Compressed.c_str() + state->srcPos, len);
            state->srcPos += len;
            return true;
        }
    }else{
        if(req.SendData.pos < curfile.Content.length()){
            size_t remaining = curfile.Content.length() - req.SendData.pos;
        if(state->srcPos < curfile.Content.length()){
            size_t remaining = curfile.Content.length() - state->srcPos;
            size_t len = BLOCKSIZE < remaining ? BLOCKSIZE : remaining;
            req.SendData.append(curfile.Content.c_str() + req.SendData.pos, len);
            req.SendData.pos += len;
            req.SendData.append(curfile.Content.c_str() + state->srcPos, len);
            state->srcPos += len;
            return true;
        }
    }