Skip to content

Commit 5b1c5b8

Browse files
authored
proxy/handler: remove unused qt event loop setup code (#48277)
1 parent 5da411e commit 5b1c5b8

File tree

5 files changed

+48
-237
lines changed

5 files changed

+48
-237
lines changed

src/handler/handlerapp.cpp

Lines changed: 12 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
*/
2323

2424
#include <assert.h>
25+
#include <unistd.h>
2526
#include <iostream>
26-
#include <QCoreApplication>
2727
#include <QCommandLineParser>
2828
#include <QStringList>
2929
#include <QFile>
@@ -100,9 +100,6 @@ class HandlerApp::Private
100100
public:
101101
static int run(const ffi::HandlerCliArgs *argsFfi)
102102
{
103-
QCoreApplication::setApplicationName("pushpin-handler");
104-
QCoreApplication::setApplicationVersion(Config::get().version);
105-
106103
HandlerArgsData args(argsFfi);
107104

108105
// Set the log level
@@ -233,7 +230,7 @@ class HandlerApp::Private
233230

234231
HandlerEngine::Configuration config;
235232
config.appVersion = Config::get().version;
236-
config.instanceId = "handler_" + QByteArray::number(QCoreApplication::applicationPid());
233+
config.instanceId = "handler_" + QByteArray::number(getpid());
237234
if(!services.contains("mongrel2") && (!connmgr_in_stream_specs.isEmpty() || !connmgr_out_specs.isEmpty()))
238235
{
239236
config.serverInStreamSpecs = connmgr_in_stream_specs;
@@ -283,11 +280,11 @@ class HandlerApp::Private
283280
config.prometheusPort = prometheusPort;
284281
config.prometheusPrefix = prometheusPrefix;
285282

286-
return runLoop(config, true);
283+
return runLoop(config);
287284
}
288285

289286
private:
290-
static int runLoop(const HandlerEngine::Configuration &config, bool newEventLoop)
287+
static int runLoop(const HandlerEngine::Configuration &config)
291288
{
292289
// includes worst-case subscriptions and update registrations
293290
int timersPerSession = qMax(TIMERS_PER_HTTPSESSION, TIMERS_PER_WSSESSION) +
@@ -297,24 +294,12 @@ class HandlerApp::Private
297294
// enough timers for sessions, plus an extra 100 for misc
298295
int timersMax = (config.connectionsMax * timersPerSession) + 100;
299296

300-
std::unique_ptr<EventLoop> loop;
301-
302-
if(newEventLoop)
303-
{
304-
log_debug("using new event loop");
297+
// enough for control requests and prometheus requests, plus an
298+
// extra 100 for misc. client sessions don't use socket notifiers
299+
int socketNotifiersMax = (SOCKETNOTIFIERS_PER_SIMPLEHTTPREQUEST * (CONTROL_CONNECTIONS_MAX + PROMETHEUS_CONNECTIONS_MAX)) + 100;
305300

306-
// enough for control requests and prometheus requests, plus an
307-
// extra 100 for misc. client sessions don't use socket notifiers
308-
int socketNotifiersMax = (SOCKETNOTIFIERS_PER_SIMPLEHTTPREQUEST * (CONTROL_CONNECTIONS_MAX + PROMETHEUS_CONNECTIONS_MAX)) + 100;
309-
310-
int registrationsMax = timersMax + socketNotifiersMax;
311-
loop = std::make_unique<EventLoop>(registrationsMax);
312-
}
313-
else
314-
{
315-
// for qt event loop, timer subsystem must be explicitly initialized
316-
Timer::init(timersMax);
317-
}
301+
int registrationsMax = timersMax + socketNotifiersMax;
302+
std::unique_ptr<EventLoop> loop = std::make_unique<EventLoop>(registrationsMax);
318303

319304
std::unique_ptr<HandlerEngine> engine;
320305

@@ -332,10 +317,7 @@ class HandlerApp::Private
332317

333318
log_debug("stopped");
334319

335-
if(newEventLoop)
336-
loop->exit(0);
337-
else
338-
QCoreApplication::exit(0);
320+
loop->exit(0);
339321
});
340322

341323
ProcessQuit::instance()->hup.connect([&] {
@@ -347,39 +329,14 @@ class HandlerApp::Private
347329
if(!engine->start(config))
348330
{
349331
engine.reset();
350-
351-
if(newEventLoop)
352-
loop->exit(1);
353-
else
354-
QCoreApplication::exit(1);
355-
332+
loop->exit(1);
356333
return;
357334
}
358335

359336
log_info("started");
360337
});
361338

362-
int ret;
363-
if(newEventLoop)
364-
ret = loop->exec();
365-
else
366-
ret = QCoreApplication::exec();
367-
368-
if(!newEventLoop)
369-
{
370-
// ensure deferred deletes are processed
371-
QCoreApplication::instance()->sendPostedEvents();
372-
}
373-
374-
// deinit here, after all event loop activity has completed
375-
376-
if(!newEventLoop)
377-
{
378-
DeferCall::cleanup();
379-
Timer::deinit();
380-
}
381-
382-
return ret;
339+
return loop->exec();
383340
}
384341
};
385342

