Skip to content

Commit 0a1a2fb

Browse files
committed
proxy/handler: reorganize program startup a little bit
1 parent 64308d2 commit 0a1a2fb

18 files changed

+94
-221
lines changed

src/bin/pushpin-handler.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023 Fastly, Inc.
2+
* Copyright (C) 2023-2025 Fastly, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,20 +15,20 @@
1515
*/
1616

1717
use clap::Parser;
18-
use pushpin::handler::handlercliargs::ffi::HandlerCliArgs;
19-
use pushpin::handler::handlercliargs::{destroy_handler_cli_args, CliArgs};
18+
use pushpin::handler::cliargs::ffi::HandlerCliArgs;
19+
use pushpin::handler::cliargs::{destroy_handler_cli_args, CliArgs};
2020
use pushpin::import_cpp;
2121
use std::process::ExitCode;
2222

2323
import_cpp! {
24-
fn handler_main(args: *const HandlerCliArgs) -> libc::c_int;
24+
fn handler_init(args: *const HandlerCliArgs) -> libc::c_int;
2525
}
2626

2727
fn main() -> ExitCode {
2828
let cli_args = CliArgs::parse().verify();
2929
let cli_args_ffi = cli_args.to_ffi();
3030

31-
let exit_code = unsafe { handler_main(&cli_args_ffi) };
31+
let exit_code = unsafe { handler_init(&cli_args_ffi) };
3232

3333
// Clean up the allocated memory
3434
unsafe { destroy_handler_cli_args(cli_args_ffi) };

src/bin/pushpin-proxy.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023 Fastly, Inc.
2+
* Copyright (C) 2023-2025 Fastly, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,19 +16,19 @@
1616

1717
use clap::Parser;
1818
use pushpin::import_cpp;
19-
use pushpin::proxy::proxycliargs::ffi::ProxyCliArgs;
20-
use pushpin::proxy::proxycliargs::{destroy_proxy_cli_args, CliArgs};
19+
use pushpin::proxy::cliargs::ffi::ProxyCliArgs;
20+
use pushpin::proxy::cliargs::{destroy_proxy_cli_args, CliArgs};
2121
use std::process::ExitCode;
2222

2323
import_cpp! {
24-
fn proxy_main(args: *const ProxyCliArgs) -> libc::c_int;
24+
fn proxy_init(args: *const ProxyCliArgs) -> libc::c_int;
2525
}
2626

2727
fn main() -> ExitCode {
2828
let cli_args = CliArgs::parse().verify();
2929
let cli_args_ffi = cli_args.to_ffi();
3030

31-
let exit_code = unsafe { proxy_main(&cli_args_ffi) };
31+
let exit_code = unsafe { proxy_init(&cli_args_ffi) };
3232

3333
// Clean up the allocated memory
3434
unsafe { destroy_proxy_cli_args(cli_args_ffi) };

src/handler/handler.pri

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ HEADERS += \
2727
$$PWD/filter.h \
2828
$$PWD/filterstack.h \
2929
$$PWD/handlerengine.h \
30-
$$PWD/handlerapp.h \
31-
$$PWD/main.h \
32-
$$PWD/handlerargsdata.h
30+
$$PWD/handlerargsdata.h
3331

3432
SOURCES += \
3533
$$PWD/deferred.cpp \
@@ -56,6 +54,5 @@ SOURCES += \
5654
$$PWD/filter.cpp \
5755
$$PWD/filterstack.cpp \
5856
$$PWD/handlerengine.cpp \
59-
$$PWD/handlerapp.cpp \
60-
$$PWD/handlermain.cpp \
61-
$$PWD/handlerargsdata.cpp
57+
$$PWD/handlerargsdata.cpp \
58+
$$PWD/handlerapp.cpp

src/handler/handlerapp.cpp

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@
2121
* $FANOUT_END_LICENSE$
2222
*/
2323

24-
#include "handlerapp.h"
25-
#include "handlerargsdata.h"
26-
#include "rust/bindings.h"
27-
2824
#include <assert.h>
25+
#include <iostream>
2926
#include <QCoreApplication>
3027
#include <QCommandLineParser>
3128
#include <QStringList>
3229
#include <QFile>
3330
#include <QFileInfo>
3431
#include <QDir>
32+
#include "rust/bindings.h"
3533
#include "timer.h"
3634
#include "defercall.h"
3735
#include "eventloop.h"
@@ -42,9 +40,9 @@
4240
#include "wssession.h"
4341
#include "httpsessionupdatemanager.h"
4442
#include "settings.h"
45-
#include "handlerengine.h"
4643
#include "config.h"
47-
#include <iostream>
44+
#include "handlerengine.h"
45+
#include "handlerargsdata.h"
4846

4947
#define DEFAULT_HTTP_MAX_HEADERS_SIZE 10000
5048
#define DEFAULT_HTTP_MAX_BODY_SIZE 1000000
@@ -85,6 +83,18 @@ static QString firstSpec(const QString &s, int peerCount)
8583
return s;
8684
}
8785

86+
class HandlerApp
87+
{
88+
public:
89+
HandlerApp();
90+
~HandlerApp();
91+
92+
int run(const ffi::HandlerCliArgs *argsFfi);
93+
94+
private:
95+
class Private;
96+
};
97+
8898
class HandlerApp::Private
8999
{
90100
public:
@@ -379,4 +389,21 @@ HandlerApp::~HandlerApp() = default;
379389
int HandlerApp::run(const ffi::HandlerCliArgs *argsFfi)
380390
{
381391
return Private::run(argsFfi);
382-
}
392+
}
393+
394+
extern "C" {
395+
396+
int handler_init(const ffi::HandlerCliArgs *argsFfi)
397+
{
398+
// Create dummy argc/argv for QCoreApplication
399+
int argc = 1;
400+
char app_name[] = "pushpin-handler";
401+
char* argv[] = { app_name, nullptr };
402+
403+
QCoreApplication qapp(argc, argv);
404+
405+
HandlerApp app;
406+
return app.run(argsFfi);
407+
}
408+
409+
}

src/handler/handlerapp.h

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/handler/handlermain.cpp

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/handler/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
pub mod handlercliargs;
17+
pub mod cliargs;
1818

1919
#[cfg(test)]
2020
mod tests {

src/proxy/app.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)