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 
10 namespace isc {
11 namespace util {
12 namespace thread {
13 
14 void
15 WatchedThread::start(const boost::function<void()>& thread_main) {
19  last_error_ = "no error";
20  thread_.reset(new Thread(thread_main));
21 }
22 
23 int
25  return(sockets_[watch_type].getSelectFd());
26 }
27 
28 void
30  sockets_[watch_type].markReady();
31 }
32 
33 bool
35  return (sockets_[watch_type].isReady());
36 }
37 
38 void
40  sockets_[watch_type].clearReady();
41 }
42 
43 bool
45  if (sockets_[TERMINATE].isReady()) {
47  return (true);
48  }
49 
50  return (false);
51 }
52 
53 void
55  if (thread_) {
57  thread_->wait();
58  thread_.reset();
59  }
60 
63  last_error_ = "thread stopped";
64 }
65 
66 void
67 WatchedThread::setError(const std::string& error_msg) {
68  last_error_ = error_msg;
70 }
71 
72 std::string
74  return (last_error_);
75 }
76 } // end of namespace isc::util::thread
77 } // end of namespace isc::util
78 } // end of namespace isc
int getWatchFd(WatchType watch_type)
Fetches the fd of a watch socket.
void setError(const std::string &error_msg)
Sets the error state.
bool isReady(WatchType watch_type)
Indicates if a watch socket state is ready.
void start(const boost::function< void()> &thread_main)
Creates and runs the thread.
void clearReady()
Clears the socket's ready to read marker.
void markReady(WatchType watch_type)
Sets a watch socket state to ready.
thread::ThreadPtr thread_
Current thread instance.
std::string getLastError()
Fetches the error message text for the most recent error.
A separate thread.
Definition: thread.h:36
WatchType
Enumerates the list of watch sockets used to mark events These are used as arguments to watch socket ...
bool shouldTerminate()
Checks if the thread should terminate.
void clearReady(WatchType watch_type)
Sets a watch socket state to not ready.
void stop()
Terminates the thread.
void markReady()
Marks the select-fd as ready to read.
Definition: watch_socket.cc:64
Defines the logger used by the top-level component of kea-dhcp-ddns.
WatchSocket sockets_[TERMINATE+1]
WatchSockets that are used to communicate with the owning thread There are three:ERROR - Marked as re...
std::string last_error_
Error message of the last error encountered.