[phodav,04/13] spice: quit service quickly

Submitted by Jakub Janku on May 23, 2019, 8:37 a.m.

Details

Message ID 20190523083725.1554-5-jjanku@redhat.com
State New
Headers show
Series "Miscellaneous series" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Jakub Janku May 23, 2019, 8:37 a.m.
We shouldn't wait for 1 second if the service is supposed to stop.

Signed-off-by: Jakub Janků <jjanku@redhat.com>
---
 spice/spice-webdavd.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/spice/spice-webdavd.c b/spice/spice-webdavd.c
index cdfa73d..6ad63c5 100644
--- a/spice/spice-webdavd.c
+++ b/spice/spice-webdavd.c
@@ -923,11 +923,15 @@  map_drive_cb(GTask *task,
 
 #endif
 
-static void
+/* returns FALSE if the service should quit */
+static gboolean
 run_service (ServiceData *service_data)
 {
   g_debug ("Run service");
 
+  if (quit_service)
+    return FALSE;
+
 #ifdef G_OS_WIN32
   MapDriveData map_drive_data;
   map_drive_data.cancel_map = g_cancellable_new ();
@@ -1003,6 +1007,7 @@  run_service (ServiceData *service_data)
 #else
   close (port_fd);
 #endif
+  return !quit_service;
 }
 
 #ifdef G_OS_WIN32
@@ -1064,9 +1069,8 @@  service_main (DWORD argc, TCHAR *argv[])
   service_status.dwWaitHint = 0;
   SetServiceStatus (service_status_handle, &service_status);
 
-  while (!quit_service) {
-      run_service (&service_data);
-      g_usleep (G_USEC_PER_SEC);
+  while (run_service(&service_data)) {
+    g_usleep(G_USEC_PER_SEC);
   }
 
   service_status.dwCurrentState = SERVICE_STOPPED;
@@ -1154,8 +1158,7 @@  main (int argc, char *argv[])
         }
     } else
 #endif
-  while (!quit_service) {
-    run_service (&service_data);
+  while (run_service(&service_data)) {
     g_usleep (G_USEC_PER_SEC);
   }
 

Comments

On Thu, May 23, 2019 at 10:37 AM Jakub Janků <jjanku@redhat.com> wrote:
>
> We shouldn't wait for 1 second if the service is supposed to stop.
>
> Signed-off-by: Jakub Janků <jjanku@redhat.com>

ack

> ---
>  spice/spice-webdavd.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/spice/spice-webdavd.c b/spice/spice-webdavd.c
> index cdfa73d..6ad63c5 100644
> --- a/spice/spice-webdavd.c
> +++ b/spice/spice-webdavd.c
> @@ -923,11 +923,15 @@ map_drive_cb(GTask *task,
>
>  #endif
>
> -static void
> +/* returns FALSE if the service should quit */
> +static gboolean
>  run_service (ServiceData *service_data)
>  {
>    g_debug ("Run service");
>
> +  if (quit_service)
> +    return FALSE;
> +
>  #ifdef G_OS_WIN32
>    MapDriveData map_drive_data;
>    map_drive_data.cancel_map = g_cancellable_new ();
> @@ -1003,6 +1007,7 @@ run_service (ServiceData *service_data)
>  #else
>    close (port_fd);
>  #endif
> +  return !quit_service;
>  }
>
>  #ifdef G_OS_WIN32
> @@ -1064,9 +1069,8 @@ service_main (DWORD argc, TCHAR *argv[])
>    service_status.dwWaitHint = 0;
>    SetServiceStatus (service_status_handle, &service_status);
>
> -  while (!quit_service) {
> -      run_service (&service_data);
> -      g_usleep (G_USEC_PER_SEC);
> +  while (run_service(&service_data)) {
> +    g_usleep(G_USEC_PER_SEC);
>    }
>
>    service_status.dwCurrentState = SERVICE_STOPPED;
> @@ -1154,8 +1158,7 @@ main (int argc, char *argv[])
>          }
>      } else
>  #endif
> -  while (!quit_service) {
> -    run_service (&service_data);
> +  while (run_service(&service_data)) {
>      g_usleep (G_USEC_PER_SEC);
>    }
>
> --
> 2.21.0
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel