void ngram_search::xor_block(string_buffer& sb, unsigned int val) { for (string_buffer::iterator i = sb.begin(); i != sb.end(); ++i) { (*i) ^= val; } }
int hstcpcli::response_recv(size_t& num_flds_r) { if (error_code < 0) { return error_code; } clear_error(); if (num_req_bufd > 0 || num_req_sent == 0 || num_req_rcvd > 0 || response_end_offset != 0) { close(); return set_error(-1, "response_recv: protocol out of sync"); } cur_row_offset = 0; num_flds_r = num_flds = 0; if (fd.get() < 0) { return set_error(-1, "read: closed"); } size_t offset = 0; while (true) { const char *const lbegin = readbuf.begin() + offset; const char *const lend = readbuf.end(); const char *const nl = memchr_char(lbegin, '\n', lend - lbegin); if (nl != 0) { offset = (nl + 1) - readbuf.begin(); break; } if (read_more() <= 0) { close(); return set_error(-1, "read: eof"); } } response_end_offset = offset; --num_req_sent; ++num_req_rcvd; char *start = readbuf.begin(); char *const finish = start + response_end_offset - 1; const size_t resp_code = read_ui32(start, finish); skip_one(start, finish); num_flds_r = num_flds = read_ui32(start, finish); if (resp_code != 0) { skip_one(start, finish); char *const err_begin = start; read_token(start, finish); char *const err_end = start; std::string e = std::string(err_begin, err_end - err_begin); if (e.empty()) { e = "unknown_error"; } return set_error(resp_code, e); } cur_row_offset = start - readbuf.begin(); DBG(fprintf(stderr, "[%s] ro=%zu eol=%zu\n", std::string(readbuf.begin(), readbuf.begin() + response_end_offset) .c_str(), cur_row_offset, response_end_offset)); DBG(fprintf(stderr, "RES 0\n")); return 0; }
int hstcpcli::response_recv(size_t& num_flds_r) { if (error_code < 0) { return error_code; } clear_error(); if (num_req_bufd > 0 || num_req_sent == 0 || num_req_rcvd > 0 || response_end_offset != 0) { close(); return set_error(-1, "response_recv: protocol out of sync"); } cur_row_offset = 0; num_flds_r = num_flds = 0; if (fd.get() < 0) { return set_error(-1, "read: closed"); } size_t offset = 0; while (true) { const char *const lbegin = readbuf.begin() + offset; const char *const lend = readbuf.end(); if (lbegin < lend) { const char *const nl = memchr_char(lbegin, '\n', lend - lbegin); if (nl != 0) { offset += (nl + 1) - lbegin; break; } offset += lend - lbegin; } if (read_more() <= 0) { close(); error_code = -1; return error_code; } } response_end_offset = offset; --num_req_sent; ++num_req_rcvd; char *start = readbuf.begin(); char *const finish = start + response_end_offset - 1; const size_t resp_code = read_ui32(start, finish); skip_one(start, finish); num_flds_r = num_flds = read_ui32(start, finish); if (resp_code != 0) { skip_one(start, finish); char *const err_begin = start; read_token(start, finish); char *const err_end = start; String e = String(err_begin, err_end - err_begin, &my_charset_bin); if (!e.length()) { e = String("unknown_error", &my_charset_bin); } return set_error(resp_code, e); } cur_row_offset = start - readbuf.begin(); DBG(fprintf(stderr, "[%s] ro=%zu eol=%zu\n", String(readbuf.begin(), readbuf.begin() + response_end_offset) .c_str(), cur_row_offset, response_end_offset)); DBG(fprintf(stderr, "RES 0\n")); if (flds.max_element < num_flds) { if (allocate_dynamic(&flds, num_flds)) return set_error(-1, "out of memory"); } flds.elements = num_flds; return 0; }