summaryrefslogtreecommitdiffstats
path: root/grpc-proxy/main-grpc.cpp
diff options
context:
space:
mode:
authorMarius Vlad <marius.vlad@collabora.com>2023-10-24 17:39:45 +0300
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2023-11-03 17:46:25 +0000
commit73e82a6f346d2835f6d6b0752629b2d2446e871d (patch)
treec7b533e1eb3b05065527704a06dc9fef2cc24d13 /grpc-proxy/main-grpc.cpp
parent53b470c60986fcfc83dc3a5eafcd9370a7264086 (diff)
grpc-proxy: Start the gRPC server and waiting thread much sooner
This change moves a bit the start-up sequence of the gRPC server and when it connects to the compositor. Changing the start-up sequence avoids waiting for the channel to change its state from disconnected to connected, and only wait for the wayland connection to take place. Otherwise, we would wait first for the wayland connection to take place, then wait for the gRPC server to start up and finally wait for the channel to be in connected state, all which would incur a massive waiting time. Moving it a bit early requires to at least verify that we have the proxy side (the wayland connection) is already set-up at that time. Bug-AGL: SPEC-4912 Signed-off-by: Marius Vlad <marius.vlad@collabora.com> Change-Id: Ied88a917df8ff98fefa601103ce04e13c8bb21ac
Diffstat (limited to 'grpc-proxy/main-grpc.cpp')
-rw-r--r--grpc-proxy/main-grpc.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/grpc-proxy/main-grpc.cpp b/grpc-proxy/main-grpc.cpp
index ea75722..2f9350a 100644
--- a/grpc-proxy/main-grpc.cpp
+++ b/grpc-proxy/main-grpc.cpp
@@ -542,8 +542,19 @@ err:
}
static void
-start_grpc_server(Shell *aglShell)
+start_grpc_server(std::shared_ptr<grpc::Server> server)
{
+ LOG("gRPC server listening\n");
+ server->Wait();
+}
+
+int main(int argc, char **argv)
+{
+ (void) argc;
+ (void) argv;
+ Shell *aglShell = nullptr;
+ int ret = 0;
+
// instantiante the grpc server
std::string server_address(kDefaultGrpcServiceAddress);
GrpcServiceImpl service{aglShell};
@@ -555,18 +566,8 @@ start_grpc_server(Shell *aglShell)
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
- std::unique_ptr<grpc::Server> server(builder.BuildAndStart());
- LOG("gRPC server listening on %s\n", server_address.c_str());
-
- server->Wait();
-}
-
-int main(int argc, char **argv)
-{
- (void) argc;
- (void) argv;
- Shell *aglShell;
- int ret = 0;
+ std::shared_ptr<grpc::Server> server(builder.BuildAndStart());
+ std::thread thread(start_grpc_server, server);
// this blocks until we detect that another shell client started
// running
@@ -581,7 +582,8 @@ int main(int argc, char **argv)
std::shared_ptr<struct agl_shell> agl_shell{sh->shell, agl_shell_destroy};
aglShell = new Shell(agl_shell, sh);
- std::thread thread(start_grpc_server, aglShell);
+ // now that we have aglShell, set it to the gRPC proxy as well
+ service.setAglShell(aglShell);
// serve wayland requests
while (running && ret != -1) {