[libanyevent-handle-udp-perl] 11/60: Handle condvars more robustly and efficiently

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 673afbc6f56b2acbc62ba1797640436c4d9f7b38
Author: Leon Timmermans <fawaka at gmail.com>
Date:   Tue Feb 14 22:37:18 2012 +0100

    Handle condvars more robustly and efficiently
---
 Changes                    |    1 +
 lib/AnyEvent/Handle/UDP.pm |   10 +++++-----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/Changes b/Changes
index 20a37b8..101cb35 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
 Revision history for AnyEvent-Handle-UDP
 
 {{$NEXT}}
+          Make push_send optionally take a $cv, and only return one if called in non-void context
           Made on_drain more consistent
 
 0.032     2012-02-14 02:13:50 Europe/Amsterdam
diff --git a/lib/AnyEvent/Handle/UDP.pm b/lib/AnyEvent/Handle/UDP.pm
index 4510090..c7809d9 100644
--- a/lib/AnyEvent/Handle/UDP.pm
+++ b/lib/AnyEvent/Handle/UDP.pm
@@ -167,8 +167,8 @@ sub _error {
 }
 
 sub push_send {
-	my ($self, $message, $to) = @_;
-	my $cv = AnyEvent::CondVar->new;
+	my ($self, $message, $to, $cv) = @_;
+	$cv ||= defined wantarray ? AnyEvent::CondVar->new : undef;
 	if (!$self->{writer}) {
 		my $ret = $self->_send($message, $to, $cv);
 		$self->_push_writer($message, $to, $cv) if not defined $ret and ($! == EAGAIN or $! == EWOULDBLOCK);
@@ -184,7 +184,7 @@ sub _send {
 	my ($self, $message, $to, $cv) = @_;
 	my $ret = defined $to ? send $self->{fh}, $message, 0, $to : send $self->{fh}, $message, 0;
 	$self->on_error->($self->{fh}, 1, "$!") if not defined $ret and ($! != EAGAIN and $! != EWOULDBLOCK);
-	$cv->($ret) if defined $ret;
+	$cv->($ret) if defined $cv and defined $ret;
 	return $ret;
 }
 
@@ -276,9 +276,9 @@ Bind to the specified addres. Note that a bound socket may be rebound to another
 
 Connect to the specified address. Note that a connected socket may be reconnected to another address. C<$address> must be in the same form as the connect argument to new.
 
-=method push_send($message, $to?)
+=method push_send($message, $to = undef, $cv = AnyEvent::CondVar->new)
 
-Try to send a message. If a socket is not connected a receptient address must also be given. If it is connected giving a receptient may not work as expected, depending on your platform.
+Try to send a message. If a socket is not connected a receptient address must also be given. If it is connected giving a receptient may not work as expected, depending on your platform. It returns C<$cv>, which will become true when C<$message> is sent.
 
 =method destroy
 

-- 
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