MCPcopy Create free account
hub / github.com/QNapi/qnapi / init

Method init

gui/src/qcumber/qinterprocesschannel.cpp:211–286  ·  view source on GitHub ↗

! \internal */

Source from the content-addressed store, hash-verified

209 \internal
210*/
211void QInterProcessChannel::init() {
212 while (isRunning()) quit();
213
214 if (pServerTimer) {
215 pServerTimer->stop();
216 delete pServerTimer;
217 pServerTimer = 0;
218 }
219
220 bool ok = true;
221
222 m_port = 0;
223 m_addr = QHostAddress::LocalHost;
224
225 pServer = new QTcpServer(this);
226 pServer->listen(m_addr, m_port);
227
228 connect(pServer, SIGNAL(newConnection()), this, SLOT(connection()));
229
230 if (QFile::exists(rcFile)) {
231 /*
232 found a server config file, let us assume it is from a running server
233 */
234 // qDebug("checking old server...");
235
236 QSettings conf(rcFile, QSettings::IniFormat);
237
238 m_port = conf.value("port").toUInt();
239 m_addr = QHostAddress(conf.value("address").toString());
240
241 QTcpSocket *pSocket = new QTcpSocket(this);
242
243 if (!m_addr.isNull() && m_port) {
244 pSocket->connectToHost(m_addr, m_port);
245 ok = pSocket->waitForConnected(WAIT_TIMEOUT);
246
247 if (ok) ok &= (bool)pSocket->write("--check");
248 if (ok) ok &= (bool)pSocket->waitForBytesWritten(WAIT_TIMEOUT);
249 if (ok) ok &= (bool)pSocket->waitForReadyRead(WAIT_TIMEOUT);
250 if (ok) ok &= (pSocket->readAll() == "[ALIVE]");
251
252 } else {
253 ok = false;
254 }
255
256 if (!ok) {
257 QFile::remove(rcFile);
258 }
259
260 pSocket->disconnectFromHost();
261 delete pSocket;
262 }
263
264 if (!QFile::exists(rcFile)) {
265 // no server found... Create one
266 // qDebug("setting up new server...");
267
268 m_port = pServer->serverPort();

Callers

nothing calls this directly

Calls 2

toStringMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected