diff options
Diffstat (limited to 'unix/x0vncserver/x0vncserver.cxx')
-rw-r--r-- | unix/x0vncserver/x0vncserver.cxx | 55 |
1 files changed, 23 insertions, 32 deletions
diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx index ffaf5788..49c95137 100644 --- a/unix/x0vncserver/x0vncserver.cxx +++ b/unix/x0vncserver/x0vncserver.cxx @@ -90,10 +90,10 @@ static const char* defaultDesktopName() return ""; struct passwd* pwent = getpwuid(getuid()); - if (pwent == NULL) + if (pwent == nullptr) return ""; - int len = snprintf(NULL, 0, "%s@%s", pwent->pw_name, hostname.data()); + int len = snprintf(nullptr, 0, "%s@%s", pwent->pw_name, hostname.data()); if (len < 0) return ""; @@ -154,19 +154,19 @@ class FileTcpFilter : public TcpFilter public: FileTcpFilter(const char *fname) - : TcpFilter("-"), fileName(NULL), lastModTime(0) + : TcpFilter("-"), fileName(nullptr), lastModTime(0) { - if (fname != NULL) + if (fname != nullptr) fileName = strdup((char *)fname); } virtual ~FileTcpFilter() { - if (fileName != NULL) + if (fileName != nullptr) free(fileName); } - virtual bool verifyConnection(Socket* s) + bool verifyConnection(Socket* s) override { if (!reloadRules()) { vlog.error("Could not read IP filtering rules: rejecting all clients"); @@ -182,7 +182,7 @@ protected: bool reloadRules() { - if (fileName == NULL) + if (fileName == nullptr) return true; struct stat st; @@ -192,7 +192,7 @@ protected: if (st.st_mtime != lastModTime) { // Actually reload only if the file was modified FILE *fp = fopen(fileName, "r"); - if (fp == NULL) + if (fp == nullptr) return false; // Remove all the rules from the parent class @@ -225,14 +225,14 @@ private: bool readLine(char *buf, int bufSize, FILE *fp) { - if (fp == NULL || buf == NULL || bufSize == 0) + if (fp == nullptr || buf == nullptr || bufSize == 0) return false; - if (fgets(buf, bufSize, fp) == NULL) + if (fgets(buf, bufSize, fp) == nullptr) return false; char *ptr = strchr(buf, '\n'); - if (ptr != NULL) { + if (ptr != nullptr) { *ptr = '\0'; // remove newline at the end } else { if (!feof(fp)) { @@ -353,7 +353,7 @@ int main(int argc, char** argv) const char *addr = interface; if (strcasecmp(addr, "all") == 0) - addr = 0; + addr = nullptr; if (localhostOnly) createLocalTcpListeners(&tcp_listeners, (int)rfbport); else @@ -368,10 +368,8 @@ int main(int argc, char** argv) FileTcpFilter fileTcpFilter(hostsFile); if (strlen(hostsFile) != 0) - for (std::list<SocketListener*>::iterator i = listeners.begin(); - i != listeners.end(); - i++) - (*i)->setFilter(&fileTcpFilter); + for (SocketListener* listener : listeners) + listener->setFilter(&fileTcpFilter); } if (listeners.empty()) { @@ -395,10 +393,8 @@ int main(int argc, char** argv) FD_ZERO(&wfds); FD_SET(ConnectionNumber(dpy), &rfds); - for (std::list<SocketListener*>::iterator i = listeners.begin(); - i != listeners.end(); - i++) - FD_SET((*i)->getFd(), &rfds); + for (SocketListener* listener : listeners) + FD_SET(listener->getFd(), &rfds); server.getSockets(&sockets); int clients_connected = 0; @@ -436,8 +432,8 @@ int main(int argc, char** argv) // Do the wait... sched.sleepStarted(); - int n = select(FD_SETSIZE, &rfds, &wfds, 0, - wait_ms ? &tv : NULL); + int n = select(FD_SETSIZE, &rfds, &wfds, nullptr, + wait_ms ? &tv : nullptr); sched.sleepFinished(); if (n < 0) { @@ -450,11 +446,9 @@ int main(int argc, char** argv) } // Accept new VNC connections - for (std::list<SocketListener*>::iterator i = listeners.begin(); - i != listeners.end(); - i++) { - if (FD_ISSET((*i)->getFd(), &rfds)) { - Socket* sock = (*i)->accept(); + for (SocketListener* listener : listeners) { + if (FD_ISSET(listener->getFd(), &rfds)) { + Socket* sock = listener->accept(); if (sock) { server.addSocket(sock); } else { @@ -494,11 +488,8 @@ int main(int argc, char** argv) TXWindow::handleXEvents(dpy); // Run listener destructors; remove UNIX sockets etc - for (std::list<SocketListener*>::iterator i = listeners.begin(); - i != listeners.end(); - i++) { - delete *i; - } + for (SocketListener* listener : listeners) + delete listener; vlog.info("Terminated"); return 0; |