MCPcopy Create free account
hub / github.com/DeNA/HandlerSocket-Plugin-for-MySQL / response_recv

Method response_recv

libhsclient/hstcpcli.cpp:325–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

323}
324
325int
326hstcpcli::response_recv(size_t& num_flds_r)
327{
328 if (error_code < 0) {
329 return error_code;
330 }
331 clear_error();
332 if (num_req_bufd > 0 || num_req_sent == 0 || num_req_rcvd > 0 ||
333 response_end_offset != 0) {
334 close();
335 return set_error(-1, "response_recv: protocol out of sync");
336 }
337 cur_row_offset = 0;
338 num_flds_r = num_flds = 0;
339 if (fd.get() < 0) {
340 return set_error(-1, "read: closed");
341 }
342 size_t offset = 0;
343 while (true) {
344 const char *const lbegin = readbuf.begin() + offset;
345 const char *const lend = readbuf.end();
346 const char *const nl = memchr_char(lbegin, '\n', lend - lbegin);
347 if (nl != 0) {
348 offset = (nl + 1) - readbuf.begin();
349 break;
350 }
351 if (read_more() <= 0) {
352 close();
353 return set_error(-1, "read: eof");
354 }
355 }
356 response_end_offset = offset;
357 --num_req_sent;
358 ++num_req_rcvd;
359 char *start = readbuf.begin();
360 char *const finish = start + response_end_offset - 1;
361 const size_t resp_code = read_ui32(start, finish);
362 skip_one(start, finish);
363 num_flds_r = num_flds = read_ui32(start, finish);
364 if (resp_code != 0) {
365 skip_one(start, finish);
366 char *const err_begin = start;
367 read_token(start, finish);
368 char *const err_end = start;
369 std::string e = std::string(err_begin, err_end - err_begin);
370 if (e.empty()) {
371 e = "unknown_error";
372 }
373 return set_error(resp_code, e);
374 }
375 cur_row_offset = start - readbuf.begin();
376 DBG(fprintf(stderr, "[%s] ro=%zu eol=%zu\n",
377 std::string(readbuf.begin(), readbuf.begin() + response_end_offset)
378 .c_str(),
379 cur_row_offset, response_end_offset));
380 DBG(fprintf(stderr, "RES 0\n"));
381 return 0;
382}

Callers 8

hstcpcli_mainFunction · 0.80
runMethod · 0.80
op_insertMethod · 0.80
op_deleteMethod · 0.80
op_updateMethod · 0.80
op_readMethod · 0.80
op_readnolockMethod · 0.80
test_11Method · 0.80

Calls 8

memchr_charFunction · 0.85
read_ui32Function · 0.85
skip_oneFunction · 0.85
read_tokenFunction · 0.85
emptyMethod · 0.80
getMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 1

test_11Method · 0.64