Changeset 486

Show
Ignore:
Timestamp:
04/05/07 22:06:33 (2 years ago)
Author:
hachi
Message:

Unfinished writing of the parse_from_sock function in XS... may make things easier or faster... but I don't even know if this code works yet.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/client-xs-20070328/Cache-Memcached-GetParserXS/GetParserXS.xs

    r485 r486  
    269269 
    270270  if (state) { 
    271     //res = read(sockfd, *buf, state); 
     271    // We're reading into a key, get the SV for the key 
     272    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 value 
     281    SV** valptr = hv_fetch(ret, keyptr, keylen, 0); 
     282    if (valptr) { 
     283      // Got a real value, must be an SV 
     284      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 length 
     293      Renew(buf, SvIV(offset) + state, char); 
     294    } 
     295 
     296    // Finally, read the data into the buffer 
     297    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    } 
    272312  } 
    273313 
     
    276316  printf("got = %x, state = %d\n", ret, state); 
    277317  return -1; 
     318} 
    278319 
    279320  /* 
     
    316357 
    317358  */ 
    318 } 
    319359 
    320360MODULE = Cache::Memcached::GetParserXS      PACKAGE = Cache::Memcached::GetParserXS