diff mbox series

[v2,10/15] qio: non-default context for async conn

Message ID 20180301084438.13594-11-peterx@redhat.com
State New
Headers show
Series qio: general non-default GMainContext support | expand

Commit Message

Peter Xu March 1, 2018, 8:44 a.m. UTC
We have worked on qio_task_run_in_thread() already.  Further, let
qio_channel_socket_connect_async() pass that context to it.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 chardev/char-socket.c          | 4 ++--
 include/io/channel-socket.h    | 4 +++-
 io/channel-socket.c            | 5 +++--
 migration/socket.c             | 3 ++-
 tests/test-io-channel-socket.c | 2 +-
 5 files changed, 11 insertions(+), 7 deletions(-)

Comments

Daniel P. Berrangé March 1, 2018, 3:48 p.m. UTC | #1
On Thu, Mar 01, 2018 at 04:44:33PM +0800, Peter Xu wrote:
> We have worked on qio_task_run_in_thread() already.  Further, let
> qio_channel_socket_connect_async() pass that context to it.
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  chardev/char-socket.c          | 4 ++--
>  include/io/channel-socket.h    | 4 +++-
>  io/channel-socket.c            | 5 +++--
>  migration/socket.c             | 3 ++-
>  tests/test-io-channel-socket.c | 2 +-
>  5 files changed, 11 insertions(+), 7 deletions(-)

> diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h
> index 53801f6042..90f7227397 100644
> --- a/include/io/channel-socket.h
> +++ b/include/io/channel-socket.h
> @@ -101,6 +101,7 @@ int qio_channel_socket_connect_sync(QIOChannelSocket *ioc,
>   * @callback: the function to invoke on completion
>   * @opaque: user data to pass to @callback
>   * @destroy: the function to free @opaque
> + * @context: the context to run the async task
>   *
>   * Attempt to connect to the address @addr. This method
>   * will run in the background so the caller will regain
> @@ -113,7 +114,8 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
>                                        SocketAddress *addr,
>                                        QIOTaskFunc callback,
>                                        gpointer opaque,
> -                                      GDestroyNotify destroy);
> +                                      GDestroyNotify destroy,
> +                                      GMainContext *context);

If you're going to add a GMainContext() to connect_async, then please
also do it for listen_async and dgram_async at the same time, so we
remain consistent in API design.


Regards,
Daniel
Peter Xu March 2, 2018, 5:01 a.m. UTC | #2
On Thu, Mar 01, 2018 at 03:48:44PM +0000, Daniel P. Berrangé wrote:
> On Thu, Mar 01, 2018 at 04:44:33PM +0800, Peter Xu wrote:
> > We have worked on qio_task_run_in_thread() already.  Further, let
> > qio_channel_socket_connect_async() pass that context to it.
> > 
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> >  chardev/char-socket.c          | 4 ++--
> >  include/io/channel-socket.h    | 4 +++-
> >  io/channel-socket.c            | 5 +++--
> >  migration/socket.c             | 3 ++-
> >  tests/test-io-channel-socket.c | 2 +-
> >  5 files changed, 11 insertions(+), 7 deletions(-)
> 
> > diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h
> > index 53801f6042..90f7227397 100644
> > --- a/include/io/channel-socket.h
> > +++ b/include/io/channel-socket.h
> > @@ -101,6 +101,7 @@ int qio_channel_socket_connect_sync(QIOChannelSocket *ioc,
> >   * @callback: the function to invoke on completion
> >   * @opaque: user data to pass to @callback
> >   * @destroy: the function to free @opaque
> > + * @context: the context to run the async task
> >   *
> >   * Attempt to connect to the address @addr. This method
> >   * will run in the background so the caller will regain
> > @@ -113,7 +114,8 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
> >                                        SocketAddress *addr,
> >                                        QIOTaskFunc callback,
> >                                        gpointer opaque,
> > -                                      GDestroyNotify destroy);
> > +                                      GDestroyNotify destroy,
> > +                                      GMainContext *context);
> 
> If you're going to add a GMainContext() to connect_async, then please
> also do it for listen_async and dgram_async at the same time, so we
> remain consistent in API design.

Sure.  Thanks,
diff mbox series

Patch

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 6c3f1de013..bd90680f5c 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -911,7 +911,7 @@  static gboolean socket_reconnect_timeout(gpointer opaque)
     tcp_chr_set_client_ioc_name(chr, sioc);
     qio_channel_socket_connect_async(sioc, s->addr,
                                      qemu_chr_socket_connected,
-                                     chr, NULL);
+                                     chr, NULL, NULL);
 
     return false;
 }
@@ -995,7 +995,7 @@  static void qmp_chardev_open_socket(Chardev *chr,
         tcp_chr_set_client_ioc_name(chr, sioc);
         qio_channel_socket_connect_async(sioc, s->addr,
                                          qemu_chr_socket_connected,
-                                         chr, NULL);
+                                         chr, NULL, NULL);
     } else {
         if (s->is_listen) {
             char *name;
diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h
index 53801f6042..90f7227397 100644
--- a/include/io/channel-socket.h
+++ b/include/io/channel-socket.h
@@ -101,6 +101,7 @@  int qio_channel_socket_connect_sync(QIOChannelSocket *ioc,
  * @callback: the function to invoke on completion
  * @opaque: user data to pass to @callback
  * @destroy: the function to free @opaque
+ * @context: the context to run the async task
  *
  * Attempt to connect to the address @addr. This method
  * will run in the background so the caller will regain
@@ -113,7 +114,8 @@  void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
                                       SocketAddress *addr,
                                       QIOTaskFunc callback,
                                       gpointer opaque,
-                                      GDestroyNotify destroy);
+                                      GDestroyNotify destroy,
+                                      GMainContext *context);
 
 
 /**
diff --git a/io/channel-socket.c b/io/channel-socket.c
index 4224ce323a..a843e49939 100644
--- a/io/channel-socket.c
+++ b/io/channel-socket.c
@@ -173,7 +173,8 @@  void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
                                       SocketAddress *addr,
                                       QIOTaskFunc callback,
                                       gpointer opaque,
-                                      GDestroyNotify destroy)
+                                      GDestroyNotify destroy,
+                                      GMainContext *context)
 {
     QIOTask *task = qio_task_new(
         OBJECT(ioc), callback, opaque, destroy);
@@ -188,7 +189,7 @@  void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
                            qio_channel_socket_connect_worker,
                            addrCopy,
                            (GDestroyNotify)qapi_free_SocketAddress,
-                           NULL);
+                           context);
 }
 
 
diff --git a/migration/socket.c b/migration/socket.c
index 60d732535c..91071b06ef 100644
--- a/migration/socket.c
+++ b/migration/socket.c
@@ -103,7 +103,8 @@  static void socket_start_outgoing_migration(MigrationState *s,
                                      saddr,
                                      socket_outgoing_migration,
                                      data,
-                                     socket_connect_data_free);
+                                     socket_connect_data_free,
+                                     NULL);
     qapi_free_SocketAddress(saddr);
 }
 
diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c
index d357cd2a8e..a67635b9b8 100644
--- a/tests/test-io-channel-socket.c
+++ b/tests/test-io-channel-socket.c
@@ -200,7 +200,7 @@  static void test_io_channel_setup_async(SocketAddress *listen_addr,
 
     qio_channel_socket_connect_async(
         QIO_CHANNEL_SOCKET(*src), connect_addr,
-        test_io_channel_complete, &data, NULL);
+        test_io_channel_complete, &data, NULL, NULL);
 
     g_main_loop_run(data.loop);
     g_main_context_iteration(g_main_context_default(), FALSE);