Subject: | Doesn't work on MSWin32 plaforms |
The code in the attached patch is working for me. The various pieces
were pillaged from code that has been in production for several years.
Subject: | UDP.patch |
*** lib/POE/Wheel/UDP.pm.orig 2009-02-19 13:15:15.000000000 -0500
--- lib/POE/Wheel/UDP.pm 2009-02-19 13:47:08.000000000 -0500
***************
*** 55,65 ****
use POE;
use Carp;
use Socket;
! use Fcntl;
! our $VERSION = '0.02';
$VERSION = eval $VERSION; # see L<perlmodstyle>
=head1 Package Methods
=head2 $wheel = POE::Wheel::UDP->new( OPTIONS );
--- 55,77 ----
use POE;
use Carp;
use Socket;
! use POSIX qw(:fcntl_h);
! our $VERSION = '0.03';
$VERSION = eval $VERSION; # see L<perlmodstyle>
+ my $DONTWAIT = ( $^O eq 'MSWin32' ) ? 0 : MSG_DONTWAIT;
+ # http://rt.cpan.org/Public/Bug/Display.html?id=11938
+ # Actually, almost by chance I discovered that the last param to
+ # the ioctl has to be a reference param... Changing the code as
+ # follows makes it work:
+ #
+ # my $nonblocking = $blocking ? 0 : 1;
+ # ioctl($self, 0x8004667e, \$nonblocking);
+ #
+ # 1 => makes the socket non blocking, 0 => makes the socket blocking
+ my $NONBLOCKING = 1;
+
=head1 Package Methods
=head2 $wheel = POE::Wheel::UDP->new( OPTIONS );
***************
*** 188,194 ****
$poe_kernel->state( $read_event, sub {
my ($kernel, $socket) = @_[KERNEL, ARG0];
$! = undef;
! while( my $addr = recv( $socket, my $input = "", 1500, MSG_DONTWAIT ) ) {
if (defined( $addr )) {
my %input_data;
--- 200,206 ----
$poe_kernel->state( $read_event, sub {
my ($kernel, $socket) = @_[KERNEL, ARG0];
$! = undef;
! while( my $addr = recv( $socket, my $input = "", 1500, $DONTWAIT ) ) {
if (defined( $addr )) {
my %input_data;
***************
*** 244,251 ****
socket( my $sock, PF_INET, SOCK_DGRAM, $proto )
or die( "socket() failure: $!" );
! fcntl( $sock, F_SETFL, O_NONBLOCK | O_RDWR )
! or die( "fcntl problem: $!" );
setsockopt( $sock, SOL_SOCKET, SO_REUSEADDR, 1 )
or die( "setsockopt SO_REUSEADDR failed: $!" );
--- 256,267 ----
socket( my $sock, PF_INET, SOCK_DGRAM, $proto )
or die( "socket() failure: $!" );
! if ( $^O eq 'MSWin32' ) {
! ioctl($sock, 0x8004667e, \$NONBLOCKING);
! } else {
! fcntl( $sock, F_SETFL, O_NONBLOCK | O_RDWR )
! or die( "fcntl problem: $!" );
! }
setsockopt( $sock, SOL_SOCKET, SO_REUSEADDR, 1 )
or die( "setsockopt SO_REUSEADDR failed: $!" );
***************
*** 332,349 ****
my $port = $thing->{port} or die;
foreach my $output (@$records) {
! $bytes = send( $sock, $output, MSG_DONTWAIT, sockaddr_in( $port,inet_aton( $addr ) ) );
}
}
elsif (exists( $self->{default_send} )) {
my $default_send = $self->{default_send};
foreach my $output (@$records) {
! $bytes = send( $sock, $output, MSG_DONTWAIT, $default_send );
}
}
else {
foreach my $output (@$records) {
! $bytes = send( $sock, $output, MSG_DONTWAIT );
}
}
--- 348,365 ----
my $port = $thing->{port} or die;
foreach my $output (@$records) {
! $bytes = send( $sock, $output, $DONTWAIT, sockaddr_in( $port,inet_aton( $addr ) ) );
}
}
elsif (exists( $self->{default_send} )) {
my $default_send = $self->{default_send};
foreach my $output (@$records) {
! $bytes = send( $sock, $output, $DONTWAIT, $default_send );
}
}
else {
foreach my $output (@$records) {
! $bytes = send( $sock, $output, $DONTWAIT );
}
}