32 const char* errstr = strerror(errno);
39 if (fcntl(source_, F_SETFD, FD_CLOEXEC)) {
40 const char* errstr = strerror(errno);
45 if (fcntl(sink_, F_SETFD, FD_CLOEXEC)) {
46 const char* errstr = strerror(errno);
51 if (fcntl(sink_, F_SETFL, O_NONBLOCK)) {
52 const char* errstr = strerror(errno);
67 if (fcntl(sink_, F_GETFL) < 0) {
70 " select_fd was closed!");
75 if (nbytes !=
sizeof(
MARKER)) {
79 const char* errstr = strerror(errno);
82 <<
" bytes written: " << nbytes <<
" : " << errstr);
96 int result = ioctl(sink_, FIONREAD, &len);
98 return ((result == 0) && (len > 0));
105 int nbytes = read (sink_, &buf,
sizeof(buf));
110 const char* errstr = strerror(errno);
113 "bytes read: " << nbytes <<
" : "
114 "value read: " << buf <<
" error :" << errstr);
121 std::ostringstream s;
127 if (close(source_)) {
129 s <<
"Could not close source: " << strerror(errno);
138 if (error_string.empty()) {
139 s <<
"could not close sink: " << strerror(errno);
146 error_string = s.str();
149 return (error_string.empty() ?
true :
false);
154 std::string error_string;
Exception thrown if an error occurs during IO source open.
static const int SOCKET_NOT_VALID
Value used to signify an invalid descriptor.
static const uint32_t MARKER
Value written to the source when marking the socket as ready.
void clearReady()
Clears the socket's ready to read marker.
WatchSocket()
Constructor.
bool closeSocket(std::string &error_string)
Closes the descriptors associated with the socket.
virtual ~WatchSocket()
Destructor.
int getSelectFd()
Returns the file descriptor to use to monitor the socket.
bool isReady()
Returns true the if socket is marked as ready.
void markReady()
Marks the select-fd as ready to read.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.
Defines the class, WatchSocket.