@@ -396,13 +353,6 @@ extern "C" {
396353

397354
int handler_init(const ffi::HandlerCliArgs *argsFfi)
398355
{
399-
// Create dummy argc/argv for QCoreApplication
400-
int argc = 1;
401-
char app_name[] = "pushpin-handler";
402-
char* argv[] = { app_name, nullptr };
403-
404-
QCoreApplication qapp(argc, argv);
405-
406356
HandlerApp app;
407357
return app.run(argsFfi);
408358
}

src/proxy/domainmap.cpp

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <QFile>
3434
#include <QDir>
3535
#include <QTextStream>
36-
#include <QCoreApplication>
3736
#include "log.h"
3837
#include "timer.h"
3938
#include "defercall.h"
@@ -789,30 +788,20 @@ class DomainMap::Worker
789788
class DomainMap::Thread
790789
{
791790
public:
792-
bool newEventLoop;
793791
QString fileName;
794792
std::thread thread;
795793
std::unique_ptr<EventLoop> loop;
796-
std::unique_ptr<QEventLoop> qloop;
797794
std::unique_ptr<Worker> worker;
798795
QMutex m;
799796
QWaitCondition w;
800797

801-
Thread() :
802-
newEventLoop(false)
803-
{
804-
}
805-
806798
~Thread()
807799
{
808800
if(worker)
809801
{
810802
worker->deferCall.defer([&] {
811803
// NOTE: called from worker thread
812-
if(newEventLoop)
813-
loop->exit(0);
814-
else
815-
qloop->quit();
804+
loop->exit(0);
816805
});
817806
}
818807

@@ -841,24 +830,8 @@ class DomainMap::Thread
841830
// will unlock during exec
842831
m.lock();
843832

844-
int timersMax = WORKER_THREAD_TIMERS;
845-
846-
if(newEventLoop)
847-
{
848-
log_debug("domainmap: using new event loop");
849-
850-
int socketNotifiersMax = WORKER_THREAD_SOCKETNOTIFIERS;
851-
852-
int registrationsMax = timersMax + socketNotifiersMax;
853-
loop = std::make_unique<EventLoop>(registrationsMax);
854-
}
855-
else
856-
{
857-
// for qt event loop, timer subsystem must be explicitly initialized
858-
Timer::init(timersMax);
859-
860-
qloop = std::make_unique<QEventLoop>();
861-
}
833+
int registrationsMax = WORKER_THREAD_TIMERS + WORKER_THREAD_SOCKETNOTIFIERS;
834+
loop = std::make_unique<EventLoop>(registrationsMax);
862835

863836
worker = std::make_unique<Worker>();
864837
worker->fileName = fileName;
@@ -870,31 +843,10 @@ class DomainMap::Thread
870843

871844
worker->deferCall.defer([=] { worker->start(); });
872845

873-
if(newEventLoop)
874-
loop->exec();
875-
else
876-
qloop->exec();
846+
loop->exec();
877847

878848
worker.reset();
879-
880-
if(!newEventLoop)
881-
{
882-
// ensure deferred deletes are processed
883-
QCoreApplication::instance()->sendPostedEvents();
884-
}
885-
886-
// deinit here, after all event loop activity has completed
887-
888-
if(!newEventLoop)
889-
{
890-
DeferCall::cleanup();
891-
Timer::deinit();
892-
}
893-
894-
if(newEventLoop)
895-
loop.reset();
896-
else
897-
qloop.reset();
849+
loop.reset();
898850
}
899851
};
900852

@@ -918,10 +870,9 @@ class DomainMap::Private
918870
delete thread;
919871
}
920872

921-
void start(bool newEventLoop, const QString &fileName = QString())
873+
void start(const QString &fileName = QString())
922874
{
923875
thread = new Thread;
924-
thread->newEventLoop = newEventLoop;
925876
thread->fileName = fileName;
926877
thread->start();
927878

@@ -945,16 +896,16 @@ class DomainMap::Private
945896
}
946897
};
947898

948-
DomainMap::DomainMap(bool newEventLoop)
899+
DomainMap::DomainMap()
949900
{
950901
d = new Private(this);
951-
d->start(newEventLoop);
902+
d->start();
952903
}
953904

954-
DomainMap::DomainMap(const QString &fileName, bool newEventLoop)
905+
DomainMap::DomainMap(const QString &fileName)
955906
{
956907
d = new Private(this);
957-
d->start(newEventLoop, fileName);
908+
d->start(fileName);
958909
}
959910

960911
DomainMap::~DomainMap()

src/proxy/domainmap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ class DomainMap
181181
}
182182
};
183183

184-
DomainMap(bool newEventLoop);
185-
DomainMap(const QString &fileName, bool newEventLoop);
184+
DomainMap();
185+
DomainMap(const QString &fileName);
186186
~DomainMap();
187187

188188
// shouldn't really ever need to call this, but it's here in case the

0 commit comments

Comments
 (0)