aboutsummaryrefslogtreecommitdiffstats
path: root/slobrok/src/vespa/slobrok/server/request_completion_handler.cpp
blob: cca43da6cb1cad32e6edcfc48ada88ca03ac3fc5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "request_completion_handler.h"
#include <vespa/fnet/frt/rpcrequest.h>

namespace slobrok {

RequestCompletionHandler::RequestCompletionHandler(FRT_RPCRequest *parent)
    : _parentRequest(parent)
{
}

RequestCompletionHandler::~RequestCompletionHandler() {
    if (_parentRequest) {
        _parentRequest->SetError(FRTE_RPC_METHOD_FAILED, "removed before completion");
        _parentRequest->Return();
    }
}

void RequestCompletionHandler::doneHandler(OkState result) {
    if (auto req = _parentRequest) {
        _parentRequest = nullptr;
        if (result.failed()) {
            req->SetError(FRTE_RPC_METHOD_FAILED, result.errorMsg.c_str());
        }
        req->Return();
    }
}

}