Re: VNC Reconnect logic / proper destruction of a VncDisplay



Good catch, thank you very much! It looks like the leak still occurs on 0.3.10, but compiling against 0.5.2 is fine.

On Thu, Feb 11, 2016 at 12:11 PM, Daniel P. Berrange <dan berrange com> wrote:
On Thu, Feb 11, 2016 at 12:01:04PM -0500, Gerald Grignan wrote:
> My original attempt at this did not destroy the vncdisplay object -- which
> unfortunately had the same results. Below is the full code of what I'm
> trying to do, which is basically a popup when the connection is down, and
> recurrent reconnect attempts (triggered off the disconnect). The only real
> interesting part is inside the disconnect() call. I've tried it with and
> without the vnc_close(), using both 0.5.2 (on RHEL7) and 0.3.10 (RHEL6)
> with similar results.
>
> #include "vncdisplay.h"
> #include <gtk/gtk.h>
> #include <gdk/gdkkeysyms.h>
> #include <stdlib.h>
> #include <string.h>
> #include <glib.h>
> #include <unistd.h>
>
> GtkMessageDialog* not_avail;
> GtkDialogFlags not_avail_flags = GTK_DIALOG_MODAL;
> GtkWidget *window;
> char port[1024];
> char hostname[1024];
>
> static gchar **args = NULL;
> static GtkWidget *vnc;
>
> static const GOptionEntry options [] =
> {
>     {
>         G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args,
>         NULL, "[hostname][:display]" },
>     { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, 0 }
> };
>
>
>
> static void vnc_initialized(GtkWidget *vncdisplay, GtkWidget *window)
> {
>    printf("initialized! - %s - %s\n",hostname,port);
>
>    if (not_avail) {
>       gtk_widget_destroy(GTK_WIDGET(not_avail));
>       not_avail=0;
>    }
>
>    gtk_widget_show_all(window);
>    gdk_window_lower(gtk_widget_get_window(GTK_WIDGET(window)));
>    gtk_window_set_keep_below(GTK_WINDOW(window), TRUE);
> }
>
> static void vnc_disconnected(GtkWidget *vncdisplay G_GNUC_UNUSED)
> {
>    printf("disconnected! - %s - %s\n",hostname,port);
>
> //   vnc_display_close(VNC_DISPLAY(vnc));
>    gtk_main_quit();
>
>    sleep (1);
>
>    vnc_display_open_host(VNC_DISPLAY(vnc), hostname, port);
>    gtk_widget_hide_all(window);
>
>    if (!not_avail) {
>       not_avail = GTK_MESSAGE_DIALOG(gtk_message_dialog_new(GTK_WINDOW(
> window),
>                                      not_avail_flags,
>                                      GTK_MESSAGE_ERROR,
>                                      GTK_BUTTONS_NONE,
>                                      "Disconnected from VNC server
> %s:%s\nAttempting reconnect",
>                                      hostname,
>                                      port));
>       gtk_widget_hide_all(GTK_WIDGET(not_avail));
>       gtk_window_set_type_hint(GTK_WINDOW(not_avail),GDK_WINDOW_
> TYPE_HINT_SPLASHSCREEN);
>       gtk_window_set_position(GTK_WINDOW(not_avail),GTK_WIN_POS_
> CENTER_ALWAYS);
>       gtk_window_set_keep_below(GTK_WINDOW(not_avail), TRUE);
>       gtk_widget_show_all(GTK_WIDGET(not_avail));
>       gdk_window_lower(gtk_widget_get_window(GTK_WIDGET(not_avail)));
>    }
>
>    gtk_main();

Hmm, running all this code from within the signal dispatch is
not a good idea & could be what's causing the problem. What you
should do in vnc_disconnected is to use g_idle_add to register
a callback to run to do the reconnect later

Daniel
--
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|



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