Commit c3029df9 authored by Steven Murray's avatar Steven Murray
Browse files

Improved io::getSockHostName() and io::getPeerHostName()

parent bb5eedc0
......@@ -457,11 +457,7 @@ castor::io::IpAndPort castor::io::getPeerIpPort(
//------------------------------------------------------------------------------
// getSockHostName
//------------------------------------------------------------------------------
void castor::io::getSockHostName(
const int socketFd,
char *const buf,
const size_t len)
{
std::string castor::io::getSockHostName(const int socketFd) {
// Throw an exception if socketFd is invalid
if(socketFd < 0) {
......@@ -498,7 +494,7 @@ void castor::io::getSockHostName(
throw ex;
}
utils::copyString(buf, len, hostName);
return hostName;
}
//------------------------------------------------------------------------------
......@@ -557,12 +553,7 @@ void castor::io::getSockIpHostnamePort(
//------------------------------------------------------------------------------
// getPeerHostName
//------------------------------------------------------------------------------
void castor::io::getPeerHostName(
const int socketFd,
char *const buf,
const size_t len)
{
std::string castor::io::getPeerHostName(const int socketFd) {
// Throw an exception if socketFd is invalid
if(socketFd < 0) {
castor::exception::InvalidArgument ex;
......@@ -601,7 +592,7 @@ void castor::io::getPeerHostName(
throw ex;
}
utils::copyString(buf, len, hostName);
return hostName;
}
}
......
......@@ -217,8 +217,7 @@ int acceptConnection(
* @param socketFd The socket file descriptor.
* @return The IP and port number of the specified socket.
*/
IpAndPort getSockIpPort(const int socketFd)
;
IpAndPort getSockIpPort(const int socketFd);
/**
* Gets the peer IP and port number of the specified socket.
......@@ -226,35 +225,15 @@ IpAndPort getSockIpPort(const int socketFd)
* @param socketFd The socket file descriptor.
* @return The IP and port number of the specified socket.
*/
IpAndPort getPeerIpPort(const int socketFd)
;
IpAndPort getPeerIpPort(const int socketFd);
/**
* Gets the locally-bound host name of the specified socket.
*
* @param socketFd The socket file descriptor.
* @param buf The buffer into which the hostname should written to.
* @param len The length of the buffer into which the host name should be
* written to.
* @return The host name.
*/
void getSockHostName(
const int socketFd,
char *const buf,
const size_t len)
;
/**
* Gets the locally-bound host name of the specified socket.
*
* @param socketFd The socket file descriptor.
* @param buf The buffer into which the hostname should written to.
*/
template<int n> static void getSockHostName(
const int socketFd,
char (&buf)[n])
{
getSockHostName(socketFd, buf, n);
}
std::string getSockHostName(const int socketFd);
/**
* Gets the locally-bound IP, host name and port of the specified socket.
......@@ -294,28 +273,10 @@ template<int n> static void getSockIpHostnamePort(
* Gets the peer host name of the specified connection.
*
* @param socketFd The socket file descriptor of the connection.
* @param buf The buffer into which the hostname should written to.
* @param len The length of the buffer into which the host name should be
* written to.
* @return The peer host name.
*/
void getPeerHostName(
const int socketFd,
char *const buf,
const size_t len)
;
/**
* Gets the peer host name of the specified connection.
*
* @param socketFd The socket file descriptor of the connection.
* @param buf The buffer into which the hostname should written to.
*/
template<int n> static void getPeerHostName(
const int socketFd,
char (&buf)[n])
{
getPeerHostName(socketFd, buf, n);
}
std::string getPeerHostName(const int socketFd);
/**
* Writes the string form of specified IP using the specified output
......
......@@ -176,10 +176,8 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
const int connectedSock)
{
try {
char hostName[io::HOSTNAMEBUFLEN];
const io::IpAndPort peerIpAndPort = io::getPeerIpPort(connectedSock);
io::getPeerHostName(connectedSock, hostName);
const std::string hostName = io::getPeerHostName(connectedSock);
castor::dlf::Param params[] = {
castor::dlf::Param("mountTransactionId", m_jobRequest.volReqId ),
......
......@@ -146,9 +146,8 @@ void castor::tape::tapebridge::VdqmRequestHandler::run(void *param)
// Log the connection from the VDQM
{
char hostName[io::HOSTNAMEBUFLEN];
const io::IpAndPort peerIpAndPort = io::getPeerIpPort(vdqmSock.get());
io::getPeerHostName(vdqmSock.get(), hostName);
const std::string hostName = io::getPeerHostName(vdqmSock.get());
castor::dlf::Param params[] = {
castor::dlf::Param("IP" ,
......@@ -440,11 +439,9 @@ void castor::tape::tapebridge::VdqmRequestHandler::exceptionThrowingRun(
// Log the initial callback connection from RTCPD
try {
char hostName[io::HOSTNAMEBUFLEN];
const io::IpAndPort peerIpAndPort =
io::getPeerIpPort(rtcpdInitialSock.get());
io::getPeerHostName(rtcpdInitialSock.get(), hostName);
const std::string hostName = io::getPeerHostName(rtcpdInitialSock.get());
castor::dlf::Param params[] = {
castor::dlf::Param("volReqId", jobRequest.volReqId ),
......
......@@ -105,7 +105,7 @@ void castor::tape::tapegateway::WorkerThread::run(void* arg)
std::auto_ptr<castor::io::ServerSocket> sock((castor::io::ServerSocket*)arg);
try {
sock->getPeerIp(requester.port, requester.ip);
io::getPeerHostName(sock->socket(), requester.hostName);
requester.hostName = io::getPeerHostName(sock->socket());
} catch(castor::exception::Exception& e) {
// "Exception caught : ignored" message
castor::dlf::Param params[] =
......
......@@ -76,7 +76,7 @@ namespace tapegateway{
hostName[0]='\0';
};
virtual ~requesterInfo() throw() {};
char hostName[castor::io::HOSTNAMEBUFLEN];
std::string hostName;
unsigned short port;
unsigned long ip;
// Helper converting requester structure into a context string
......
......@@ -432,9 +432,7 @@ void castor::tape::tpcp::TpcpCommand::executeCommand() {
castor::utils::writeTime(os, now, TIMEFORMAT);
os << " Selected tape server is ";
char hostName[io::HOSTNAMEBUFLEN];
io::getPeerHostName(connectionSockFd, hostName);
const std::string hostName = io::getPeerHostName(connectionSockFd);
os << hostName << std::endl;
}
......
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