From: Michael Stapelberg Date: Sat, 13 Mar 2010 16:38:32 +0000 (+0100) Subject: Return connection status in condvar in $i3->connect X-Git-Tag: AnyEvent-0.02~17 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=468615e4f51119166add732b5af6fa440711aaa2;p=i3%2Fi3 Return connection status in condvar in $i3->connect --- 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