ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Handle.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Handle.pm (file contents):
Revision 1.109 by root, Wed Jan 14 02:03:43 2009 UTC vs.
Revision 1.115 by root, Tue Feb 10 13:58:49 2009 UTC

767 ) { 767 ) {
768 $self->_error (&Errno::ENOSPC, 1), return; 768 $self->_error (&Errno::ENOSPC, 1), return;
769 } 769 }
770 770
771 while () { 771 while () {
772 $self->{rbuf} .= delete $self->{tls_rbuf} if exists $self->{tls_rbuf};#d#
773
772 my $len = length $self->{rbuf}; 774 my $len = length $self->{rbuf};
773 775
774 if (my $cb = shift @{ $self->{_queue} }) { 776 if (my $cb = shift @{ $self->{_queue} }) {
775 unless ($cb->($self)) { 777 unless ($cb->($self)) {
776 if ($self->{_eof}) { 778 if ($self->{_eof}) {
1144 } 1146 }
1145}; 1147};
1146 1148
1147=item json => $cb->($handle, $hash_or_arrayref) 1149=item json => $cb->($handle, $hash_or_arrayref)
1148 1150
1149Reads a JSON object or array, decodes it and passes it to the callback. 1151Reads a JSON object or array, decodes it and passes it to the
1152callback. When a parse error occurs, an C<EBADMSG> error will be raised.
1150 1153
1151If a C<json> object was passed to the constructor, then that will be used 1154If a C<json> object was passed to the constructor, then that will be used
1152for the final decode, otherwise it will create a JSON coder expecting UTF-8. 1155for the final decode, otherwise it will create a JSON coder expecting UTF-8.
1153 1156
1154This read type uses the incremental parser available with JSON version 1157This read type uses the incremental parser available with JSON version
1171 my $rbuf = \$self->{rbuf}; 1174 my $rbuf = \$self->{rbuf};
1172 1175
1173 my $json = $self->{json} ||= JSON->new->utf8; 1176 my $json = $self->{json} ||= JSON->new->utf8;
1174 1177
1175 sub { 1178 sub {
1176 my $ref = $json->incr_parse ($self->{rbuf}); 1179 my $ref = eval { $json->incr_parse ($self->{rbuf}) };
1177 1180
1178 if ($ref) { 1181 if ($ref) {
1179 $self->{rbuf} = $json->incr_text; 1182 $self->{rbuf} = $json->incr_text;
1180 $json->incr_text = ""; 1183 $json->incr_text = "";
1181 $cb->($self, $ref); 1184 $cb->($self, $ref);
1182 1185
1183 1 1186 1
1187 } elsif ($@) {
1188 # error case
1189 $json->incr_skip;
1190
1191 $self->{rbuf} = $json->incr_text;
1192 $json->incr_text = "";
1193
1194 $self->_error (&Errno::EBADMSG);
1195
1196 ()
1184 } else { 1197 } else {
1185 $self->{rbuf} = ""; 1198 $self->{rbuf} = "";
1199
1186 () 1200 ()
1187 } 1201 }
1188 } 1202 }
1189}; 1203};
1190 1204
1331 delete $self->{_rw}; 1345 delete $self->{_rw};
1332 $self->{_eof} = 1; 1346 $self->{_eof} = 1;
1333 &_freetls; 1347 &_freetls;
1334 } 1348 }
1335 1349
1336 $self->{rbuf} .= $tmp; 1350 $self->{tls_rbuf} .= $tmp;#d#
1337 $self->_drain_rbuf unless $self->{_in_drain}; 1351 $self->_drain_rbuf unless $self->{_in_drain};
1338 $self->{tls} or return; # tls session might have gone away in callback 1352 $self->{tls} or return; # tls session might have gone away in callback
1339 } 1353 }
1340 1354
1341 $tmp = Net::SSLeay::get_error ($self->{tls}, -1); 1355 $tmp = Net::SSLeay::get_error ($self->{tls}, -1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines