ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/MP/DataConn.pm
(Generate patch)

Comparing AnyEvent-MP/MP/DataConn.pm (file contents):
Revision 1.5 by root, Sun Nov 8 23:53:08 2009 UTC vs.
Revision 1.6 by root, Sun Nov 8 23:58:02 2009 UTC

159=cut 159=cut
160 160
161sub connect_to($$$$@) { 161sub connect_to($$$$@) {
162 my $cb = pop; 162 my $cb = pop;
163 my ($node, $timeout, $initfunc, @initdata) = @_; 163 my ($node, $timeout, $initfunc, @initdata) = @_;
164
164 my $port = $SELF; 165 my $port = $SELF
166 or Carp::croak "AnyEvent::MP::DataConn::connect_to must be called in port context";
167
165 $node = node_of $node; 168 $node = node_of $node;
166 169
167 my $id = (++$ID) . "\@$NODE"; 170 my $id = (++$ID) . "\@$NODE";
168 171
169 # damn, why do my simple state hashes resemble objects so quickly 172 # damn, why do my simple state hashes resemble objects so quickly
185 } 188 }
186 }, 189 },
187 }; 190 };
188 191
189 if (AnyEvent::MP::Kernel::port_is_local $node) { 192 if (AnyEvent::MP::Kernel::port_is_local $node) {
190 return kil $port, AnyEvent::MP::DataConn:: => 193 # teh sucks
191 "connect_to does not yet support local/local connections, please bug me about it"; 194
195 require AnyEvent::Util;
196 my ($fh1, $fh2) = AnyEvent::Util::portable_socketpair ()
197 or return kil $port, AnyEvent::MP::DataConn:: => "cannot create local socketpair: $!";
198
199 use AnyEvent::Handle;
200 my $hdl1 = new AnyEvent::Handle fh => $fh1;
201 my $hdl2 = new AnyEvent::Handle fh => $fh2;
202
203 (AnyEvent::MP::Kernel::load_func $initfunc)->(@initdata, $hdl2);
204 $cb->($hdl1);
192 205
193 } else { 206 } else {
194 AnyEvent::MP::Kernel::snd_to_func $node, 207 AnyEvent::MP::Kernel::snd_to_func $node,
195 AnyEvent::MP::DataConn::_expect:: => $id, $port, $timeout, $initfunc, @initdata; 208 AnyEvent::MP::DataConn::_expect:: => $id, $port, $timeout, $initfunc, @initdata;
196 209

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines