Commit 47511bc6 authored by Steven Murray's avatar Steven Murray
Browse files

I have removed the following "tape" class:

    castor::tape::SmartFd

The above class has been replaced by:

    castor::utils::SmartFd
parent 0d38d0c8
......@@ -27,8 +27,8 @@
#include "castor/exception/Internal.hpp"
#include "castor/exception/InvalidArgument.hpp"
#include "castor/tape/net/net.hpp"
#include "castor/tape/utils/SmartFd.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/utils/SmartFd.hpp"
#include "h/serrno.h"
#include "h/net.h"
......@@ -71,7 +71,7 @@ int castor::tape::net::createListenerSock(
}
// Create a socket
utils::SmartFd sock(socket(PF_INET, SOCK_STREAM, IPPROTO_TCP));
castor::utils::SmartFd sock(socket(PF_INET, SOCK_STREAM, IPPROTO_TCP));
if(sock.get() < 0) {
const int savedErrno = errno;
......@@ -720,7 +720,7 @@ int castor::tape::net::connectWithTimeout(
throw(castor::exception::TimeOut, castor::exception::Exception) {
// Create the socket for the new connection
utils::SmartFd smartSock(socket(sockDomain, sockType, sockProtocol));
castor::utils::SmartFd smartSock(socket(sockDomain, sockType, sockProtocol));
if(-1 == smartSock.get()) {
const int socketErrno = errno;
TAPE_THROW_CODE(errno,
......
......@@ -55,9 +55,9 @@
#include "castor/tape/tapegateway/FileToRecallStruct.hpp"
#include "castor/tape/tapegateway/NoMoreFiles.hpp"
#include "castor/tape/tapegateway/NotificationAcknowledge.hpp"
#include "castor/tape/utils/SmartFd.hpp"
#include "castor/tape/utils/SmartFdList.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/utils/utils.hpp"
#include "h/Ctape_constants.h"
#include "h/getconfent.h"
......@@ -131,7 +131,7 @@ castor::tape::tapebridge::BridgeProtocolEngine::BridgeProtocolEngine(
int castor::tape::tapebridge::BridgeProtocolEngine::acceptRtcpdConnection()
throw(castor::exception::Exception) {
utils::SmartFd connectedSock;
castor::utils::SmartFd connectedSock;
const int timeout = 5; // Seconds
bool connectionAccepted = false;
......@@ -716,7 +716,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
// Release the socket-descriptor from the catalogue
uint64_t tapebridgeTransId = 0;
utils::SmartFd catalogueSock(
castor::utils::SmartFd catalogueSock(
m_sockCatalogue.releaseClientMigrationReportSock(tapebridgeTransId));
// Check for a mismatch between the pending and catalogue socket-decriptors
......@@ -913,7 +913,7 @@ bool castor::tape::tapebridge::BridgeProtocolEngine::startMigrationSession()
m_tapebridgeTransactionCounter.next();
const uint64_t maxFiles = 1;
const uint64_t maxBytes = 1;
utils::SmartFd clientSock(m_clientProxy.sendFilesToMigrateListRequest(
castor::utils::SmartFd clientSock(m_clientProxy.sendFilesToMigrateListRequest(
tapebridgeTransId, maxFiles, maxBytes));
// Receive the reply
......@@ -1692,7 +1692,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
tapegateway::TAPE_GATEWAY == m_volume.clientType() ?
m_bulkRequestConfigParams.getBulkRequestMigrationMaxBytes().getValue() :
1;
utils::SmartFd clientSock(m_clientProxy.sendFilesToMigrateListRequest(
castor::utils::SmartFd clientSock(m_clientProxy.sendFilesToMigrateListRequest(
tapebridgeTransId, maxFiles, maxBytes));
try {
......@@ -1792,7 +1792,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
tapegateway::TAPE_GATEWAY == m_volume.clientType() ?
m_bulkRequestConfigParams.getBulkRequestRecallMaxBytes().getValue() :
1;
utils::SmartFd clientSock(m_clientProxy.sendFilesToRecallListRequest(
castor::utils::SmartFd clientSock(m_clientProxy.sendFilesToRecallListRequest(
tapebridgeTransId, maxFiles, maxBytes));
{
castor::dlf::Param params[] = {
......@@ -2340,7 +2340,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
// Send the report to the client
timeval connectDuration = {0, 0};
utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(report,
castor::utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(report,
connectDuration));
{
const double connectDurationDouble =
......@@ -2797,7 +2797,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
// Send the report message to the client (the tapegewayd daemon or the
// writetp command-line tool
timeval connectDuration = {0, 0};
utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(report,
castor::utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(report,
connectDuration));
{
const double connectDurationDouble =
......@@ -3583,7 +3583,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
// Send the report to the client and receive the reply
timeval connectDuration = {0, 0};
utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(
castor::utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(
listReport, connectDuration));
try {
m_clientProxy.receiveNotificationReplyAndClose(
......@@ -3658,7 +3658,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
// Send the report to the client and receive the reply
timeval connectDuration = {0, 0};
utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(
castor::utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(
listReport, connectDuration));
try {
m_clientProxy.receiveNotificationReplyAndClose(tapebridgeTransId,
......
......@@ -24,8 +24,8 @@
#include "castor/tape/net/net.hpp"
#include "castor/tape/tapebridge/ClientAddressLocal.hpp"
#include "castor/tape/utils/SmartFd.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/utils/utils.hpp"
#include <errno.h>
......@@ -95,7 +95,7 @@ int castor::tape::tapebridge::ClientAddressLocal::connectToClient(
timeval connectEndTime = {0, 0};
utils::getTimeOfDay(&connectStartTime, NULL);
utils::SmartFd smartConnectSock;
castor::utils::SmartFd smartConnectSock;
try {
smartConnectSock.reset(net::connectWithTimeout(
PF_LOCAL,
......
......@@ -41,8 +41,8 @@
#include "castor/tape/tapegateway/PingNotification.hpp"
#include "castor/tape/tapegateway/Volume.hpp"
#include "castor/tape/tapegateway/VolumeRequest.hpp"
#include "castor/tape/utils/SmartFd.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/utils/utils.hpp"
#include <memory>
......@@ -259,7 +259,7 @@ int castor::tape::tapebridge::ClientProxy::sendFilesToMigrateListRequest(
request.setMaxBytes(maxBytes);
// Send the request and return the socket-descriptor of the connection
utils::SmartFd clientSock;
castor::utils::SmartFd clientSock;
timeval connectDuration = {0, 0};
try {
clientSock.reset(connectAndSendMessage(request, connectDuration));
......
......@@ -46,9 +46,9 @@
#include "castor/tape/tapegateway/FileErrorReportStruct.hpp"
#include "castor/tape/tapegateway/VolumeRequest.hpp"
#include "castor/tape/tapegateway/Volume.hpp"
#include "castor/tape/utils/SmartFd.hpp"
#include "castor/tape/utils/SmartFdList.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/utils/SmartFd.hpp"
#include "h/common.h"
#include "h/Ctape_constants.h"
#include "h/rtcp_constants.h"
......@@ -128,7 +128,7 @@ void castor::tape::tapebridge::VdqmRequestHandler::run(void *param)
// Wrap the VDQM connection socket within a smart file-descriptor. When the
// smart file-descriptor goes out of scope it will close file-descriptor of
// the socket.
utils::SmartFd vdqmSock;
castor::utils::SmartFd vdqmSock;
{
castor::io::ServerSocket *tmpServerSocket =
(castor::io::ServerSocket*)param;
......@@ -245,8 +245,8 @@ void castor::tape::tapebridge::VdqmRequestHandler::run(void *param)
const unsigned short highPort = utils::getPortFromConfig(
"TAPEBRIDGE", "RTCPDHIGHPORT", TAPEBRIDGE_RTCPDHIGHPORT);
unsigned short chosenPort = 0;
utils::SmartFd listenSock(net::createListenerSock("127.0.0.1", lowPort,
highPort, chosenPort));
castor::utils::SmartFd listenSock(net::createListenerSock("127.0.0.1",
lowPort, highPort, chosenPort));
// Get and log the IP, host name, port and socket file-descriptor of the
// callback socket
......@@ -436,8 +436,8 @@ void castor::tape::tapebridge::VdqmRequestHandler::exceptionThrowingRun(
// Accept the initial incoming RTCPD callback connection.
// Wrap the socket file descriptor in a smart file descriptor so that it is
// guaranteed to be closed if it goes out of scope.
utils::SmartFd rtcpdInitialSock(net::acceptConnection(bridgeCallbackSockFd,
RTCPDCALLBACKTIMEOUT));
castor::utils::SmartFd rtcpdInitialSock(
net::acceptConnection(bridgeCallbackSockFd, RTCPDCALLBACKTIMEOUT));
// Log the initial callback connection from RTCPD
try {
......
......@@ -30,7 +30,6 @@ set (TAPE_UTILS_LIB_SRC_FILES
ShutdownBoolFunctor.cpp
ScopedLock.cpp
SmartFILEPtr.cpp
SmartFd.cpp
SmartFdList.cpp
Timer.cpp
utils.cpp)
......
/******************************************************************************
* castor/tape/utils/SmartFd.cpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
*
* @author Nicola.Bessone@cern.ch Steven.Murray@cern.ch
*****************************************************************************/
#include "castor/tape/utils/SmartFd.hpp"
#include <errno.h>
#include <unistd.h>
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
castor::tape::utils::SmartFd::SmartFd() throw():
m_fd(-1), m_closedCallback(NULL) {
}
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
castor::tape::utils::SmartFd::SmartFd(const int fd) throw():
m_fd(fd), m_closedCallback(NULL) {
}
//-----------------------------------------------------------------------------
// setClosedCallback
//-----------------------------------------------------------------------------
void castor::tape::utils::SmartFd::setClosedCallback
(const int, ClosedCallback closedCallback) throw() {
m_closedCallback = closedCallback;
}
//-----------------------------------------------------------------------------
// reset
//-----------------------------------------------------------------------------
void castor::tape::utils::SmartFd::reset(const int fd = -1) throw() {
// If the new file descriptor is not the one already owned
if(fd != m_fd) {
// If this SmartFd still owns a file descriptor, then close it
if(m_fd >= 0) {
close(m_fd);
if(m_closedCallback) {
try {
(*m_closedCallback)(m_fd);
} catch(...) {
// Ignore any exception thrown my the m_closedCallback function
// because this reset function maybe called by the destructor of
// SmartFd
}
}
}
// Take ownership of the new file descriptor
m_fd = fd;
}
}
//-----------------------------------------------------------------------------
// SmartFd assignment operator
//-----------------------------------------------------------------------------
castor::tape::utils::SmartFd
&castor::tape::utils::SmartFd::operator=(SmartFd& obj) throw() {
reset(obj.release());
return *this;
}
//-----------------------------------------------------------------------------
// destructor
//-----------------------------------------------------------------------------
castor::tape::utils::SmartFd::~SmartFd() {
reset();
}
//-----------------------------------------------------------------------------
// get
//-----------------------------------------------------------------------------
int castor::tape::utils::SmartFd::get() const throw() {
return m_fd;
}
//-----------------------------------------------------------------------------
// release
//-----------------------------------------------------------------------------
int castor::tape::utils::SmartFd::release()
throw(castor::exception::Exception) {
// If this SmartFd does not own a file descriptor
if(m_fd < 0) {
castor::exception::Exception ex(EPERM);
ex.getMessage() <<
"Smart file-descriptor does not own a file-descriptor";
throw(ex);
}
const int tmpFd = m_fd;
// A negative number indicates this SmartFd does not own a file descriptor
m_fd = -1;
return tmpFd;
}
/******************************************************************************
* castor/tape/utils/SmartFd.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Nicola.Bessone@cern.ch Steven.Murray@cern.ch
*****************************************************************************/
#ifndef CASTOR_TAPE_UTILS_SMARTFD
#define CASTOR_TAPE_UTILS_SMARTFD
#include "castor/exception/Exception.hpp"
namespace castor {
namespace tape {
namespace utils {
/**
* A smart file descriptor that owns a basic file descriptor. When the smart
* file descriptor goes out of scope, it will close the file descriptor it
* owns.
*/
class SmartFd {
public:
/**
* A pointer to a callback function that will called by the Smart
* immediately after the SmartFd has closed the file-descriptor it owns.
*
* Please note that any exception thrown by this function will be ignored
* because this function maybe called by the destructor of SmartFd.
*
* @param closedfd The value of the file descriptor that was closed.
*/
typedef void (*ClosedCallback)(int closedfd);
/**
* Constructor.
*
*/
SmartFd() throw();
/**
* Constructor.
*
* @param fd The file descriptor to be owned by the smart file
* descriptor.
*/
SmartFd(const int fd) throw();
/**
* Sets the function to be called back by the SmartFd immediately after
* the SmartFd has closed the file-descriptor it owns.
*
* Setting the callback function to NULL means that no function will be
* called.
*
* Please note any exception thrown by the callback function will be
* ignored because the callback function maybe called by the destructor of
* SmartFd.
*
* @param fd The file descriptor to be owned by the smart file
* descriptor.
* @param closedCallback This function will be called immediately after
* the SmartFd has closed the file-descriptor it owns.
* Please note that any exception thrown by this
* function will be ignored because this function
* maybe called by the destructor of SmartFd.
*/
void setClosedCallback(const int fd, ClosedCallback closedCallback) throw();
/**
* Take ownership of the specified file descriptor, closing the previously
* owned file descriptor if there is one and it is not the same as the one
* specified.
*
* @param fd The file descriptor to be owned, defaults to -1 if not
* specified, where a negative number means this SmartFd does not
* own a file descriptor.
*/
void reset(const int fd) throw();
/**
* SmartFd assignment operator.
*
* This function does the following:
* <ul>
* <li> Calls release on the previous owner (obj);
* <li> Closes the file descriptor of this object if it already owns one.
* <li> Makes this object the owner of the file descriptor released from
* the previous owner (obj).
* </ul>
*/
SmartFd &operator=(SmartFd& obj) throw();
/**
* Destructor.
*
* Closes the owned file descriptor if there is one.
*/
~SmartFd();
/**
* Returns the owned file descriptor or a negative number if this SmartFd
* does not own a file descriptor.
*
* @return The owned file desccriptor.
*/
int get() const throw();
/**
* Releases the owned file descriptor.
*
* @return The released file descriptor.
*/
int release() throw(castor::exception::Exception);
private:
/**
* The owned file descriptor. A negative value means this SmartFd does not
* own a file descriptor..
*/
int m_fd;
/**
* The function to be called immediately after the SmartFd has closed its
* file-descriptor. A value of null means no function will be called.
*/
ClosedCallback m_closedCallback;
/**
* Private copy-constructor to prevent users from trying to create a new
* copy of an object of this class.
* Not implemented so that it cannot be called
*/
SmartFd(const SmartFd &obj) throw();
}; // class SmartFd
} // namespace utils
} // namespace tape
} // namespace castor
#endif // CASTOR_TAPE_UTILS_SMARTFD
......@@ -155,4 +155,4 @@ private:
} // namespace utils
} // namespace castor
#endif // CASTOR_TAPE_UTILS_SMARTFD
#endif // CASTOR_UTILS_SMARTFD
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