summaryrefslogtreecommitdiff
path: root/lib/POE
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-07-17 18:26:04 +0200
committerYorhel <git@yorhel.nl>2009-07-17 18:26:04 +0200
commite6be8bfffb5344ec8adfc1d67baf8f7cebfb395b (patch)
treed83a7a42bca6f91bad27ffcc6e9f615110ce8470 /lib/POE
parent3aca4f551791a99503398fdfeceaf74bd56ba80e (diff)
Send LISTEN queries on (re)connect
Diffstat (limited to 'lib/POE')
-rw-r--r--lib/POE/Component/Pg.pm10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/POE/Component/Pg.pm b/lib/POE/Component/Pg.pm
index 174ab60..076d4b7 100644
--- a/lib/POE/Component/Pg.pm
+++ b/lib/POE/Component/Pg.pm
@@ -149,6 +149,12 @@ sub connect {
return sendevent \@_, 'error', 'connect', $@;
}
+ # send LISTEN queries before any other queued statements
+ $_[HEAP]{queue} = [
+ map([ 'do', undef, "LISTEN $_->[1]", undef, undef, undef ], @{$_[HEAP]{listen}}),
+ @{$_[HEAP]{queue}}
+ ] if @{$_[HEAP]{listen}};
+
# put PgSQL's socket into POE's event loop, this enables us
# to receive NOTIFY events and SQL results without polling
open $_[HEAP]{fh}, '<&=', $_[HEAP]{dbi}->{pg_socket};
@@ -171,7 +177,7 @@ sub listen {
} else {
$r->[2] = $listen{$e};
}
- $_[KERNEL]->call($_[SESSION], 'do', "LISTEN $e");
+ $_[KERNEL]->call($_[SESSION], 'do', "LISTEN $e") if $_[HEAP]{dbi};
}
}
@@ -271,7 +277,7 @@ sub dbi_canread {
} elsif($item->[QEVENT]) {
$_[KERNEL]->post($item->[QSESID], $item->[QEVENT], $num, $res, exists $item->[QARG] ? $item->[QARG] : ());
}
- $_[KERNEL]->refcount_decrement($item->[QSESID], 'P:C:PG');
+ $_[KERNEL]->refcount_decrement($item->[QSESID], 'P:C:PG') if defined $item->[QSESID];
# execute next query in the queue, if any
$_[KERNEL]->call($_[SESSION], 'process_queue');