Kea 1.5.0
watched_thread.cc
Go to the documentation of this file.
1// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
9
10namespace isc {
11namespace util {
12namespace thread {
13
14void
15WatchedThread::start(const boost::function<void()>& thread_main) {
19 last_error_ = "no error";
20 thread_.reset(new Thread(thread_main));
21}
22
23int
25 return(sockets_[watch_type].getSelectFd());
26}
27
28void
30 sockets_[watch_type].markReady();
31}
32
33bool
35 return (sockets_[watch_type].isReady());
36}
37
38void
40 sockets_[watch_type].clearReady();
41}
42
43bool
45 if (sockets_[TERMINATE].isReady()) {
47 return (true);
48 }
49
50 return (false);
51}
52
53void
55 if (thread_) {
57 thread_->wait();
58 thread_.reset();
59 }
60
63 last_error_ = "thread stopped";
64}
65
66void
67WatchedThread::setError(const std::string& error_msg) {
68 last_error_ = error_msg;
70}
71
72std::string
74 return (last_error_);
75}
76} // end of namespace isc::util::thread
77} // end of namespace isc::util
78} // end of namespace isc
void clearReady()
Clears the socket's ready to read marker.
void markReady()
Marks the select-fd as ready to read.
Definition: watch_socket.cc:64
A separate thread.
Definition: thread.h:36
void start(const boost::function< void()> &thread_main)
Creates and runs the thread.
WatchType
Enumerates the list of watch sockets used to mark events These are used as arguments to watch socket ...
std::string last_error_
Error message of the last error encountered.
void markReady(WatchType watch_type)
Sets a watch socket state to ready.
bool isReady(WatchType watch_type)
Indicates if a watch socket state is ready.
void setError(const std::string &error_msg)
Sets the error state.
WatchSocket sockets_[TERMINATE+1]
WatchSockets that are used to communicate with the owning thread There are three:
thread::ThreadPtr thread_
Current thread instance.
std::string getLastError()
Fetches the error message text for the most recent error.
void clearReady(WatchType watch_type)
Sets a watch socket state to not ready.
void stop()
Terminates the thread.
bool shouldTerminate()
Checks if the thread should terminate.
int getWatchFd(WatchType watch_type)
Fetches the fd of a watch socket.
Defines the logger used by the top-level component of kea-dhcp-ddns.