From 468615e4f51119166add732b5af6fa440711aaa2 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 13 Mar 2010 17:38:32 +0100 Subject: [PATCH] Return connection status in condvar in $i3->connect --- lib/AnyEvent/I3.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index c11acf01..bf25bda4 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -60,6 +60,7 @@ our @EXPORT = qw(i3); my $magic = "i3-ipc"; +# TODO: export constants for message types # TODO: auto-generate this from the header file? (i3/ipc.h) my $event_mask = (1 << 31); my %events = ( @@ -93,7 +94,12 @@ sub new { =head2 $i3->connect Establishes the connection to i3. Returns an C which will -be triggered as soon as the connection has been established. +be triggered with a boolean (true if the connection was established) as soon as +the connection has been established. + + if ($i3->connect->recv) { + say "Connected to i3"; + } =cut sub connect { @@ -104,12 +110,14 @@ sub connect { tcp_connect "unix/", $self->{path}, sub { my ($fh) = @_; + return $cv->send(0) unless $fh; + $self->{ipchdl} = AnyEvent::Handle->new( fh => $fh, on_read => sub { my ($hdl) = @_; $self->_data_available($hdl) } ); - $cv->send + $cv->send(1) }; $cv -- 2.39.5