summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/network/socket/qtcpserver/crashingServer/main.cpp')
-rw-r--r--tests/auto/network/socket/qtcpserver/crashingServer/main.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp b/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp
index 7cb65cd1a3..758a396a35 100644
--- a/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp
+++ b/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp
@@ -32,6 +32,9 @@
#if defined(Q_OS_WIN) && defined(Q_CC_MSVC)
# include <crtdbg.h>
#endif
+#ifdef Q_OS_UNIX
+# include <unistd.h>
+#endif
int main(int argc, char *argv[])
{
@@ -40,10 +43,26 @@ int main(int argc, char *argv[])
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
#endif
QCoreApplication app(argc, argv);
+ if (argc < 1) {
+ fprintf(stderr, "Need a port number\n");
+ return 1;
+ }
+ int port = QByteArray(argv[1]).toInt();
QTcpServer server;
- if (!server.listen(QHostAddress::LocalHost, 49199)) {
- qDebug("Failed to listen: %s", server.errorString().toLatin1().constData());
+ if (!server.listen(QHostAddress::LocalHost, port)) {
+ fprintf(stderr, "Failed to listen: %s\n", server.errorString().toLatin1().constData());
+ if (server.serverError() == QTcpSocket::AddressInUseError) {
+ // let's see if we can find the process that would be holding this
+ // still open
+#ifdef Q_OS_LINUX
+ static const char *ss_args[] = {
+ "ss", "-nap", "sport", "=", argv[1], nullptr
+ };
+ dup2(STDERR_FILENO, STDOUT_FILENO);
+ execvp(ss_args[0], const_cast<char **>(ss_args));
+#endif
+ }
return 1;
}