Commit 28205225 authored by Francis Dupont's avatar Francis Dupont
Browse files

[master] renamed INVALID_SOCKET -> SOCKET_NOT_VALID (#3861)

parent d34d3f19
934. [bug] fdupont
Renamed the DHCP-DDNS constant INVALID_SOCKET to SOCKET_NOT_VALID
to avoid conflicting with a constant of that name defined on some
operating systems.
(Trac #3861, git xxx)
933. [func]* marcin
DHCPv4 server by default identifies a client using the
client-identifier, if present. The new configuration
......
File mode changed from 100755 to 100644
......@@ -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::INVALID_SOCKET, select_fd);
ASSERT_NE(dhcp_ddns::WatchSocket::SOCKET_NOT_VALID, select_fd);
// Make sure select_fd does evaluates to not ready via select and
// that ioReady() method agrees.
......
......@@ -41,7 +41,7 @@ TEST(WatchSocketTest, basics) {
/// Verify that post-construction the state the select-fd is valid.
int select_fd = watch->getSelectFd();
EXPECT_NE(select_fd, WatchSocket::INVALID_SOCKET);
EXPECT_NE(select_fd, WatchSocket::SOCKET_NOT_VALID);
/// Verify that isReady() is false and that a call to select agrees.
EXPECT_FALSE(watch->isReady());
......@@ -85,7 +85,7 @@ TEST(WatchSocketTest, closedWhileClear) {
/// Verify that post-construction the state the select-fd is valid.
int select_fd = watch->getSelectFd();
ASSERT_NE(select_fd, WatchSocket::INVALID_SOCKET);
ASSERT_NE(select_fd, WatchSocket::SOCKET_NOT_VALID);
// Verify that socket does not appear ready.
ASSERT_EQ(0, watch->isReady());
......@@ -106,7 +106,7 @@ TEST(WatchSocketTest, closedWhileClear) {
ASSERT_NO_THROW(watch->clearReady());
// Verify that getSelectFd() returns invalid socket.
ASSERT_EQ(WatchSocket::INVALID_SOCKET, watch->getSelectFd());
ASSERT_EQ(WatchSocket::SOCKET_NOT_VALID, watch->getSelectFd());
}
/// @brief Checks behavior when select_fd has closed while in the "ready"
......@@ -120,7 +120,7 @@ TEST(WatchSocketTest, closedWhileReady) {
/// Verify that post-construction the state the select-fd is valid.
int select_fd = watch->getSelectFd();
ASSERT_NE(select_fd, WatchSocket::INVALID_SOCKET);
ASSERT_NE(select_fd, WatchSocket::SOCKET_NOT_VALID);
/// Verify that the socket can be marked ready.
ASSERT_NO_THROW(watch->markReady());
......@@ -150,7 +150,7 @@ TEST(WatchSocketTest, emptyReadySelectFd) {
/// Verify that post-construction the state the select-fd is valid.
int select_fd = watch->getSelectFd();
ASSERT_NE(select_fd, WatchSocket::INVALID_SOCKET);
ASSERT_NE(select_fd, WatchSocket::SOCKET_NOT_VALID);
/// Verify that the socket can be marked ready.
ASSERT_NO_THROW(watch->markReady());
......@@ -183,7 +183,7 @@ TEST(WatchSocketTest, badReadOnClear) {
/// Verify that post-construction the state the select-fd is valid.
int select_fd = watch->getSelectFd();
ASSERT_NE(select_fd, WatchSocket::INVALID_SOCKET);
ASSERT_NE(select_fd, WatchSocket::SOCKET_NOT_VALID);
/// Verify that the socket can be marked ready.
ASSERT_NO_THROW(watch->markReady());
......@@ -203,7 +203,7 @@ TEST(WatchSocketTest, badReadOnClear) {
EXPECT_NE(1, selectCheck(select_fd));
// Verify that getSelectFd() returns INVALID.
ASSERT_EQ(WatchSocket::INVALID_SOCKET, watch->getSelectFd());
ASSERT_EQ(WatchSocket::SOCKET_NOT_VALID, watch->getSelectFd());
// Verify that subsequent attempt to mark it fails.
ASSERT_THROW(watch->markReady(), WatchSocketError);
......
......@@ -25,11 +25,11 @@ namespace isc {
namespace dhcp_ddns {
const int WatchSocket::INVALID_SOCKET;
const int WatchSocket::SOCKET_NOT_VALID;
const uint32_t WatchSocket::MARKER;
WatchSocket::WatchSocket()
: source_(INVALID_SOCKET), sink_(INVALID_SOCKET) {
: source_(SOCKET_NOT_VALID), sink_(SOCKET_NOT_VALID) {
// Open the pipe.
int fds[2];
if (pipe(fds)) {
......@@ -79,7 +79,7 @@ WatchSocket::markReady() {
bool
WatchSocket::isReady() {
// Report it as not ready rather than error here.
if (sink_ == INVALID_SOCKET) {
if (sink_ == SOCKET_NOT_VALID) {
return (false);
}
......@@ -122,24 +122,24 @@ WatchSocket::closeSocket() {
// but there's no recovery for it either. If one does fail we log it
// and go on. Plus this is called by the destructor and no one likes
// destructors that throw.
if (source_ != INVALID_SOCKET) {
if (source_ != SOCKET_NOT_VALID) {
if (close(source_)) {
const char* errstr = strerror(errno);
LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_WATCH_SOURCE_CLOSE_ERROR)
.arg(errstr);
}
source_ = INVALID_SOCKET;
source_ = SOCKET_NOT_VALID;
}
if (sink_ != INVALID_SOCKET) {
if (sink_ != SOCKET_NOT_VALID) {
if (close(sink_)) {
const char* errstr = strerror(errno);
LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_WATCH_SINK_CLOSE_ERROR)
.arg(errstr);
}
sink_ = INVALID_SOCKET;
sink_ = SOCKET_NOT_VALID;
}
}
......
......@@ -54,7 +54,7 @@ public:
class WatchSocket {
public:
/// @brief Value used to signify an invalid descriptor.
static const int INVALID_SOCKET = -1;
static const int SOCKET_NOT_VALID = -1;
/// @brief Value written to the source when marking the socket as ready.
/// The value itself is arbitrarily chosen as one that is unlikely to occur
/// otherwise and easy to debug.
......@@ -88,7 +88,7 @@ public:
/// select_fd. Rather than track what the status "should be" it tests the status.
/// This should eliminate conditions where the select-fd appear to be perpetually
/// ready.
/// @return Returns true if select_fd is not INVALID_SOCKET and select() reports it
/// @return Returns true if select_fd is not SOCKET_NOT_VALID and select() reports it
/// as !EWOULDBLOCK, otherwise it returns false.
/// This method is guaranteed NOT to throw.
bool isReady();
......
......@@ -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::INVALID_SOCKET) {
registered_select_fd_(dhcp_ddns::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::INVALID_SOCKET) {
if (registered_select_fd_ != dhcp_ddns::WatchSocket::SOCKET_NOT_VALID) {
IfaceMgr::instance().deleteExternalSocket(registered_select_fd_);
registered_select_fd_ = dhcp_ddns::WatchSocket::INVALID_SOCKET;
registered_select_fd_ = dhcp_ddns::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::INVALID_SOCKET.
/// dhcp_ddns::WatchSocket::SOCKET_NOT_VALID.
///
/// @note This is only exposed for testing purposes.
int getRegisteredSelectFd();
......
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