aboutsummaryrefslogtreecommitdiffstats
path: root/fnet/src/vespa/fnet/signalshutdown.cpp
blob: de1090c5b7a74a39691e0cac7eb8dd1d467d7cb8 (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
31
32
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "signalshutdown.h"
#include "transport.h"
#include <vespa/vespalib/util/signalhandler.h>

FNET_SignalShutDown::FNET_SignalShutDown(FNET_Transport &t)
    : FNET_Task(t.GetScheduler()),
      _transport(t)
{
    ScheduleNow();
}

void
FNET_SignalShutDown::PerformTask()
{
    using SIG = vespalib::SignalHandler;
    if (SIG::INT.check() || SIG::TERM.check()) {
        fprintf(stderr, "got signal, shutting down...\n");
        _transport.ShutDown(false);
    } else {
        Schedule(0.1);
    }
}

void
FNET_SignalShutDown::hookSignals()
{
    using SIG = vespalib::SignalHandler;
    SIG::INT.hook();
    SIG::TERM.hook();
}