Changeset 529
- Timestamp:
- 05/02/07 21:57:25 (2 years ago)
- Files:
-
- branches/client-xs-20070328/Cache-Memcached-GetParserXS (modified) (1 prop)
- branches/client-xs-20070328/Cache-Memcached-GetParserXS/GetParserXS.xs (modified) (1 diff)
- branches/client-xs-20070328/Cache-Memcached-GetParserXS/Makefile.PL (modified) (1 diff)
- branches/client-xs-20070328/Cache-Memcached-GetParserXS/const-c.inc (deleted)
- branches/client-xs-20070328/Cache-Memcached-GetParserXS/const-xs.inc (deleted)
- branches/client-xs-20070328/Cache-Memcached-GetParserXS/lib/Cache/Memcached/GetParserXS.pm (modified) (3 diffs)
- branches/client-xs-20070328/Cache-Memcached-GetParserXS/t/Cache-Memcached-GetParserXS.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/client-xs-20070328/Cache-Memcached-GetParserXS
- Property svn:ignore set to
const-xs.inc
const-c.inc
GetParserXS.c
*.diff
notes.txt
*blib
*.bs
Makefile
Makefile.old
- Property svn:ignore set to
branches/client-xs-20070328/Cache-Memcached-GetParserXS/GetParserXS.xs
r528 r529 262 262 } 263 263 264 int parse_from_sock_xx (SV* selfref, SV* sock, int sockfd) {265 int res;266 AV* self = (AV*) SvRV(selfref);267 HV* ret = get_dest(self);268 IV state = get_state(self);269 270 if (state) {271 // We're reading into a key, get the SV for the key272 SV* key = get_key_sv(self);273 SV* offset = get_offset_sv(self);274 STRLEN keylen;275 char *keyptr = SvPV(key, keylen);276 277 STRLEN buflen;278 char* buf;279 280 // Then we try to get the value281 SV** valptr = hv_fetch(ret, keyptr, keylen, 0);282 if (valptr) {283 // Got a real value, must be an SV284 buf = SvPV(*valptr, buflen);285 } else {286 // If we get null back, it's because the entry didn't exist, vivify it.287 New(0, buf, state, char);288 *valptr = newSVpvn(buf, state);289 }290 291 if (buflen < SvIV(offset) + state) {292 // Buffer is too short, Renew it to the proper length293 Renew(buf, SvIV(offset) + state, char);294 }295 296 // Finally, read the data into the buffer297 res = read(sockfd, (buf + SvIV(offset)), (state - SvIV(offset)));298 299 if (res < 0 && errno == EWOULDBLOCK)300 return 0;301 302 if (res == 0) {303 clear_on_item(self);304 return -1;305 }306 307 sv_setiv(offset, (SvIV(offset) + res));308 309 if (SvIV(offset) == state) {310 311 }312 }313 314 printf("fileno = %d\n", sockfd);315 316 printf("got = %x, state = %d\n", ret, state);317 return -1;318 }319 320 /*321 # where are we reading into?322 if ($self->[STATE]) { # reading value into $ret323 $res = sysread($sock, $ret->{$self->[KEY]},324 $self->[STATE] - $self->[OFFSET],325 $self->[OFFSET]);326 327 return 0328 if !defined($res) and $!==EWOULDBLOCK;329 330 if ($res == 0) { # catches 0=conn closed or undef=error331 $self->[ON_ITEM] = undef;332 return -1;333 }334 335 $self->[OFFSET] += $res;336 if ($self->[OFFSET] == $self->[STATE]) { # finished reading337 $self->[ON_ITEM]->($self->[KEY], $self->[FLAGS]);338 $self->[OFFSET] = 0;339 $self->[STATE] = 0;340 # wait for another VALUE line or END...341 }342 return 0; # still working, haven't got to end yet343 }344 345 # we're reading a single line.346 # first, read whatever's there, but be satisfied with 2048 bytes347 $res = sysread($sock, $self->[BUF],348 2048, $self->[OFFSET]);349 return 0350 if !defined($res) and $!==EWOULDBLOCK;351 if ($res == 0) {352 $self->[ON_ITEM] = undef;353 return -1;354 }355 356 $self->[OFFSET] += $res;357 358 */359 360 264 MODULE = Cache::Memcached::GetParserXS PACKAGE = Cache::Memcached::GetParserXS 361 265 362 266 INCLUDE: const-xs.inc 363 364 int365 parse_from_sock_xx ( self, sock, sockfd )366 SV *self367 SV *sock368 int sockfd369 267 370 268 int branches/client-xs-20070328/Cache-Memcached-GetParserXS/Makefile.PL
r526 r529 5 5 WriteMakefile( 6 6 OPTIMIZE => '-g', 7 NAME => 'Cache::Memcached::GetParserXS', 8 VERSION_FROM => 'lib/Cache/Memcached/GetParserXS.pm', # finds $VERSION 9 PREREQ_PM => {}, # e.g., Module::Name => 1.1 10 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 11 (ABSTRACT_FROM => 'lib/Cache/Memcached/GetParserXS.pm', # retrieve abstract from module 12 AUTHOR => 'LiveJournal user <lj@>') : ()), 13 LIBS => [''], # e.g., '-lm' 14 DEFINE => '', # e.g., '-DHAVE_SOMETHING' 15 INC => '-I.', # e.g., '-I. -I/usr/include/other' 16 # Un-comment this if you add C files to link with later: 17 # OBJECT => '$(O_FILES)', # link all the C files too 18 ); 7 NAME => 'Cache::Memcached::GetParserXS', 8 VERSION_FROM => 'lib/Cache/Memcached/GetParserXS.pm', # finds $VERSION 9 PREREQ_PM => { 10 'Cache::Memcached' => 1.21, 11 }, # e.g., Module::Name => 1.1 12 ABSTRACT_FROM => 'lib/Cache/Memcached/GetParserXS.pm', # retrieve abstract from module 13 AUTHOR => 'LiveJournal user <lj@>', 14 LIBS => [''], # e.g., '-lm' 15 DEFINE => '', # e.g., '-DHAVE_SOMETHING' 16 INC => '-I.', # e.g., '-I. -I/usr/include/other' 17 # Un-comment this if you add C files to link with later: 18 # OBJECT => '$(O_FILES)', # link all the C files too 19 ); 20 19 21 if (eval {require ExtUtils::Constant; 1}) { 20 22 # If you edit these definitions to change the constants used by this module, branches/client-xs-20070328/Cache-Memcached-GetParserXS/lib/Cache/Memcached/GetParserXS.pm
r528 r529 9 9 use Errno qw( EINPROGRESS EWOULDBLOCK EISCONN ); 10 10 use AutoLoader; 11 use Cache::Memcached 1.21; 11 12 12 13 our $VERSION = '0.01'; … … 45 46 sub current_key { 46 47 return $_[0][KEY]; 48 } 49 50 sub t_parse_buf { 51 my ($self, $buf) = @_; 52 # force buf into \r\n format 53 $buf =~ s/\n/\r\n/g; 54 $buf =~ s/\r\r/\r/g; 55 56 $self->[BUF] .= $buf; 57 $self->[OFFSET] += length $buf; 58 my $rv = $self->parse_buffer; 59 if ($rv > 0) { 60 $self->[ON_ITEM]->($self->[FINISHED]); 61 $self->[ON_ITEM] = undef; 62 } 63 return $rv; 47 64 } 48 65 … … 92 109 93 110 if ($answer > 0) { 94 my $finished = $self->[FINISHED]; 95 my $finalize = $self->[ON_ITEM]; 96 97 while (my ($key, $flags) = each %$finished) { 98 $finalize->($key, $flags); 99 } 111 $self->[ON_ITEM]->($self->[FINISHED]); 100 112 $self->[ON_ITEM] = undef; 101 113 } branches/client-xs-20070328/Cache-Memcached-GetParserXS/t/Cache-Memcached-GetParserXS.t
r524 r529 1 use Test::More tests => 2; 1 #!/usr/bi/perl 2 3 use Test::More tests => 6; 2 4 BEGIN { use_ok('Cache::Memcached::GetParserXS') }; 5 use Data::Dumper; 3 6 4 my $parser = Cache::Memcached::GetParserXS->new({}, 0, sub {}); 5 ok($parser, "Parser object was created"); 7 my $fin; 8 my $p = new_parser(); 9 ok($p, "Parser object was created"); 10 11 # simple case 12 $p->t_parse_buf("VALUE foo 0 3 13 bar 14 END 15 "); 16 is_deeply($fin, { foo => 0 }, "got foo"); 17 18 # in chunks... 19 $p = new_parser(); 20 $p->t_parse_buf("VALUE foo 0 3 21 bar 22 VALUE bar 1 3 23 baz 24 "); 25 is($fin, undef, "nothing yet"); 26 $p->t_parse_buf("END"); 27 is($fin, undef, "nothing yet"); 28 $p->t_parse_buf("\n"); 29 is_deeply($fin, { foo => 0, bar => 1 }, "got 'em"); 30 31 32 sub new_parser { 33 $fin = undef; 34 Cache::Memcached::GetParserXS->new({}, 0, sub { $fin = $_[0] }); 35 }
