Commit 9978fa0e authored by Jan Koester's avatar Jan Koester
Browse files

bugfix

parent 803cf0b2
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -1358,6 +1358,26 @@ namespace blogi {
            return false;
        }

        // The browser gave up on `req` (tab closed, navigated away, network
        // drop, ...) before its download finished. Response() will never be
        // called for it again, so release its pooled mediadb connection now
        // instead of leaving it for the STREAM_IDLE_TIMEOUT reaper to
        // eventually notice — see _reapStaleStreamsLocked() above for why
        // that reaper exists at all (no such per-request signal used to be
        // available here) and _storeStreamState()/_getStreamState() for the
        // state this cleans up.
        void Disconnect(const int tid, libhttppp::HttpRequest &req){
            {
                std::unique_lock lock(_streamMutex);
                auto it = _streams.find(reinterpret_cast<uintptr_t>(&req));
                if(it != _streams.end()){
                    it->second.client.discard();
                    _streams.erase(it);
                }
            }
            _removeUploadResponse(req);
        }

        void GetSiteMap(const int tid,std::map<libhttppp::HttpUrl,std::chrono::year_month_day> &sitemap){
            return;
        }
+20 −0
Original line number Diff line number Diff line
@@ -3676,6 +3676,26 @@ void blogi::Blogi::ResponseEvent(libhttppp::HttpRequest &curreq, const int tid,
    }
}

// Notifies every loaded plugin that this connection is gone, so any plugin
// holding per-request state (keyed off `curreq`, e.g. media's streaming
// bookkeeping in plugins/media/media.cpp) can release it — see the
// PluginApi::Disconnect() doc comment in plugin.h for why this exists.
// Unlike ResponseEvent, this isn't routed by request URL prefix: the
// connection is going away regardless of which route it was last serving,
// so every plugin gets a chance to check its own state for this request.
void blogi::Blogi::DisconnectEvent(libhttppp::HttpRequest &curreq, const int tid, ULONG_PTR args)
{
    DomainContext *ctx = resolveDomain(curreq);
    if (!ctx)
        return;

    for (const blogi::Plugin::PluginData *curplg = ctx->plugins->getFirstPlugin(); curplg; curplg = curplg->getNextPlg())
    {
        PluginApi *api = curplg->getInstace();
        api->Disconnect(tid, curreq);
    }
}

// Binds the server socket(s) without starting the event loop.
// Used by the supervisor in pre-fork mode so the fd is inherited by all
// domain worker children before they diverge into separate processes.
+1 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ namespace blogi {
        void llmsTxtRoot(libhttppp::HttpRequest& curreq, const int tid, const std::string &sessionid, DomainContext &ctx);
        void RequestEvent(libhttppp::HttpRequest &curreq,const int tid,ULONG_PTR args);
        void ResponseEvent(libhttppp::HttpRequest &curreq,const int tid,ULONG_PTR args);
        void DisconnectEvent(libhttppp::HttpRequest &curreq,const int tid,ULONG_PTR args);

        // Only the media plugin's getimage route makes a slow, blocking
        // backend round-trip (mediadb) inside RequestEvent — opting just
+4 −0
Original line number Diff line number Diff line
@@ -146,6 +146,10 @@ bool blogi::PluginApi::Response(const int tid,libhttppp::HttpRequest& req){
    return false;
}

void blogi::PluginApi::Disconnect(const int tid,libhttppp::HttpRequest& req){
    return;
}

void blogi::PluginApi::Search(const int tid, const char* word, blogi::SearchRet &result, const std::string &sessionid){
    return;
}
+10 −0
Original line number Diff line number Diff line
@@ -173,6 +173,16 @@ namespace blogi {

        virtual bool Response(const int tid,libhttppp::HttpRequest &req);

        // Called once for every plugin when the connection behind `req` goes
        // away (browser closed the tab, navigated off, network drop, ...) --
        // there was previously no such signal at all: a plugin that stashed
        // per-request state keyed off `req` (e.g. media's streaming-download
        // bookkeeping) had no way to find out its request would never be
        // revisited, so that state — and anything it held open, such as a
        // pooled backend connection — leaked for the life of the process.
        // Default does nothing; override only if the plugin keeps such state.
        virtual void Disconnect(const int tid,libhttppp::HttpRequest &req);

        virtual json_object* Settings(const int tid,libhttppp::HttpRequest &req,const std::string &sessionid);

        virtual void Rendering(const int tid,libhttppp::HttpRequest &req,libhtmlpp::HtmlElement *curpage,int type=0,const std::string &sessionid="");