1.1 --- a/libfsserver/include/fsserver/resource_server.h Wed May 19 00:01:41 2021 +0200
1.2 +++ b/libfsserver/include/fsserver/resource_server.h Wed May 19 00:38:36 2021 +0200
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Common resource server functions.
1.6 *
1.7 - * Copyright (C) 2018, 2019, 2020 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2018, 2019, 2020, 2021 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -56,6 +56,8 @@
1.13 long start();
1.14
1.15 long start_thread();
1.16 +
1.17 + long start_thread(l4_cap_idx_t *server);
1.18 };
1.19
1.20
1.21 @@ -74,3 +76,5 @@
1.22 /* Server finalisation. */
1.23
1.24 void resource_thread_finaliser(ipc_server_config_type *config);
1.25 +
1.26 +// vim: tabstop=2 expandtab shiftwidth=2
2.1 --- a/libfsserver/lib/files/opener_context_resource.cc Wed May 19 00:01:41 2021 +0200
2.2 +++ b/libfsserver/lib/files/opener_context_resource.cc Wed May 19 00:38:36 2021 +0200
2.3 @@ -75,22 +75,13 @@
2.4
2.5 Pager *pager = _opener->open(path, flags);
2.6
2.7 - /* Complete the initialisation and start a server in a new thread.
2.8 - If the thread does not start, the resource should be finalised. */
2.9 -
2.10 - ResourceServer server(pager);
2.11 - long err = server.start_thread();
2.12 + *size = pager->get_data_size();
2.13
2.14 - if (!err)
2.15 - {
2.16 - /* Return the file size. */
2.17 - /* Return the server capability to the caller. */
2.18 + /* Complete the initialisation and start a server in a new thread.
2.19 + If the thread does not start, the resource (including pager) will be
2.20 + finalised. */
2.21
2.22 - *size = pager->get_data_size();
2.23 - *file = server.config()->server;
2.24 - }
2.25 -
2.26 - return err;
2.27 + return ResourceServer(pager).start_thread(file);
2.28 }
2.29
2.30 // vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/libfsserver/lib/files/opener_resource.cc Wed May 19 00:01:41 2021 +0200
3.2 +++ b/libfsserver/lib/files/opener_resource.cc Wed May 19 00:38:36 2021 +0200
3.3 @@ -63,17 +63,9 @@
3.4 OpenerContextResource *resource = new OpenerContextResource(this);
3.5
3.6 /* Complete the initialisation and start a server in a new thread.
3.7 - If the thread does not start, the resource should be finalised. */
3.8 -
3.9 - ResourceServer server(resource);
3.10 - long err = server.start_thread();
3.11 + If the thread does not start, the resource will be finalised. */
3.12
3.13 - /* Return the server capability to the caller. */
3.14 -
3.15 - if (!err)
3.16 - *context = server.config()->server;
3.17 -
3.18 - return err;
3.19 + return ResourceServer(resource).start_thread(context);
3.20 }
3.21
3.22 // vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/libfsserver/lib/generic/resource_server.cc Wed May 19 00:01:41 2021 +0200
4.2 +++ b/libfsserver/lib/generic/resource_server.cc Wed May 19 00:38:36 2021 +0200
4.3 @@ -68,6 +68,19 @@
4.4 return resource_start_config(_config, _resource);
4.5 }
4.6
4.7 +/* A convenience method starting a thread and providing the server
4.8 + capability. */
4.9 +
4.10 +long ResourceServer::start_thread(l4_cap_idx_t *server)
4.11 +{
4.12 + long err = start_thread();
4.13 +
4.14 + if (!err)
4.15 + *server = _config->server;
4.16 +
4.17 + return err;
4.18 +}
4.19 +
4.20
4.21
4.22 /* Initialise a server configuration for a resource. */
5.1 --- a/libfsserver/lib/pipes/pipe_opener_resource.cc Wed May 19 00:01:41 2021 +0200
5.2 +++ b/libfsserver/lib/pipes/pipe_opener_resource.cc Wed May 19 00:38:36 2021 +0200
5.3 @@ -62,22 +62,14 @@
5.4 return open_endpoint(paging, false, reader) || open_endpoint(paging, true, writer);
5.5 }
5.6
5.7 +/* Start the endpoint server in a new thread. If the thread does not start, the
5.8 + resource (including pager) will be finalised. */
5.9 +
5.10 long PipeOpenerResource::open_endpoint(PipePaging *paging, bool writing, l4_cap_idx_t *endpoint)
5.11 {
5.12 PipePager *pager = new PipePager(paging, writing);
5.13
5.14 - /* Start the endpoint server in a new thread.
5.15 - If the thread does not start, the resource should be finalised. */
5.16 -
5.17 - ResourceServer server(pager);
5.18 - long err = server.start_thread();
5.19 -
5.20 - /* Return the server capability to the caller. */
5.21 -
5.22 - if (!err)
5.23 - *endpoint = server.config()->server;
5.24 -
5.25 - return err;
5.26 + return ResourceServer(pager).start_thread(endpoint);
5.27 }
5.28
5.29 // vim: tabstop=4 expandtab shiftwidth=4