18 #include <sys/ioctl.h>
29 : source_(SOCKET_NOT_VALID), sink_(SOCKET_NOT_VALID) {
33 const char* errstr = strerror(errno);
40 if (fcntl(source_, F_SETFD, FD_CLOEXEC)) {
41 const char* errstr = strerror(errno);
46 if (fcntl(sink_, F_SETFD, FD_CLOEXEC)) {
47 const char* errstr = strerror(errno);
52 if (fcntl(sink_, F_SETFL, O_NONBLOCK)) {
53 const char* errstr = strerror(errno);
68 if (fcntl(sink_, F_GETFL) < 0) {
71 " select_fd was closed!");
76 if (nbytes !=
sizeof(
MARKER)) {
80 const char* errstr = strerror(errno);
83 <<
" bytes written: " << nbytes <<
" : " << errstr);
97 int result = ioctl(sink_, FIONREAD, &len);
99 return ((result == 0) && (len > 0));
106 int nbytes = read (sink_, &buf,
sizeof(buf));
111 const char* errstr = strerror(errno);
114 <<
" bytes read: " << nbytes <<
" : "
115 <<
" value read: " << buf <<
" error :" <<errstr);
121 WatchSocket::closeSocket(std::string& error_string) {
122 std::ostringstream s;
128 if (close(source_)) {
130 s <<
"Could not close source: " << strerror(errno);
139 if (error_string.empty()) {
140 s <<
"could not close sink: " << strerror(errno);
147 error_string = s.str();
150 return (error_string.empty() ?
true :
false);
154 WatchSocket::closeSocket() {
155 std::string error_string;
156 closeSocket(error_string);