Leont / anyevent-handle-udp

Client/server UDP handles for AnyEvent
5 stars 3 forks source link

Uncaught error on sending to the closed port #5

Closed und3f closed 7 years ago

und3f commented 7 years ago

Hello, I have an issue with latest versions (later than 0.043), if I am trying to send some message to closed port it just generates uncagh error. Not able to handle this using on_error. Also this test works correctly with older version 0.043 Tests:

#! perl

use strict;
use warnings FATAL   => 'all';
use Test::More tests => 1;
use AnyEvent::Handle::UDP;
use Socket qw/unpack_sockaddr_in/;
use IO::Socket::INET;

alarm 3;

{

    my $addr = inet_aton('localhost');
    socket my $socket, PF_INET, SOCK_DGRAM, 0
      or die "Unable to create socket: $!";

    connect $socket, pack_sockaddr_in(0, $addr) or die "connect: $!";

    my $sockaddr_closed = getsockname $socket;
    close $socket or die "close: $!";

    my $cb     = AE::cv;
    my $client = AnyEvent::Handle::UDP->new(
        connect  => $sockaddr_closed,
        on_recv  => $cb,
        on_error => sub { $cb->send($_[2]) },
        timeout => 2,
        on_timeout => $cb,
    );
    $client->push_send("test");
    is($cb->recv, "Couldn't recv: Connection refused", 'Got connection refused error');
}
Leont commented 7 years ago

Sorry about that, it seems I made a mistake in my recent rewrite (0.045). 0.047 should solve your problem.

und3f commented 7 years ago

I suggest to add this test to the distro.

Leont commented 7 years ago

I suggest to add this test to the distro.

Patches are most welcome.