Skip Menu |

This queue is for tickets about the Log-Dispatch-Jabber CPAN distribution.

Report information
The Basics
Id: 45012
Status: new
Priority: 0/
Queue: Log-Dispatch-Jabber

People
Owner: Nobody in particular
Requestors: mschout [...] gkg.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: do not reconnect in send()
Date: Mon, 13 Apr 2009 15:27:44 -0500
To: bug-Log-Dispatch-Jabber [...] rt.cpan.org
From: Michael Schout <mschout [...] gkg.net>
Log::Dispatch::Jabber unnecessarily reconnects to the jabber server for every single recipient. This is needlessly inefficient if you are sending to multiple jabber ids. The attached patch moves the connect/disconnect outside the loop so that send() will only connect once per message.
From f670fd0eb8d736dba88ffbc82d9dd233e069eded Mon Sep 17 00:00:00 2001 From: Michael Schout <mschout@gkg.net> Date: Mon, 13 Apr 2009 15:18:28 -0500 Subject: [PATCH] do not reconnect for each recipient. --- lib/Log/Dispatch/Jabber.pm | 44 ++++++++++++++++++++++---------------------- 1 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/Log/Dispatch/Jabber.pm b/lib/Log/Dispatch/Jabber.pm index 613f66b..6d0ff8c 100644 --- a/lib/Log/Dispatch/Jabber.pm +++ b/lib/Log/Dispatch/Jabber.pm @@ -263,31 +263,31 @@ sub _send { my $im = Net::Jabber::Message->new(); $im->SetMessage(body=>join("",@{$self->{'__buffer'}}),type=>"chat"); - foreach my $addr (@{$self->{'__to'}}) { - $im->SetTo($addr); - - # + my $ok = $self->{'__client'}->Connect( + hostname => $self->{'__login'}->{'hostname'}, + port => $self->{'__login'}->{'port'}, + ); + + if (! $ok) { + $self->_error("Failed to connect to Jabber server:$!\n"); + return 0; + } - my $ok = $self->{'__client'}->Connect( - hostname => $self->{'__login'}->{'hostname'}, - port => $self->{'__login'}->{'port'}, - ); + my @auth = $self->{'__client'}->AuthSend( + username => $self->{'__login'}->{'username'}, + password => $self->{'__login'}->{'password'}, + resource => $self->{'__login'}->{'resource'}, + ); - if (! $ok) { - $self->_error("Failed to connect to Jabber server:$!\n"); - return 0; - } + if ($auth[0] ne "ok") { + $self->_error("Failed to ident/auth with Jabber server:($auth[0]) $auth[1]. Message not sent.\n"); + return 0; + } - my @auth = $self->{'__client'}->AuthSend( - username => $self->{'__login'}->{'username'}, - password => $self->{'__login'}->{'password'}, - resource => $self->{'__login'}->{'resource'}, - ); + # - if ($auth[0] ne "ok") { - $self->_error("Failed to ident/auth with Jabber server:($auth[0]) $auth[1]. Message not sent.\n"); - return 0; - } + foreach my $addr (@{$self->{'__to'}}) { + $im->SetTo($addr); # @@ -310,9 +310,9 @@ sub _send { # $self->{'__client'}->Send($im); - $self->{'__client'}->Disconnect(); } + $self->{'__client'}->Disconnect(); $self->{'__buffer'} = []; return 1; -- 1.5.6.3