Skip to content
Snippets Groups Projects
Commit c1f9fc35 authored by Jan David Mol's avatar Jan David Mol
Browse files

Task #7345: Removed depricated nfskey functionality, resolving an obscure...

Task #7345: Removed depricated nfskey functionality, resolving an obscure crash of tPortBroker on kis001
parent 31290a8c
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,7 @@ class SocketStream : public FileDescriptorBasedStream
};
SocketStream(const std::string &hostname, uint16 _port, Protocol, Mode,
time_t deadline = 0, const std::string &nfskey = "", bool doAccept = true);
time_t deadline = 0, bool doAccept = true);
virtual ~SocketStream();
FileDescriptorBasedStream *detach();
......@@ -73,16 +73,9 @@ class SocketStream : public FileDescriptorBasedStream
private:
const std::string hostname;
uint16 port;
const std::string nfskey;
int listen_sk;
void accept(time_t timeout);
static void syncNFS();
static std::string readkey(const std::string &nfskey, time_t deadline);
static void writekey(const std::string &nfskey, uint16 port);
static void deletekey(const std::string &nfskey);
};
EXCEPTION_CLASS(TimeOutException, LOFAR::Exception);
......
......@@ -62,7 +62,7 @@ PortBroker &PortBroker::instance()
PortBroker::PortBroker( uint16 port )
:
SocketStream( "0.0.0.0", port, TCP, Server, 0, "", false ),
SocketStream( "0.0.0.0", port, TCP, Server, 0, false ),
itsDone(false)
{
}
......
......@@ -74,13 +74,12 @@ namespace {
};
SocketStream::SocketStream(const std::string &hostname, uint16 _port, Protocol protocol,
Mode mode, time_t deadline, const std::string &nfskey, bool doAccept)
Mode mode, time_t deadline, bool doAccept)
:
protocol(protocol),
mode(mode),
hostname(hostname),
port(_port),
nfskey(nfskey),
listen_sk(-1)
{
const std::string description = str(boost::format("%s:%s:%s")
......@@ -116,9 +115,6 @@ SocketStream::SocketStream(const std::string &hostname, uint16 _port, Protocol p
int retval;
struct addrinfo *result;
if (mode == Client && nfskey != "")
port = boost::lexical_cast<uint16>(readkey(nfskey, deadline));
if (mode == Server && autoPort)
port = MINPORT + static_cast<unsigned short>((MAXPORT - MINPORT) * erand48(randomState.xsubi)); // erand48() not thread safe, but not a problem.
......@@ -252,27 +248,6 @@ void SocketStream::reaccept(time_t deadline)
void SocketStream::accept(time_t deadline)
{
if (nfskey != "")
writekey(nfskey, port);
// make sure the key will be deleted
struct D {
~D() {
if (nfskey != "") {
ScopedDelayCancellation dc; // unlink is a cancellation point
try {
deletekey(nfskey);
} catch (Exception &ex) {
LOG_ERROR_STR("Exception in destructor: " << ex);
}
}
}
const std::string nfskey;
} onDestruct = { nfskey };
(void)onDestruct;
if (deadline > 0) {
fd_set fds;
......@@ -308,72 +283,6 @@ void SocketStream::setReadBufferSize(size_t size)
}
void SocketStream::syncNFS()
{
// sync NFS
DIR *dir = opendir(".");
if (!dir)
THROW_SYSCALL("opendir");
struct dirent entry;
struct dirent *result;
if (readdir_r(dir, &entry, &result) != 0 || !result)
THROW_SYSCALL("readdir_r");
if (closedir(dir) != 0)
THROW_SYSCALL("closedir");
}
std::string SocketStream::readkey(const std::string &nfskey, time_t deadline)
{
for(;;) {
char portStr[16];
ssize_t len;
syncNFS();
len = readlink(nfskey.c_str(), portStr, sizeof portStr - 1); // reserve 1 character to insert \0 below
if (len >= 0) {
portStr[len] = 0;
return std::string(portStr);
}
if (deadline > 0 && deadline <= time(0))
THROW(TimeOutException, "client socket");
if (usleep(999999) < 0) { // near 1 sec; max portably safe arg val
// interrupted by a signal handler -- abort to allow this thread to
// be forced to continue after receiving a SIGINT, as with any other
// system call
THROW_SYSCALL("usleep");
}
}
}
void SocketStream::writekey(const std::string &nfskey, uint16 port)
{
char portStr[16];
snprintf(portStr, sizeof portStr, "%hu", port);
// Symlinks can be atomically created over NFS
if (symlink(portStr, nfskey.c_str()) < 0)
THROW_SYSCALL("symlink");
}
void SocketStream::deletekey(const std::string &nfskey)
{
syncNFS();
if (unlink(nfskey.c_str()) < 0)
THROW_SYSCALL("unlink");
}
void SocketStream::setTimeout(double timeout)
{
ASSERT(timeout >= 0.0);
......
......@@ -49,12 +49,8 @@ namespace LOFAR
return new SocketStream(split[1].c_str(), boost::lexical_cast<unsigned short>(split[2]), SocketStream::UDP, asServer ? SocketStream::Server : SocketStream::Client, deadline);
else if (split.size() == 3 && split[0] == "tcp")
return new SocketStream(split[1].c_str(), boost::lexical_cast<unsigned short>(split[2]), SocketStream::TCP, asServer ? SocketStream::Server : SocketStream::Client, deadline);
else if (split.size() == 3 && split[0] == "udpkey")
return new SocketStream(split[1].c_str(), 0, SocketStream::UDP, asServer ? SocketStream::Server : SocketStream::Client, deadline, split[2].c_str());
else if (split.size() == 4 && split[0] == "tcpbroker")
return asServer ? static_cast<Stream*>(new PortBroker::ServerStream(split[3])) : static_cast<Stream*>(new PortBroker::ClientStream(split[1], boost::lexical_cast<unsigned short>(split[2]), split[3]));
else if (split.size() == 3 && split[0] == "tcpkey")
return new SocketStream(split[1].c_str(), 0, SocketStream::TCP, asServer ? SocketStream::Server : SocketStream::Client, deadline, split[2].c_str());
else if (split.size() > 1 && split[0] == "file") {
// don't use split[1] to allow : in filenames
const std::string filename = descriptor.substr(5);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment