Little patch

Albert 'TSDgeos' Astals Cid <[email protected]>
Newsgroups gmane.comp.kde.devel.atlantik
Message-ID <[email protected]>
It corrects a segmentation fault added for my previous patch :-/

If you openend atlantik and closed it, it segfaulted, because m_job was not 
initialized to NULL.

I've also added a timer, if the connection doesn't makes signals of life 
(slotData) in less than 10 seconds the job is cancelled as i think it is 
pretty safe to think that the connection is having problems.

Along with this, now when you click on "Refresh server list " the button 
becomes not enabled, because previously you could click hundred of times and 
it started a hundred of m_job

What do you think of it?

_______________________________________________
atlantik-devel mailing list
[email protected]
http://mail.kde.org/mailman/listinfo/atlantik-devel
diff (text/x-diff, 4.1 KB)
? diff
Index: monopigator.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/monopigator.cpp,v
retrieving revision 1.12
diff -u -r1.12 monopigator.cpp
--- monopigator.cpp	27 May 2003 21:03:19 -0000	1.12
+++ monopigator.cpp	2 Jun 2003 18:11:54 -0000
@@ -22,11 +22,12 @@
 Monopigator::Monopigator()
 {
 	m_downloadData = 0;
+	m_job = NULL;
 }
 
 Monopigator::~Monopigator()
 {
-	if (m_job != NULL) m_job -> kill();
+	if (m_job) m_job -> kill();
 }
 
 void Monopigator::loadData(const KURL &url)
@@ -40,12 +41,17 @@
 	m_job = KIO::get(url.url(), true, false);
 	m_job->addMetaData(QString::fromLatin1("UserAgent"), QString::fromLatin1("Atlantik/" ATLANTIK_VERSION_STRING));
 
+	m_timer = new QTimer(this);
+	m_timer->start(10 *1000, true);
+
 	connect(m_job, SIGNAL(data(KIO::Job *, const QByteArray &)), SLOT(slotData(KIO::Job *, const QByteArray &)));
 	connect(m_job, SIGNAL(result(KIO::Job *)), SLOT(slotResult(KIO::Job *)));
+	connect(m_timer, SIGNAL(timeout()), SLOT(slotTimeout()));
 }
 
 void Monopigator::slotData(KIO::Job *, const QByteArray &data)
 {
+	m_timer->stop();
 	m_downloadData->writeBlock(data.data(), data.size());
 }
 
@@ -53,6 +59,13 @@
 {
 	processData(m_downloadData->buffer(), !job->error());
 	m_job = NULL;
+}
+
+void Monopigator::slotTimeout()
+{
+	if (m_job) m_job -> kill();
+	m_job = NULL;
+	emit timeout();
 }
 
 void Monopigator::processData(const QByteArray &data, bool okSoFar)
Index: monopigator.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/monopigator.h,v
retrieving revision 1.11
diff -u -r1.11 monopigator.h
--- monopigator.h	27 May 2003 21:03:19 -0000	1.11
+++ monopigator.h	2 Jun 2003 18:11:55 -0000
@@ -19,6 +19,7 @@
 
 #include <qobject.h>
 #include <qbuffer.h>
+#include <qtimer.h>
 
 #include <kio/job.h>
 #include <kurl.h>
@@ -35,16 +36,19 @@
 signals:
 	void monopigatorAdd(QString host, QString port, QString version, int users);
 	void finished();
+	void timeout();
 
 private slots:
 	void slotData(KIO::Job *, const QByteArray &);
 	void slotResult(KIO::Job *);
+	void slotTimeout();
 
 private:
 	void processData(const QByteArray &, bool = true);
 
 	QBuffer *m_downloadData;
 	KIO::Job *m_job;
+	QTimer *m_timer;
 };
 
 #endif
Index: selectserver_widget.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/selectserver_widget.cpp,v
retrieving revision 1.25
diff -u -r1.25 selectserver_widget.cpp
--- selectserver_widget.cpp	27 May 2003 21:03:19 -0000	1.25
+++ selectserver_widget.cpp	2 Jun 2003 18:11:55 -0000
@@ -80,6 +80,7 @@
 
 	connect(m_monopigator, SIGNAL(monopigatorAdd(QString, QString, QString, int)), this, SLOT(slotMonopigatorAdd(QString, QString, QString, int)));
 	connect(m_monopigator, SIGNAL(finished()), SLOT(monopigatorFinished()));
+	connect(m_monopigator, SIGNAL(timeout()), SLOT(monopigatorTimeout()));
 
 	// Until we have a good way to use start a local monopd server, disable this button
 //	m_localGameButton->setEnabled(false);
@@ -138,6 +139,13 @@
 void SelectServer::monopigatorFinished()
 {
 	status_label->setText(i18n("Retrieved server list."));
+	m_refreshButton->setEnabled(true);
+}
+
+void SelectServer::monopigatorTimeout()
+{
+	status_label->setText(i18n("Error while retrieving the server list."));
+	m_refreshButton->setEnabled(true);
 }
 
 void SelectServer::validateRadioButtons()
@@ -183,7 +191,10 @@
 
 	checkLocalServer();
 	if (useMonopigator)
+	{
+		m_refreshButton->setEnabled(false);
 		initMonopigator();
+	}
 }
 
 void SelectServer::slotAddServer()
Index: selectserver_widget.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/selectserver_widget.h,v
retrieving revision 1.13
diff -u -r1.13 selectserver_widget.h
--- selectserver_widget.h	6 Mar 2003 13:42:53 -0000	1.13
+++ selectserver_widget.h	2 Jun 2003 18:11:55 -0000
@@ -56,6 +56,7 @@
 		void slotLocalConnected();
 		void slotLocalError();
 		void monopigatorFinished();
+		void monopigatorTimeout();
 
 	signals:
 		void serverConnect(const QString host, int port);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.