Subject: | Socket no longer blocking after being passed to Mail::IMAPClient |
I had a report from a user of my Script GhettoPush
https://github.com/mschmitt/GhettoPush (which converts IDLE updates to
iPhone push messages) that he can't use it on Debian Squeeze.
Squeeze has a packaged Mail::IMAPClient 3.25 but I have developed my
Script 2 years ago on 3.18, which is what I still have installed on my
Debian system from CPAN.
The script opens a socket first and hands it to Mail::IMAPClient for
further use.
Some testing turns up that 3.25 and 3.28 convert this socket into a
non-blocking socket, which is why waiting for messages in the IDLE
session fails. Due to the non-blocking socket, the script does not wait
for data from the socket and fails miserably.
I would rather not refactor my script to use the new idle_data function
as I do not want to lose backwards compatibility.
Can you let me know why the socket isn't blocking anymore after being
used by Mail::IMAPClient? Is this intended behaviour? How can it be
undone? Is there a Workaround?
Sample script. Mail::IMAPClient 3.28 is in /home/martin/perllib,
Mail::IMAPClient 3.18 is in /usr/local/lib/perl/whatever. If using
Version 3.18, the script blocks at the read attempt, as expected:
#!/usr/bin/perl -w
use strict;
use diagnostics;
#use lib qw(/home/martin/perllib);
use IO::Socket::INET;
use Mail::IMAPClient;
my $socket = IO::Socket::INET->new(
PeerAddr => '127.0.0.1',
PeerPort => 143,
Timeout => 30
);
unless ($socket){
die "Connection failed.\n";
}
my $imap = Mail::IMAPClient->new(
Socket => $socket,
Timeout => 60
);
<$socket>;
print "If you can read this, the socket is not blocking.\n";