[wing/namedpipeconnection-close] namedpipeconnection: implement close method



commit c708f140a75d79c5dc4e18b547b6169a18ab6617
Author: Ignacio Casal Quinteiro <qignacio amazon com>
Date:   Thu Nov 28 09:55:21 2019 +0100

    namedpipeconnection: implement close method
    
    We should ensure the named pipe gets closed when closing the stream
    otherwise the peer will not detect EOF until the object gets finalized.

 wing/wingnamedpipeconnection.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
---
diff --git a/wing/wingnamedpipeconnection.c b/wing/wingnamedpipeconnection.c
index 0d97c49..f88ad88 100644
--- a/wing/wingnamedpipeconnection.c
+++ b/wing/wingnamedpipeconnection.c
@@ -242,6 +242,34 @@ wing_named_pipe_connection_get_output_stream (GIOStream *stream)
   return connection->output_stream;
 }
 
+static gboolean
+wing_named_pipe_connection_close (GIOStream     *stream,
+                                  GCancellable  *cancellable,
+                                  GError       **error)
+{
+  WingNamedPipeConnection *connection = WING_NAMED_PIPE_CONNECTION (stream);
+
+  if (connection->output_stream)
+    g_output_stream_close (connection->output_stream, cancellable, NULL);
+
+  if (connection->input_stream)
+    g_input_stream_close (connection->input_stream, cancellable, NULL);
+
+  if (connection->close_handle && connection->handle != INVALID_HANDLE_VALUE)
+    {
+      DisconnectNamedPipe (connection->handle);
+      CloseHandle (connection->handle);
+      connection->handle = INVALID_HANDLE_VALUE;
+    }
+
+  if (connection->threadpool_io != NULL)
+    {
+      WaitForThreadpoolIoCallbacks (connection->threadpool_io, FALSE);
+      CloseThreadpoolIo (connection->threadpool_io);
+      connection->threadpool_io = NULL;
+    }
+}
+
 static void
 wing_named_pipe_connection_class_init (WingNamedPipeConnectionClass *class)
 {
@@ -255,6 +283,7 @@ wing_named_pipe_connection_class_init (WingNamedPipeConnectionClass *class)
 
   io_class->get_input_stream = wing_named_pipe_connection_get_input_stream;
   io_class->get_output_stream = wing_named_pipe_connection_get_output_stream;
+  io_class->close_fn = wing_named_pipe_connection_close;
 
   /**
    * WingNamedPipeConnection:pipe-name:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]