| 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 | } |
|---|