Apologies if this isn't the correct place to be reporting this issue. If that's the case, I'd be grateful if someone would point me in the right direction.
I have recently been blowing the dust off a Perl/Tk application that I wrote some 20 years ago. I'm pretty sure it was working properly back then, but I tried it against the the perl-tk package in Debian Bookworm (version 1:804.036-1+b2) and it doesn't work as expected.
I have narrowed the problem down to the way fileevent behaves. My application uses a socket and always needs a 'readable' event handler and creates a 'writable' event handler as and when it needs it. So it's regularly calling fileevent to both set and unset the 'writable' event handler.
What I'm seeing with the version of Perl/Tk that I've been using is that when the 'writable' event handler is removed, the 'readable' event handler is also removed. I can work around this behaviour by retrieving the 'readable' event handler before removing the 'writable' one and then re-setting the 'readable' handler.
Here's a script that shows the problem for me:
#!/usr/bin/perl
use strict;
use IO::Socket;
use Tk;
my $mw = MainWindow->new;
sub printHandlers {
my $sock = shift;
my $ret = $mw->fileevent($sock, 'readable');
print("readable: ${ret}\n");
$ret = $mw->fileevent($sock, 'writable');
print("writable: ${ret}\n");
}
my $sock = IO::Socket::INET->new (PeerAddr => 'google.com', PeerPort => 80, Proto => 'tcp');
print "No handlers set...\n";
printHandlers($sock);
$mw->fileevent($sock, 'readable' => sub {});
$mw->fileevent($sock, 'writable' => sub {});
print "\nBoth readable and writable handlers set...\n";
printHandlers($sock);
$mw->fileevent($sock, 'readable' => '');
print "\nReadable handler removed...\n";
printHandlers($sock);
I see the following output:
No handlers set...
readable:
writable:
Both readable and writable handlers set...
readable: Tk::Callback=ARRAY(0x556871a43960)
writable: Tk::Callback=ARRAY(0x5568718188a8)
Readable handler removed...
readable:
writable:
I would expect the last line of the above output to show a 'writable' handler because only the 'readable' handler was removed.
Interestingly, the following Tcl/Tk script doesn't show this behaviour:
No handlers set...
readable:
writable:
Both readable and writable handlers set...
readable: readHandler sock55ab4d96fc90
writable: writeHandler sock55ab4d96fc90
Readble handler removed...
readable:
writable: writeHandler sock55ab4d96fc90
This seems correct to me. Perhaps I'm using the Perl/Tk interface incorrectly. If that's the case I'd be interested to know what I'm doing wrong. Thanks.
Apologies if this isn't the correct place to be reporting this issue. If that's the case, I'd be grateful if someone would point me in the right direction.
I have recently been blowing the dust off a Perl/Tk application that I wrote some 20 years ago. I'm pretty sure it was working properly back then, but I tried it against the the perl-tk package in Debian Bookworm (version 1:804.036-1+b2) and it doesn't work as expected.
I have narrowed the problem down to the way fileevent behaves. My application uses a socket and always needs a 'readable' event handler and creates a 'writable' event handler as and when it needs it. So it's regularly calling fileevent to both set and unset the 'writable' event handler.
What I'm seeing with the version of Perl/Tk that I've been using is that when the 'writable' event handler is removed, the 'readable' event handler is also removed. I can work around this behaviour by retrieving the 'readable' event handler before removing the 'writable' one and then re-setting the 'readable' handler.
Here's a script that shows the problem for me:
I see the following output:
I would expect the last line of the above output to show a 'writable' handler because only the 'readable' handler was removed.
Interestingly, the following Tcl/Tk script doesn't show this behaviour:
I see the following output:
This seems correct to me. Perhaps I'm using the Perl/Tk interface incorrectly. If that's the case I'd be interested to know what I'm doing wrong. Thanks.