leont / anyevent-handle-udp Goto Github PK
View Code? Open in Web Editor NEWClient/server UDP handles for AnyEvent
Client/server UDP handles for AnyEvent
I want to shutdown the handle when i encounter some strange behavior in on_recv()
, so i call destroy()
... but this produce an error recv() on closed socket GEN24 at /path/to/AnyEvent/Handle/UDP.pm line 151.
Perhaps there should be a check at line 151 if $self->{reader} still exists?
while (exists($self->{reader}) and defined (my $addr = recv $self->{fh}, ...) {
on_timeout keep executing even after Handle ->destroy
#! perl
use strict;
use warnings FATAL => 'all';
use Test::More tests => 2;
use AnyEvent::Handle::UDP;
use Socket qw/unpack_sockaddr_in/;
use IO::Socket::INET;
alarm 6;
{
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 = getsockname $socket;
my $client;
my $cb = sub {
is shift, "TIMEOUT", 'first client timed out';
$client->destroy;
};
$client = AnyEvent::Handle::UDP->new(
connect => $sockaddr,
on_recv => $cb,
on_error => $cb,
timeout => 1,
on_timeout => sub { $cb->("TIMEOUT"); return; },
);
my $cb2 = AE::cv;
my $client2 = AnyEvent::Handle::UDP->new(
connect => $sockaddr,
on_recv => $cb2,
on_error => $cb2,
timeout => 4,
on_timeout => sub { $cb2->("TIMEOUT"); return; },
);
$client->push_send('test');
$client2->push_send('test');
is(
$cb2->recv,
"TIMEOUT",
'second client timed out'
);
}
Hello, thank you for the great module.
Is it possible to setup secure connection using DTLS or SSL over UDP?
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');
}
Hi, I tried to use this module, but didn't work as expected.
I guess _send() in push_send should be _send($message, $to)
please make sure of it.
Cheers,
BEFORE
sub push_send {
my ($self, $message, $to) = @_;
my $ret = $self->_send();
$self->_push_writer($message, $to) if not defined $ret and ($! == EAGAIN or $! == EWOULDBLOCK);
return;
}
AFTER
sub push_send {
my ($self, $message, $to) = @_;
my $ret = $self->_send($message, $to);
$self->_push_writer($message, $to) if not defined $ret and ($! == EAGAIN or $! == EWOULDBLOCK);
return;
}
Hi,
when using AnyEvent::Handle::UDP with a hostname in the connect argument there is (ofc) a short delay till the handle is working properly.
For the first push_send i reveice the following error:
Bad filehandle: GEN0 at /path/to/AnyEvent/Handle/UDP.pm line 288.
Perhaps there should be some kind of queueing or at least a better error message, when using a hostname and imitiatly use the handle and the fh is not ready.
please consider passing $self so that it is possible to use it as a client module.
Also, the use of the ::Handle namespace is very confusing as it implies that ::Handle::UDP is a subclass of AnyEvent::Handle, I was very surprised when it was not!
$self->_error->(...)
The second ->
is wrong, so timeouts are not working:
Can't use an undefined value as a subroutine reference at /path/to/AnyEvent/Handle/UDP.pm line 103.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.