summaryrefslogtreecommitdiffstats
path: root/tdecore
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2014-10-04 12:52:55 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2014-10-04 12:52:55 -0500
commit379f344bb31b16b7800442c86bd925ea47b99fa4 (patch)
tree10ad38bc2cadc40d3f19d7dd1d75cbd370ed7689 /tdecore
parent319f69a280df213c70a2bf18d999d29641d45fc7 (diff)
downloadtdelibs-379f344bb31b16b7800442c86bd925ea47b99fa4.tar.gz
tdelibs-379f344bb31b16b7800442c86bd925ea47b99fa4.zip
Modify bindAndListen to allow suppression of warnings when bind failures are expected as part of normal operation
This relates to Bug 1988
Diffstat (limited to 'tdecore')
-rw-r--r--tdecore/ksock.cpp19
-rw-r--r--tdecore/ksock.h10
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 <config.h>
#include <sys/types.h>
@@ -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&);