Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
8a160874
Commit
8a160874
authored
Sep 01, 2016
by
Steven Murray
Browse files
Moved SmartFd into CTA common
parent
bbcc17e6
Changes
12
Hide whitespace changes
Inline
Side-by-side
common/CMakeLists.txt
View file @
8a160874
...
...
@@ -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
...
...
tapeserver/castor/utils
/SmartFd.cpp
→
common
/SmartFd.cpp
View file @
8a160874
...
...
@@ -22,7 +22,7 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include
"c
astor/utils
/SmartFd.hpp"
#include
"c
ommon
/SmartFd.hpp"
#include
<errno.h>
#include
<unistd.h>
...
...
@@ -30,21 +30,21 @@
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
ca
stor
::
utils
::
SmartFd
::
SmartFd
()
throw
()
:
c
t
a
::
SmartFd
::
SmartFd
()
throw
()
:
m_fd
(
-
1
),
m_closedCallback
(
NULL
)
{
}
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
ca
stor
::
utils
::
SmartFd
::
SmartFd
(
const
int
fd
)
throw
()
:
c
t
a
::
SmartFd
::
SmartFd
(
const
int
fd
)
throw
()
:
m_fd
(
fd
),
m_closedCallback
(
NULL
)
{
}
//-----------------------------------------------------------------------------
// setClosedCallback
//-----------------------------------------------------------------------------
void
ca
stor
::
utils
::
SmartFd
::
setClosedCallback
(
ClosedCallback
closedCallback
)
void
c
t
a
::
SmartFd
::
setClosedCallback
(
ClosedCallback
closedCallback
)
throw
()
{
m_closedCallback
=
closedCallback
;
}
...
...
@@ -52,7 +52,7 @@ void castor::utils::SmartFd::setClosedCallback(ClosedCallback closedCallback)
//-----------------------------------------------------------------------------
// reset
//-----------------------------------------------------------------------------
void
ca
stor
::
utils
::
SmartFd
::
reset
(
const
int
fd
=
-
1
)
throw
()
{
void
c
t
a
::
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
//-----------------------------------------------------------------------------
ca
stor
::
utils
::
SmartFd
::~
SmartFd
()
{
c
t
a
::
SmartFd
::~
SmartFd
()
{
reset
();
}
//-----------------------------------------------------------------------------
// get
//-----------------------------------------------------------------------------
int
ca
stor
::
utils
::
SmartFd
::
get
()
const
throw
()
{
int
c
t
a
::
SmartFd
::
get
()
const
throw
()
{
return
m_fd
;
}
//-----------------------------------------------------------------------------
// release
//-----------------------------------------------------------------------------
int
ca
stor
::
utils
::
SmartFd
::
release
()
{
int
c
t
a
::
SmartFd
::
release
()
{
// If this SmartFd does not own a file descriptor
if
(
m_fd
<
0
)
{
cta
::
exception
::
NotAnOwner
ex
;
...
...
tapeserver/castor/utils
/SmartFd.hpp
→
common
/SmartFd.hpp
View file @
8a160874
...
...
@@ -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
tapeserver/castor/utils
/SmartFdTest.cpp
→
common
/SmartFdTest.cpp
View file @
8a160874
...
...
@@ -21,7 +21,7 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include
"c
astor/utils
/SmartFd.hpp"
#include
"c
ommon
/SmartFd.hpp"
#include
<gtest/gtest.h>
#include
<sys/types.h>
...
...
@@ -31,7 +31,7 @@
namespace
unitTests
{
class
ca
stor_utils
_SmartFdTest
:
public
::
testing
::
Test
{
class
c
t
a_SmartFdTest
:
public
::
testing
::
Test
{
protected:
static
int
s_fd
;
static
bool
s_closedCallbackWasCalled
;
...
...
@@ -50,11 +50,11 @@ protected:
}
};
int
ca
stor_utils
_SmartFdTest
::
s_fd
=
-
1
;
bool
ca
stor_utils
_SmartFdTest
::
s_closedCallbackWasCalled
=
false
;
int
c
t
a_SmartFdTest
::
s_fd
=
-
1
;
bool
c
t
a_SmartFdTest
::
s_closedCallbackWasCalled
=
false
;
TEST_F
(
ca
stor_utils
_SmartFdTest
,
testClosedCallback
)
{
using
namespace
ca
stor
::
utils
;
TEST_F
(
c
t
a_SmartFdTest
,
testClosedCallback
)
{
using
namespace
c
t
a
;
ASSERT_EQ
(
-
1
,
s_fd
);
ASSERT_FALSE
(
s_closedCallbackWasCalled
);
...
...
tapeserver/castor/io/IoTest.cpp
View file @
8a160874
...
...
@@ -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
ca
stor
::
utils
::
SmartFd
smartListenSock
(
socket
(
PF_LOCAL
,
SOCK_STREAM
,
0
));
c
t
a
::
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
)
{
ca
stor
::
utils
::
SmartFd
smartListenSock
;
c
t
a
::
SmartFd
smartListenSock
;
ASSERT_NO_THROW
(
smartListenSock
.
reset
(
createLocalListenSocket
(
m_listenSockPath
)));
ca
stor
::
utils
::
SmartFd
smartClientConnectionSock
;
c
t
a
::
SmartFd
smartClientConnectionSock
;
{
const
int
sockDomain
=
PF_LOCAL
;
const
int
sockType
=
SOCK_STREAM
;
...
...
@@ -138,7 +138,7 @@ TEST_F(castor_io_IoTest, connectWithTimeout) {
timeout
)));
}
ca
stor
::
utils
::
SmartFd
smartServerConnectionSock
;
c
t
a
::
SmartFd
smartServerConnectionSock
;
{
const
time_t
acceptTimeout
=
10
;
// Timeout is in seconds
ASSERT_NO_THROW
(
smartServerConnectionSock
.
reset
(
...
...
tapeserver/castor/io/io.cpp
View file @
8a160874
...
...
@@ -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
()
<<
...
...
tapeserver/castor/legacymsg/RmcProxyTcpIp.cpp
View file @
8a160874
...
...
@@ -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"
;
ca
stor
::
utils
::
SmartFd
smartConnectSock
;
c
t
a
::
SmartFd
smartConnectSock
;
try
{
smartConnectSock
.
reset
(
io
::
connectWithTimeout
(
rmcHost
,
m_rmcPort
,
m_netTimeout
));
...
...
tapeserver/castor/legacymsg/RmcProxyTcpIp.hpp
View file @
8a160874
...
...
@@ -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
ca
stor
::
utils
::
SmartFd
fd
(
connectToRmc
());
c
t
a
::
SmartFd
fd
(
connectToRmc
());
{
char
buf
[
RMC_MSGBUFSIZ
];
const
size_t
len
=
marshal
(
buf
,
rqstBody
);
...
...
tapeserver/castor/tape/tapeserver/daemon/ProcessForkerConnectionHandler.cpp
View file @
8a160874
...
...
@@ -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
"c
astor/utils
/SmartFd.hpp"
#include
"c
ommon
/SmartFd.hpp"
//------------------------------------------------------------------------------
// constructor
...
...
tapeserver/castor/tape/tapeserver/daemon/ProcessForkerTest.cpp
View file @
8a160874
...
...
@@ -24,7 +24,7 @@
#include
"castor/log/DummyLogger.hpp"
#include
"castor/tape/tapeserver/daemon/ProcessForker.hpp"
#include
"castor/tape/tapeserver/daemon/ProcessForkerProxySocket.hpp"
#include
"c
astor/utils
/SmartFd.hpp"
#include
"c
ommon
/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
));
ca
stor
::
utils
::
SmartFd
cmdSenderSocket
(
cmdPair
[
0
]);
ca
stor
::
utils
::
SmartFd
cmdReceiverSocket
(
cmdPair
[
1
]);
c
t
a
::
SmartFd
cmdSenderSocket
(
cmdPair
[
0
]);
c
t
a
::
SmartFd
cmdReceiverSocket
(
cmdPair
[
1
]);
int
reaperPair
[
2
]
=
{
-
1
,
-
1
};
ASSERT_EQ
(
0
,
socketpair
(
AF_UNIX
,
SOCK_STREAM
,
0
,
reaperPair
));
ca
stor
::
utils
::
SmartFd
reaperSenderSocket
(
reaperPair
[
0
]);
ca
stor
::
utils
::
SmartFd
reaperReceiverSocket
(
reaperPair
[
1
]);
c
t
a
::
SmartFd
reaperSenderSocket
(
reaperPair
[
0
]);
c
t
a
::
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
));
ca
stor
::
utils
::
SmartFd
cmdSenderSocket
(
cmdPair
[
0
]);
ca
stor
::
utils
::
SmartFd
cmdReceiverSocket
(
cmdPair
[
1
]);
c
t
a
::
SmartFd
cmdSenderSocket
(
cmdPair
[
0
]);
c
t
a
::
SmartFd
cmdReceiverSocket
(
cmdPair
[
1
]);
int
reaperPair
[
2
]
=
{
-
1
,
-
1
};
ASSERT_EQ
(
0
,
socketpair
(
AF_UNIX
,
SOCK_STREAM
,
0
,
reaperPair
));
ca
stor
::
utils
::
SmartFd
reaperSenderSocket
(
reaperPair
[
0
]);
ca
stor
::
utils
::
SmartFd
reaperReceiverSocket
(
reaperPair
[
1
]);
c
t
a
::
SmartFd
reaperSenderSocket
(
reaperPair
[
0
]);
c
t
a
::
SmartFd
reaperReceiverSocket
(
reaperPair
[
1
]);
const
std
::
string
programName
=
"unittests"
;
const
std
::
string
hostName
=
"hostName"
;
...
...
tapeserver/castor/tape/tapeserver/daemon/TapeDaemon.cpp
View file @
8a160874
...
...
@@ -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>
...
...
tapeserver/castor/utils/CMakeLists.txt
View file @
8a160874
...
...
@@ -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
}
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment