From 379f344bb31b16b7800442c86bd925ea47b99fa4 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sat, 4 Oct 2014 12:52:55 -0500 Subject: Modify bindAndListen to allow suppression of warnings when bind failures are expected as part of normal operation This relates to Bug 1988 --- tdecore/ksock.cpp | 19 +++++++++++++++---- tdecore/ksock.h | 10 +++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/tdecore/ksock.cpp b/tdecore/ksock.cpp index 96526463a..57bfc26d1 100644 --- a/tdecore/ksock.cpp +++ b/tdecore/ksock.cpp @@ -20,6 +20,8 @@ * Boston, MA 02110-1301, USA. **/ +#define KSOCK_INTERNAL_C_COMPILATION 1 + #include #include @@ -312,7 +314,7 @@ bool TDEServerSocket::init( const char *_path ) d->ks = ks; if (d->bind) - return bindAndListen(); + return bindAndListen(false); return true; } @@ -326,11 +328,11 @@ bool TDEServerSocket::init( unsigned short int _port ) d->ks = ks; if (d->bind) - return bindAndListen(); + return bindAndListen(false); return true; } -bool TDEServerSocket::bindAndListen() +bool TDEServerSocket::bindAndListen(bool suppressFailureMessages) { if (d == NULL || d->ks == NULL) return false; @@ -339,7 +341,10 @@ bool TDEServerSocket::bindAndListen() int ret = d->ks->listen( SOMAXCONN ); if (ret < 0) { - kdWarning(170) << "Error listening on socket: " << ret << "\n"; + if (!suppressFailureMessages) + { + kdWarning(170) << "Error listening on socket for port " << d->ks->port() << ": " << ret << "\n"; + } delete d->ks; d->ks = NULL; sock = -1; @@ -432,4 +437,10 @@ TDEServerSocket::~TDEServerSocket() // ::close( sock ); } +// DEPRECATED +bool TDEServerSocket::bindAndListen() +{ + return bindAndListen(false); +} + #include "ksock.moc" diff --git a/tdecore/ksock.h b/tdecore/ksock.h index cdf4ad1ac..422e69b9b 100644 --- a/tdecore/ksock.h +++ b/tdecore/ksock.h @@ -282,9 +282,12 @@ public: * Binds the socket and start listening. This should only be called * once when the constructor was called with _bind false. * On error the socket will be closed. + * @param suppressFailureMessages suppress warning messages generated if the socket cannot be opened. * @return true on success. false on error. + * @warning If suppressFailureMessages is TRUE future debugging may be made more difficult. Only set it + * if your application expects to bind to unavailable ports, e.g. while scanning for open ports in a range. */ - bool bindAndListen(); + bool bindAndListen(bool suppressFailureMessages = false); /** * Returns the file descriptor associated with the socket. @@ -339,6 +342,11 @@ protected: int sock; private: + // DEPRECATED +#ifdef KSOCK_INTERNAL_C_COMPILATION + KDE_EXPORT bool bindAndListen(); +#endif // KSOCK_INTERNAL_C_COMPILATION + TDEServerSocket(const TDEServerSocket&); TDEServerSocket& operator=(const TDEServerSocket&); -- cgit v1.2.1