Commit 1d8fe4c3 authored by Marcin Siodelski's avatar Marcin Siodelski

[3970] Moved WatchSocket class to utilities.

parent e9c58e3d
......@@ -34,7 +34,6 @@ libkea_dhcp_ddns_la_SOURCES += dhcp_ddns_log.cc dhcp_ddns_log.h
libkea_dhcp_ddns_la_SOURCES += ncr_io.cc ncr_io.h
libkea_dhcp_ddns_la_SOURCES += ncr_msg.cc ncr_msg.h
libkea_dhcp_ddns_la_SOURCES += ncr_udp.cc ncr_udp.h
libkea_dhcp_ddns_la_SOURCES += watch_socket.cc watch_socket.h
nodist_libkea_dhcp_ddns_la_SOURCES = dhcp_ddns_messages.cc dhcp_ddns_messages.h
......
......@@ -260,7 +260,7 @@ NameChangeUDPSender::open(isc::asiolink::IOService& io_service) {
send_callback_->setDataSource(server_endpoint_);
watch_socket_.reset(new WatchSocket());
watch_socket_.reset(new util::WatchSocket());
}
void
......
// Copyright (C) 2013-2014 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -112,8 +112,8 @@
#include <asiolink/udp_endpoint.h>
#include <asiolink/udp_socket.h>
#include <dhcp_ddns/ncr_io.h>
#include <dhcp_ddns/watch_socket.h>
#include <util/buffer.h>
#include <util/watch_socket.h>
#include <boost/shared_array.hpp>
......@@ -579,7 +579,7 @@ private:
bool reuse_address_;
/// @brief Pointer to WatchSocket instance supplying the "select-fd".
WatchSocketPtr watch_socket_;
util::WatchSocketPtr watch_socket_;
};
} // namespace isc::dhcp_ddns
......
......@@ -30,7 +30,6 @@ libdhcp_ddns_unittests_SOURCES = run_unittests.cc
libdhcp_ddns_unittests_SOURCES += ncr_unittests.cc
libdhcp_ddns_unittests_SOURCES += ncr_udp_unittests.cc
libdhcp_ddns_unittests_SOURCES += test_utils.cc test_utils.h
libdhcp_ddns_unittests_SOURCES += watch_socket_unittests.cc
libdhcp_ddns_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
......
......@@ -362,7 +362,7 @@ TEST(NameChangeUDPSenderBasicTest, basicSendTests) {
int select_fd = sender.getSelectFd();
// Verify select_fd is valid and currently shows no ready to read.
ASSERT_NE(dhcp_ddns::WatchSocket::SOCKET_NOT_VALID, select_fd);
ASSERT_NE(util::WatchSocket::SOCKET_NOT_VALID, select_fd);
// Make sure select_fd does evaluates to not ready via select and
// that ioReady() method agrees.
......@@ -747,7 +747,7 @@ TEST(NameChangeUDPSenderBasicTest, watchClosedBeforeSendRequest) {
close(sender.getSelectFd());
// Send should fail as we interferred by closing the select-fd.
ASSERT_THROW(sender.sendRequest(ncr), WatchSocketError);
ASSERT_THROW(sender.sendRequest(ncr), util::WatchSocketError);
// Verify we didn't invoke the handler.
EXPECT_EQ(0, ncr_handler.pass_count_);
......@@ -827,7 +827,7 @@ TEST(NameChangeUDPSenderBasicTest, watchSocketBadRead) {
// Interfere by reading part of the marker from the select-fd.
uint32_t buf = 0;
ASSERT_EQ((read (select_fd, &buf, 1)), 1);
ASSERT_NE(WatchSocket::MARKER, buf);
ASSERT_NE(util::WatchSocket::MARKER, buf);
// Run one handler. This should execute the send completion handler
// after sending the message. Duing completion handling clearing the
......
......@@ -30,7 +30,7 @@ namespace dhcp {
D2ClientMgr::D2ClientMgr() : d2_client_config_(new D2ClientConfig()),
name_change_sender_(), private_io_service_(),
registered_select_fd_(dhcp_ddns::WatchSocket::SOCKET_NOT_VALID) {
registered_select_fd_(util::WatchSocket::SOCKET_NOT_VALID) {
// Default constructor initializes with a disabled configuration.
}
......@@ -275,9 +275,9 @@ D2ClientMgr::amSending() const {
void
D2ClientMgr::stopSender() {
/// Unregister sender's select-fd.
if (registered_select_fd_ != dhcp_ddns::WatchSocket::SOCKET_NOT_VALID) {
if (registered_select_fd_ != util::WatchSocket::SOCKET_NOT_VALID) {
IfaceMgr::instance().deleteExternalSocket(registered_select_fd_);
registered_select_fd_ = dhcp_ddns::WatchSocket::SOCKET_NOT_VALID;
registered_select_fd_ = util::WatchSocket::SOCKET_NOT_VALID;
}
// If its not null, call stop.
......
......@@ -409,7 +409,7 @@ protected:
/// @brief Fetches the select-fd that is currently registered.
///
/// @return The currently registered select-fd or
/// dhcp_ddns::WatchSocket::SOCKET_NOT_VALID.
/// util::WatchSocket::SOCKET_NOT_VALID.
///
/// @note This is only exposed for testing purposes.
int getRegisteredSelectFd();
......
......@@ -26,6 +26,7 @@ libkea_util_la_SOURCES += range_utilities.h
libkea_util_la_SOURCES += signal_set.cc signal_set.h
libkea_util_la_SOURCES += stopwatch.cc stopwatch.h
libkea_util_la_SOURCES += stopwatch_impl.cc stopwatch_impl.h
libkea_util_la_SOURCES += watch_socket.cc watch_socket.h
libkea_util_la_SOURCES += encode/base16_from_binary.h
libkea_util_la_SOURCES += encode/base32hex.h encode/base64.h
libkea_util_la_SOURCES += encode/base32hex_from_binary.h
......
......@@ -51,6 +51,8 @@ run_unittests_SOURCES += time_utilities_unittest.cc
run_unittests_SOURCES += range_utilities_unittest.cc
run_unittests_SOURCES += signal_set_unittest.cc
run_unittests_SOURCES += stopwatch_unittest.cc
run_unittests_SOURCES += watch_socket_unittests.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
......
// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -12,8 +12,7 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <config.h>
#include <dhcp_ddns/watch_socket.h>
#include <test_utils.h>
#include <util/watch_socket.h>
#include <gtest/gtest.h>
......@@ -27,10 +26,33 @@
using namespace std;
using namespace isc;
using namespace isc::dhcp_ddns;
using namespace isc::util;
namespace {
/// @brief Returns the result of select() given an fd to check for read status.
///
/// @param fd_to_check The file descriptor to test
///
/// @return Returns less than one on an error, 0 if the fd is not ready to
/// read, > 0 if it is ready to read.
int selectCheck(int fd_to_check) {
fd_set read_fds;
int maxfd = 0;
FD_ZERO(&read_fds);
// Add this socket to listening set
FD_SET(fd_to_check, &read_fds);
maxfd = fd_to_check;
struct timeval select_timeout;
select_timeout.tv_sec = 0;
select_timeout.tv_usec = 0;
return (select(maxfd + 1, &read_fds, NULL, NULL, &select_timeout));
}
/// @brief Tests the basic functionality of WatchSocket.
TEST(WatchSocketTest, basics) {
WatchSocketPtr watch;
......
// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -14,15 +14,15 @@
/// @file watch_socket.cc
#include <dhcp_ddns/dhcp_ddns_log.h>
#include <dhcp_ddns/watch_socket.h>
//#include <dhcp_ddns/dhcp_ddns_log.h>
#include <util/watch_socket.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/select.h>
namespace isc {
namespace dhcp_ddns {
namespace util {
const int WatchSocket::SOCKET_NOT_VALID;
......@@ -124,9 +124,9 @@ WatchSocket::closeSocket() {
// destructors that throw.
if (source_ != SOCKET_NOT_VALID) {
if (close(source_)) {
const char* errstr = strerror(errno);
/* const char* errstr = strerror(errno);
LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_WATCH_SOURCE_CLOSE_ERROR)
.arg(errstr);
.arg(errstr); */
}
source_ = SOCKET_NOT_VALID;
......@@ -134,9 +134,9 @@ WatchSocket::closeSocket() {
if (sink_ != SOCKET_NOT_VALID) {
if (close(sink_)) {
const char* errstr = strerror(errno);
/* const char* errstr = strerror(errno);
LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_WATCH_SINK_CLOSE_ERROR)
.arg(errstr);
.arg(errstr); */
}
sink_ = SOCKET_NOT_VALID;
......@@ -148,5 +148,5 @@ WatchSocket::getSelectFd() {
return (sink_);
}
} // namespace isc::dhcp_ddns
} // namespace isc::util
} // namespace isc
// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -24,7 +24,7 @@
#include <stdint.h>
namespace isc {
namespace dhcp_ddns {
namespace util {
/// @brief Exception thrown if an error occurs during IO source open.
class WatchSocketError : public isc::Exception {
......@@ -132,7 +132,7 @@ private:
/// @brief Defines a smart pointer to an instance of a WatchSocket.
typedef boost::shared_ptr<WatchSocket> WatchSocketPtr;
} // namespace isc::dhcp_ddns
} // namespace isc::util
} // namespace isc
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment