Implementing Gtk2->main in select?



  Hello everybody.

I'm new to this list and Gtk2-perl. I've got one question. How should I add Gtk2->main that it doesn't stop all program. I must listen on UDP and in same time UI must be responsive. When something comes to UDP socket i call sub and echo something on GTK UI. I have this code:

vyc_startup();

my $gladexml = Gtk2::GladeXML->new('gnovyc.glade');
$gladexml->signal_autoconnect_from_package('main');

# IO::Socket stuff. Watches when there is data on socket that can be read.
while (my @ready = $select->can_read) {
    # for each buffer read from buffer to scalar.
    foreach $fh (@ready) { $fh->sysread($buffer, 1024); }
    if ($buffer =~ /^quit$/) { vyc_shutdown(); }
    # Who's here?
    elsif ($buffer =~ /^\x58.{9}0.+\x00$/) {
        my ($updater) = $buffer =~ /^\x58.{9}0(.+)\x00$/;
        print "$updater asked who's here --- [$buffer]\n" if $debug;
        i_am_here($updater);
    }
}

sub vyc_startup {
    my $port = 8167;
    # Create sending socket
    $sock = IO::Socket::INET->new(
                        PeerAddr => inet_ntoa(INADDR_BROADCAST),
                                 PeerPort => $port,
                                 Proto    => 'udp',
                                 Broadcast => 1 ) || die ("Can't"
                                ."establish socket: $!\n");
    print "Established socket on port $port\n" if $debug;
    # Listening socket. That's one i've got to listen on.
    $listen = IO::Socket::INET->new ( LocalPort => $port,
                                 Proto    => 'udp') || die ("Can't"
                                ." establish listen socket: $!\n");
    print "Established listen socket on port $port\n" if $debug;
    # I use IO::Select to watch on the sockets.
    $select = IO::Select->new;
    $select->add(\*STDIN);
    $select->add($listen);
    join_chan("#Main", $status, $gender);
    who_is_here();
}
# And this is real shutdown sequence.
sub vyc_shutdown {
    part_chan("#Main", $gender);
    exit;
}
# I call this sub on quit from GTK UI.
sub gtk_main_quit {
    Gtk2->main_quit;
    vyc_shutdown();
}

Well I think you get the idea. So how i would add Gtk2->main so it doesn't stop watching on UDP ($listen) socket?
--
Sincerely, ArtÃras 'arturaz' Ãlajus
You can find me at:
irc.freenode.org: nick arturaz
irc.data.lt: nick arturaz
ICQ: 157929934
Jabber: arturaz akl lt




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