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

Comparing AnyEvent-MP/MP/Transport.pm (file contents):
Revision 1.3 by root, Fri Jul 31 21:00:37 2009 UTC vs.
Revision 1.5 by root, Sun Aug 2 14:44:37 2009 UTC

113 peername => $peername, # for verification 113 peername => $peername, # for verification
114 ; 114 ;
115 115
116=cut 116=cut
117 117
118our @FRAMING_WANT = qw(json storable);#d##TODO#
119
118sub new { 120sub new {
119 my ($class, %arg) = @_; 121 my ($class, %arg) = @_;
120 122
121 my $self = bless \%arg, $class; 123 my $self = bless \%arg, $class;
122 124
128 if (exists $arg{connect}) { 130 if (exists $arg{connect}) {
129 $arg{tls} ||= "connect"; 131 $arg{tls} ||= "connect";
130 $arg{tls_ctx} ||= { sslv2 => 0, sslv3 => 0, tlsv1 => 1, verify => 1 }; 132 $arg{tls_ctx} ||= { sslv2 => 0, sslv3 => 0, tlsv1 => 1, verify => 1 };
131 } 133 }
132 134
133 $arg{secret} = AnyEvent::MP::default_secret () 135 $arg{secret} = AnyEvent::MP::Base::default_secret ()
134 unless exists $arg{secret}; 136 unless exists $arg{secret};
135 137
136 $self->{hdl} = new AnyEvent::Handle 138 $self->{hdl} = new AnyEvent::Handle
137 fh => delete $arg{fh}, 139 fh => delete $arg{fh},
138 rbuf_max => 64 * 1024, 140 rbuf_max => 64 * 1024,
141 autocork => 1,
142 no_delay => 1,
139 on_error => sub { 143 on_error => sub {
140 $self->error ($_[2]); 144 $self->error ($_[2]);
141 }, 145 },
142 peername => delete $arg{peername}, 146 peername => delete $arg{peername},
143 ; 147 ;
148 if exists $arg{tls} && $arg{tls_ctx}; 152 if exists $arg{tls} && $arg{tls_ctx};
149 $greeting_kv->{provider} = "AE-$VERSION"; 153 $greeting_kv->{provider} = "AE-$VERSION";
150 154
151 # send greeting 155 # send greeting
152 my $lgreeting = "aemp;$PROTOCOL_VERSION;$PROTOCOL_VERSION" # version, min 156 my $lgreeting = "aemp;$PROTOCOL_VERSION;$PROTOCOL_VERSION" # version, min
153 . ";$AnyEvent::MP::UNIQ" 157 . ";$AnyEvent::MP::Base::UNIQ"
154 . ";$AnyEvent::MP::NODE" 158 . ";$AnyEvent::MP::Base::NODE"
155 . ";" . (MIME::Base64::encode_base64 AnyEvent::MP::Util::nonce 33, "") 159 . ";" . (MIME::Base64::encode_base64 AnyEvent::MP::Base::nonce (33), "")
156 . ";hmac_md6_64_256" # hardcoded atm. 160 . ";hmac_md6_64_256" # hardcoded atm.
157 . ";json" # hardcoded atm. 161 . ";json" # hardcoded atm.
158 . ";$self->{peerhost};$self->{peerport}" 162 . ";$self->{peerhost};$self->{peerport}"
159 . (join "", map ";$_=$greeting_kv->{$_}", keys %$greeting_kv); 163 . (join "", map ";$_=$greeting_kv->{$_}", keys %$greeting_kv);
160 164
225 for @$queue; 229 for @$queue;
226 230
227 my $rmsg; $rmsg = sub { 231 my $rmsg; $rmsg = sub {
228 $_[0]->push_read ($r_framing => $rmsg); 232 $_[0]->push_read ($r_framing => $rmsg);
229 233
230 AnyEvent::MP::_inject ($_[1]); 234 AnyEvent::MP::Base::_inject ($_[1]);
231 }; 235 };
232 $hdl->push_read ($r_framing => $rmsg); 236 $hdl->push_read ($r_framing => $rmsg);
233 }); 237 });
234 }); 238 });
235 } 239 }
238} 242}
239 243
240sub error { 244sub error {
241 my ($self, $msg) = @_; 245 my ($self, $msg) = @_;
242 246
247 if ($self->{node} && $self->{node}{transport} == $self) {
248 $self->{node}->clr_transport;
249 }
243 $self->{on_error}($self, $msg); 250# $self->{on_error}($self, $msg);
244 $self->{hdl}->destroy; 251 $self->destroy;
245} 252}
246 253
247sub connected { 254sub connected {
248 my ($self) = @_; 255 my ($self) = @_;
249 256
250 (AnyEvent::MP::add_node ($self->{remote_node})) 257 my $node = AnyEvent::MP::Base::add_node ($self->{remote_node});
258 Scalar::Util::weaken ($self->{node} = $node);
251 ->set_transport ($self); 259 $node->set_transport ($self);
252} 260}
253 261
254sub send { 262sub send {
255 $_[0]{hdl}->push_write ($_[0]{s_framing} => $_[1]); 263 $_[0]{hdl}->push_write ($_[0]{s_framing} => $_[1]);
256} 264}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines