Commit 8a160874 authored by Steven Murray's avatar Steven Murray
Browse files

Moved SmartFd into CTA common

parent bbcc17e6
......@@ -100,6 +100,7 @@ set (COMMON_LIB_SRC_FILES
remoteFS/RemoteFileStatus.cpp
remoteFS/RemotePath.cpp
remoteFS/RemotePathAndStatus.cpp
SmartFd.cpp
threading/ChildProcess.cpp
threading/Daemon.cpp
threading/Mutex.cpp
......@@ -136,6 +137,7 @@ set (COMMON_UNIT_TESTS_LIB_SRC_FILES
log/SyslogLoggerTest.cpp
log/StringLoggerTest.cpp
remoteFS/RemotePathTest.cpp
SmartFdTest.cpp
threading/DaemonTest.cpp
threading/SocketPairTest.cpp
utils/UtilsTest.cpp
......
......@@ -22,7 +22,7 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/utils/SmartFd.hpp"
#include "common/SmartFd.hpp"
#include <errno.h>
#include <unistd.h>
......@@ -30,21 +30,21 @@
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
castor::utils::SmartFd::SmartFd() throw():
cta::SmartFd::SmartFd() throw():
m_fd(-1), m_closedCallback(NULL) {
}
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
castor::utils::SmartFd::SmartFd(const int fd) throw():
cta::SmartFd::SmartFd(const int fd) throw():
m_fd(fd), m_closedCallback(NULL) {
}
//-----------------------------------------------------------------------------
// setClosedCallback
//-----------------------------------------------------------------------------
void castor::utils::SmartFd::setClosedCallback(ClosedCallback closedCallback)
void cta::SmartFd::setClosedCallback(ClosedCallback closedCallback)
throw() {
m_closedCallback = closedCallback;
}
......@@ -52,7 +52,7 @@ void castor::utils::SmartFd::setClosedCallback(ClosedCallback closedCallback)
//-----------------------------------------------------------------------------
// reset
//-----------------------------------------------------------------------------
void castor::utils::SmartFd::reset(const int fd = -1) throw() {
void cta::SmartFd::reset(const int fd = -1) throw() {
// If the new file descriptor is not the one already owned
if(fd != m_fd) {
......@@ -78,8 +78,7 @@ void castor::utils::SmartFd::reset(const int fd = -1) throw() {
//-----------------------------------------------------------------------------
// SmartFd assignment operator
//-----------------------------------------------------------------------------
castor::utils::SmartFd &castor::utils::SmartFd::operator=(SmartFd& obj)
{
cta::SmartFd &cta::SmartFd::operator=(SmartFd& obj) {
reset(obj.release());
return *this;
}
......@@ -87,21 +86,21 @@ castor::utils::SmartFd &castor::utils::SmartFd::operator=(SmartFd& obj)
//-----------------------------------------------------------------------------
// destructor
//-----------------------------------------------------------------------------
castor::utils::SmartFd::~SmartFd() {
cta::SmartFd::~SmartFd() {
reset();
}
//-----------------------------------------------------------------------------
// get
//-----------------------------------------------------------------------------
int castor::utils::SmartFd::get() const throw() {
int cta::SmartFd::get() const throw() {
return m_fd;
}
//-----------------------------------------------------------------------------
// release
//-----------------------------------------------------------------------------
int castor::utils::SmartFd::release() {
int cta::SmartFd::release() {
// If this SmartFd does not own a file descriptor
if(m_fd < 0) {
cta::exception::NotAnOwner ex;
......
......@@ -25,8 +25,7 @@
#include "common/exception/NotAnOwner.hpp"
namespace castor {
namespace utils {
namespace cta {
/**
* A smart file descriptor that owns a basic file descriptor. When the smart
......@@ -149,6 +148,4 @@ private:
}; // class SmartFd
} // namespace utils
} // namespace castor
} // namespace cta
......@@ -21,7 +21,7 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/utils/SmartFd.hpp"
#include "common/SmartFd.hpp"
#include <gtest/gtest.h>
#include <sys/types.h>
......@@ -31,7 +31,7 @@
namespace unitTests {
class castor_utils_SmartFdTest : public ::testing::Test {
class cta_SmartFdTest : public ::testing::Test {
protected:
static int s_fd;
static bool s_closedCallbackWasCalled;
......@@ -50,11 +50,11 @@ protected:
}
};
int castor_utils_SmartFdTest::s_fd = -1;
bool castor_utils_SmartFdTest::s_closedCallbackWasCalled = false;
int cta_SmartFdTest::s_fd = -1;
bool cta_SmartFdTest::s_closedCallbackWasCalled = false;
TEST_F(castor_utils_SmartFdTest, testClosedCallback) {
using namespace castor::utils;
TEST_F(cta_SmartFdTest, testClosedCallback) {
using namespace cta;
ASSERT_EQ(-1, s_fd);
ASSERT_FALSE(s_closedCallbackWasCalled);
......
......@@ -22,9 +22,9 @@
*****************************************************************************/
#include "castor/io/io.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/io/marshall.h"
#include "common/exception/Errnum.hpp"
#include "common/SmartFd.hpp"
#include <fcntl.h>
#include <gtest/gtest.h>
......@@ -58,7 +58,7 @@ protected:
unlink(listenSockPath);
// Create the socket
castor::utils::SmartFd smartListenSock(socket(PF_LOCAL, SOCK_STREAM, 0));
cta::SmartFd smartListenSock(socket(PF_LOCAL, SOCK_STREAM, 0));
if(-1 == smartListenSock.get()) {
char strErrBuf[256];
if(0 != strerror_r(errno, strErrBuf, sizeof(strErrBuf))) {
......@@ -112,11 +112,11 @@ protected:
}; // class castor_io_IoTest
TEST_F(castor_io_IoTest, connectWithTimeout) {
castor::utils::SmartFd smartListenSock;
cta::SmartFd smartListenSock;
ASSERT_NO_THROW(smartListenSock.reset(
createLocalListenSocket(m_listenSockPath)));
castor::utils::SmartFd smartClientConnectionSock;
cta::SmartFd smartClientConnectionSock;
{
const int sockDomain = PF_LOCAL;
const int sockType = SOCK_STREAM;
......@@ -138,7 +138,7 @@ TEST_F(castor_io_IoTest, connectWithTimeout) {
timeout)));
}
castor::utils::SmartFd smartServerConnectionSock;
cta::SmartFd smartServerConnectionSock;
{
const time_t acceptTimeout = 10; // Timeout is in seconds
ASSERT_NO_THROW(smartServerConnectionSock.reset(
......
......@@ -24,9 +24,9 @@
#include "common/exception/InvalidArgument.hpp"
#include "castor/io/io.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/utils/utils.hpp"
#include "common/exception/Exception.hpp"
#include "common/SmartFd.hpp"
#include "common/utils/utils.hpp"
#include "common/Timer.hpp"
#include "common/exception/Errnum.hpp"
......@@ -129,7 +129,7 @@ int castor::io::createListenerSock(
}
// Create a socket
utils::SmartFd sock(socket(PF_INET, SOCK_STREAM, IPPROTO_TCP));
cta::SmartFd sock(socket(PF_INET, SOCK_STREAM, IPPROTO_TCP));
if(sock.get() < 0) {
cta::exception::Exception ex;
ex.getMessage() << ": Failed to create socket: "
......@@ -909,7 +909,7 @@ int castor::io::connectWithTimeout(
throw(cta::exception::TimeOut, cta::exception::Exception) {
// Create the socket for the new connection
utils::SmartFd smartSock(socket(sockDomain, sockType, sockProtocol));
cta::SmartFd smartSock(socket(sockDomain, sockType, sockProtocol));
if(-1 == smartSock.get()) {
cta::exception::Exception ex;
ex.getMessage() <<
......
......@@ -23,9 +23,9 @@
#include "castor/legacymsg/CommonMarshal.hpp"
#include "castor/legacymsg/RmcMarshal.hpp"
#include "castor/legacymsg/RmcProxyTcpIp.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/utils/utils.hpp"
#include "Castor_limits.h"
#include "common/SmartFd.hpp"
#include "rmc_constants.h"
//------------------------------------------------------------------------------
......@@ -117,7 +117,7 @@ void castor::legacymsg::RmcProxyTcpIp::forceDismountTape(const std::string &vid,
int castor::legacymsg::RmcProxyTcpIp::connectToRmc()
const {
const std::string rmcHost = "localhost";
castor::utils::SmartFd smartConnectSock;
cta::SmartFd smartConnectSock;
try {
smartConnectSock.reset(io::connectWithTimeout(rmcHost, m_rmcPort,
m_netTimeout));
......
......@@ -26,8 +26,8 @@
#include "castor/legacymsg/RmcMountMsgBody.hpp"
#include "castor/legacymsg/RmcProxy.hpp"
#include "castor/legacymsg/RmcUnmountMsgBody.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/utils/utils.hpp"
#include "common/SmartFd.hpp"
#include "h/rmc_constants.h"
#include <unistd.h>
......@@ -240,7 +240,7 @@ protected:
template<typename T> int rmcSendRecv(const T &rqstBody,
std::ostringstream &rmcErrorStream) {
// Connect to rmcd and send request
castor::utils::SmartFd fd(connectToRmc());
cta::SmartFd fd(connectToRmc());
{
char buf[RMC_MSGBUFSIZ];
const size_t len = marshal(buf, rqstBody);
......
......@@ -24,7 +24,7 @@
#include "castor/tape/tapeserver/daemon/ProcessForkerConnectionHandler.hpp"
#include "castor/tape/tapeserver/daemon/ProcessForkerUtils.hpp"
#include "castor/tape/tapeserver/daemon/Session.hpp"
#include "castor/utils/SmartFd.hpp"
#include "common/SmartFd.hpp"
//------------------------------------------------------------------------------
// constructor
......
......@@ -24,7 +24,7 @@
#include "castor/log/DummyLogger.hpp"
#include "castor/tape/tapeserver/daemon/ProcessForker.hpp"
#include "castor/tape/tapeserver/daemon/ProcessForkerProxySocket.hpp"
#include "castor/utils/SmartFd.hpp"
#include "common/SmartFd.hpp"
#include <gtest/gtest.h>
#include <memory>
......@@ -48,13 +48,13 @@ TEST_F(castor_tape_tapeserver_daemon_ProcessForkerTest, constructor) {
int cmdPair[2] = {-1, -1};
ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, cmdPair));
castor::utils::SmartFd cmdSenderSocket(cmdPair[0]);
castor::utils::SmartFd cmdReceiverSocket(cmdPair[1]);
cta::SmartFd cmdSenderSocket(cmdPair[0]);
cta::SmartFd cmdReceiverSocket(cmdPair[1]);
int reaperPair[2] = {-1, -1};
ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, reaperPair));
castor::utils::SmartFd reaperSenderSocket(reaperPair[0]);
castor::utils::SmartFd reaperReceiverSocket(reaperPair[1]);
cta::SmartFd reaperSenderSocket(reaperPair[0]);
cta::SmartFd reaperReceiverSocket(reaperPair[1]);
const std::string programName = "unittests";
const std::string hostName = "hostName";
......@@ -73,13 +73,13 @@ TEST_F(castor_tape_tapeserver_daemon_ProcessForkerTest, socketproxy) {
int cmdPair[2] = {-1, -1};
ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, cmdPair));
castor::utils::SmartFd cmdSenderSocket(cmdPair[0]);
castor::utils::SmartFd cmdReceiverSocket(cmdPair[1]);
cta::SmartFd cmdSenderSocket(cmdPair[0]);
cta::SmartFd cmdReceiverSocket(cmdPair[1]);
int reaperPair[2] = {-1, -1};
ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, reaperPair));
castor::utils::SmartFd reaperSenderSocket(reaperPair[0]);
castor::utils::SmartFd reaperReceiverSocket(reaperPair[1]);
cta::SmartFd reaperSenderSocket(reaperPair[0]);
cta::SmartFd reaperReceiverSocket(reaperPair[1]);
const std::string programName = "unittests";
const std::string hostName = "hostName";
......
......@@ -39,8 +39,8 @@
#include "castor/tape/tapeserver/daemon/TapeMessageHandler.hpp"
#include "castor/tape/tapeserver/file/File.hpp"
#include "castor/tape/tapeserver/TapeBridgeConstants.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/utils/utils.hpp"
#include "common/SmartFd.hpp"
#include "rmc_constants.h"
#include <algorithm>
......
......@@ -24,7 +24,6 @@ include_directories(${PROJECT_SOURCE_DIR}/tapeserver)
set_source_files_properties(CRC.cpp PROPERTIES COMPILE_FLAGS -O2)
set (UTILS_LIB_SRC_FILES
SmartFd.cpp
SmartFILEPtr.cpp
Timer.cpp
CRC.cpp
......@@ -50,7 +49,6 @@ install(TARGETS ctautils DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
add_library (ctautilsunittests SHARED
SmartArrayPtrTest.cpp
SmartFdTest.cpp
UtilsTest.cpp)
install(TARGETS ctautilsunittests DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
Supports Markdown
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