[libanyevent-handle-udp-perl] 10/60: More consistent on_drain handling

Jonas Smedegaard js at alioth.debian.org
Mon Sep 30 10:05:37 UTC 2013


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libanyevent-handle-udp-perl.

commit 7949d16279501a143fe86964455e275a6dcdf3e6
Author: Leon Timmermans <fawaka at gmail.com>
Date:   Tue Feb 14 21:53:33 2012 +0100

    More consistent on_drain handling
---
 Changes                    |    1 +
 lib/AnyEvent/Handle/UDP.pm |   20 +++++++++++++++-----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/Changes b/Changes
index f10a80f..20a37b8 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
 Revision history for AnyEvent-Handle-UDP
 
 {{$NEXT}}
+          Made on_drain more consistent
 
 0.032     2012-02-14 02:13:50 Europe/Amsterdam
           Make push_send actually work
diff --git a/lib/AnyEvent/Handle/UDP.pm b/lib/AnyEvent/Handle/UDP.pm
index c825a75..4510090 100644
--- a/lib/AnyEvent/Handle/UDP.pm
+++ b/lib/AnyEvent/Handle/UDP.pm
@@ -40,6 +40,7 @@ sub BUILD {
 	my $self = shift;
 	$self->bind_to($self->_bind_addr) if $self->_has_bind_addr;
 	$self->connect_to($self->_connect_addr) if $self->_has_connect_addr;
+	$self->_drained;
 	return;
 }
 
@@ -52,11 +53,20 @@ has on_recv => (
 has on_drain => (
 	is => 'rw',
 	isa => sub { reftype($_[0]) eq 'CODE' },
-	default => sub {
-		return sub {};
+	required => 0,
+	predicate => '_has_on_drain',
+	clearer => 'clear_on_drain',
+	trigger => sub {
+		my ($self, $callback) = @_;
+		$self->_drained if not @{ $self->{buffers} };
 	},
 );
 
+sub _drained {
+	my $self = shift;
+	$self->on_drain->($self) if $self->_has_on_drain
+}
+
 has on_error => (
 	is => 'rw',
 	isa => sub { reftype($_[0]) eq 'CODE' },
@@ -162,7 +172,7 @@ sub push_send {
 	if (!$self->{writer}) {
 		my $ret = $self->_send($message, $to, $cv);
 		$self->_push_writer($message, $to, $cv) if not defined $ret and ($! == EAGAIN or $! == EWOULDBLOCK);
-		$self->on_drain->($self) if $ret;
+		$self->_drained if $ret;
 	}
 	else {
 		$self->_push_writer($message, $to, $cv);
@@ -182,7 +192,7 @@ sub _push_writer {
 	my ($self, $message, $to, $condvar) = @_;
 	push @{$self->{buffers}}, [ $message, $to, $condvar ];
 	$self->{writer} ||= AE::io $self->{fh}, 1, sub {
-		if (@{$self->{buffers}}) {
+		if (@{ $self->{buffers} }) {
 			while (my ($msg, $to, $cv) = shift @{$self->{buffers}}) {
 				my $ret = $self->_send(@{$msg}, $to, $cv);
 				if (not defined $ret) {
@@ -194,7 +204,7 @@ sub _push_writer {
 		}
 		else {
 			delete $self->{writer};
-			$self->on_drain->($self);
+			$self->_drained;
 		}
 	};
 	return $condvar;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libanyevent-handle-udp-perl.git



More information about the Pkg-perl-cvs-commits mailing list