diff --git a/LCS/Stream/include/Stream/FileStream.h b/LCS/Stream/include/Stream/FileStream.h index a45a7990849f5ca164423d7aca72df29c22e823d..9af3c751064f3e14349c18806dbc8187c2bfdd5d 100644 --- a/LCS/Stream/include/Stream/FileStream.h +++ b/LCS/Stream/include/Stream/FileStream.h @@ -24,6 +24,7 @@ #define LOFAR_LCS_STREAM_FILE_STREAM_H #include <Stream/FileDescriptorBasedStream.h> +#include <string> namespace LOFAR { @@ -31,9 +32,9 @@ namespace LOFAR { class FileStream : public FileDescriptorBasedStream { public: - FileStream(const char *name); // read-only; existing file - FileStream(const char *name, int mode); // rd/wr; create file - FileStream(const char *name, int flags, int mode); // rd/wr; create file, use given flags + FileStream(const std::string &name); // read-only; existing file + FileStream(const std::string &name, int mode); // rd/wr; create file + FileStream(const std::string &name, int flags, int mode); // rd/wr; create file, use given flags virtual ~FileStream(); diff --git a/LCS/Stream/include/Stream/SocketStream.h b/LCS/Stream/include/Stream/SocketStream.h index 4bb4f5c1af84134b9dcae758c4c0c4d27f5f4437..007c570a72dac85c147334580394096df959def1 100644 --- a/LCS/Stream/include/Stream/SocketStream.h +++ b/LCS/Stream/include/Stream/SocketStream.h @@ -47,7 +47,7 @@ class SocketStream : public FileDescriptorBasedStream Client, Server }; - SocketStream(const char *hostname, uint16 _port, Protocol, Mode, time_t timeout = 0, const char *nfskey = 0); + SocketStream(const string &hostname, uint16 _port, Protocol, Mode, time_t timeout = 0, const string &nfskey = 0); virtual ~SocketStream(); void reaccept(time_t timeout = 0); // only for TCP server socket @@ -57,16 +57,16 @@ class SocketStream : public FileDescriptorBasedStream const Mode mode; private: - const char *hostname; + const string hostname; uint16 port; - const char *nfskey; + const string nfskey; int listen_sk; void accept(time_t timeout); - static std::string readkey(const char *nfskey, time_t &timeout); - static void writekey(const char *nfskey, uint16 port); - static void deletekey(const char *nfskey); + static std::string readkey(const string &nfskey, time_t &timeout); + static void writekey(const string &nfskey, uint16 port); + static void deletekey(const string &nfskey); }; } // namespace LOFAR diff --git a/LCS/Stream/src/FileStream.cc b/LCS/Stream/src/FileStream.cc index 59ca99f8e68b7c485a19eacdb2d4b16ec9d15815..55951be3874a77c89cd57fa9ddfb2f7c794133c1 100644 --- a/LCS/Stream/src/FileStream.cc +++ b/LCS/Stream/src/FileStream.cc @@ -33,23 +33,23 @@ namespace LOFAR { -FileStream::FileStream(const char *name) +FileStream::FileStream(const std::string &name) { - if ((fd = open(name, O_RDONLY)) < 0) + if ((fd = open(name.c_str(), O_RDONLY)) < 0) throw SystemCallException(std::string("open ") + name, errno, THROW_ARGS); } -FileStream::FileStream(const char *name, int mode) +FileStream::FileStream(const std::string &name, int mode) { - if ((fd = open(name, O_RDWR | O_CREAT | O_TRUNC, mode)) < 0) + if ((fd = open(name.c_str(), O_RDWR | O_CREAT | O_TRUNC, mode)) < 0) throw SystemCallException(std::string("open ") + name, errno, THROW_ARGS); } -FileStream::FileStream(const char *name, int flags, int mode) +FileStream::FileStream(const std::string &name, int flags, int mode) { - if ((fd = open(name, flags, mode)) < 0) + if ((fd = open(name.c_str(), flags, mode)) < 0) throw SystemCallException(std::string("open ") + name, errno, THROW_ARGS); } diff --git a/LCS/Stream/src/SocketStream.cc b/LCS/Stream/src/SocketStream.cc index 36809ca238d235ecffb28c2c75db698172bd5877..d69c98c5b4c20b276ea71029fe04b469f27e2ab7 100644 --- a/LCS/Stream/src/SocketStream.cc +++ b/LCS/Stream/src/SocketStream.cc @@ -65,7 +65,7 @@ static struct RandomState { } randomState; -SocketStream::SocketStream(const char *hostname, uint16 _port, Protocol protocol, Mode mode, time_t timeout, const char *nfskey) +SocketStream::SocketStream(const std::string &hostname, uint16 _port, Protocol protocol, Mode mode, time_t timeout, const std::string &nfskey) : protocol(protocol), mode(mode), @@ -97,7 +97,7 @@ SocketStream::SocketStream(const char *hostname, uint16 _port, Protocol protocol int retval; struct addrinfo *result; - if (mode == Client && nfskey) + if (mode == Client && nfskey != "") port = boost::lexical_cast<uint16>(readkey(nfskey, timeout)); if (mode == Server && autoPort) @@ -105,7 +105,7 @@ SocketStream::SocketStream(const char *hostname, uint16 _port, Protocol protocol snprintf(portStr, sizeof portStr, "%hu", port); - if ((retval = getaddrinfo(hostname, portStr, &hints, &result)) != 0) + if ((retval = getaddrinfo(hostname.c_str(), portStr, &hints, &result)) != 0) throw SystemCallException("getaddrinfo", retval, THROW_ARGS); // make sure result will be freed @@ -210,13 +210,13 @@ void SocketStream::reaccept( time_t timeout ) void SocketStream::accept( time_t timeout ) { - if (nfskey) + if (nfskey != "") writekey(nfskey, port); // make sure the key will be deleted struct D { ~D() { - if (nfskey) { + if (nfskey != "") { ScopedDelayCancellation dc; // unlink is a cancellation point try { @@ -227,7 +227,7 @@ void SocketStream::accept( time_t timeout ) } } - const char *nfskey; + const std::string &nfskey; } onDestruct = { nfskey }; (void)onDestruct; @@ -261,7 +261,7 @@ void SocketStream::setReadBufferSize(size_t size) } -std::string SocketStream::readkey(const char *nfskey, time_t &timeout) +std::string SocketStream::readkey(const std::string &nfskey, time_t &timeout) { for(;;) { // sync NFS @@ -279,7 +279,7 @@ std::string SocketStream::readkey(const char *nfskey, time_t &timeout) char portStr[16]; ssize_t len; - len = readlink(nfskey, portStr, sizeof portStr - 1); // reserve 1 character to insert \0 below + len = readlink(nfskey.c_str(), portStr, sizeof portStr - 1); // reserve 1 character to insert \0 below if (len >= 0) { portStr[len] = 0; @@ -300,20 +300,20 @@ std::string SocketStream::readkey(const char *nfskey, time_t &timeout) } } -void SocketStream::writekey(const char *nfskey, uint16 port) +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) < 0) + if (symlink(portStr, nfskey.c_str()) < 0) throw SystemCallException("symlink", errno, THROW_ARGS); } -void SocketStream::deletekey(const char *nfskey) +void SocketStream::deletekey(const std::string &nfskey) { - if (unlink(nfskey) < 0) + if (unlink(nfskey.c_str()) < 0) throw SystemCallException("unlink", errno, THROW_ARGS); }