Kea  1.9.9-git
watch_socket.h
Go to the documentation of this file.
1 // Copyright (C) 2014-2015 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 #ifndef WATCH_SOCKET_H
8 #define WATCH_SOCKET_H
9 
11 
12 #include <exceptions/exceptions.h>
13 #include <boost/noncopyable.hpp>
14 #include <boost/shared_ptr.hpp>
15 
16 #include <stdint.h>
17 #include <string>
18 
19 namespace isc {
20 namespace util {
21 
24 public:
25  WatchSocketError(const char* file, size_t line, const char* what) :
26  isc::Exception(file, line, what) { };
27 };
28 
47 class WatchSocket : public boost::noncopyable {
48 public:
50  static const int SOCKET_NOT_VALID = -1;
54  static const uint32_t MARKER = 0xDEADBEEF;
55 
60  WatchSocket();
61 
65  virtual ~WatchSocket();
66 
76  void markReady();
77 
87  bool isReady();
88 
99  void clearReady();
100 
108  int getSelectFd();
109 
119  bool closeSocket(std::string& error_string);
120 
121 private:
122 
127  void closeSocket();
128 
130  int source_;
131 
134  int sink_;
135 };
136 
138 typedef boost::shared_ptr<WatchSocket> WatchSocketPtr;
139 
140 } // namespace isc::util
141 } // namespace isc
142 
143 #endif
WatchSocketError(const char *file, size_t line, const char *what)
Definition: watch_socket.h:25
void clearReady()
Clears the socket's ready to read marker.
boost::shared_ptr< WatchSocket > WatchSocketPtr
Defines a smart pointer to an instance of a WatchSocket.
Definition: watch_socket.h:138
WatchSocket()
Constructor.
Definition: watch_socket.cc:28
static const uint32_t MARKER
Value written to the source when marking the socket as ready.
Definition: watch_socket.h:54
int getSelectFd()
Returns the file descriptor to use to monitor the socket.
bool closeSocket(std::string &error_string)
Closes the descriptors associated with the socket.
Provides an IO "ready" semaphore for use with select() or poll() WatchSocket exposes a single open fi...
Definition: watch_socket.h:47
virtual ~WatchSocket()
Destructor.
Definition: watch_socket.cc:59
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void markReady()
Marks the select-fd as ready to read.
Definition: watch_socket.cc:64
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Exception thrown if an error occurs during IO source open.
Definition: watch_socket.h:23
static const int SOCKET_NOT_VALID
Value used to signify an invalid descriptor.
Definition: watch_socket.h:50
bool isReady()
Returns true the if socket is marked as ready.
Definition: watch_socket.cc:89