MCPcopy Create free account
hub / github.com/acl-dev/acl / get_string

Method get_string

lib_acl_cpp/src/redis/redis_client.cpp:243–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

241}
242
243redis_result* redis_client::get_string(socket_stream& conn, dbuf_pool* dbuf)
244{
245 string& sbuf = conn.get_buf();
246 sbuf.clear();
247 if (!conn_.gets(sbuf)) {
248 logger_error("gets error, server: %s", conn.get_peer(true));
249 return NULL;
250 }
251 redis_result* rr = new(dbuf) redis_result(dbuf);
252 rr->set_type(REDIS_RESULT_STRING);
253 int len = atoi(sbuf.c_str());
254 if (len < 0) {
255 return rr;
256 }
257
258 char* buf;
259
260 if (!slice_res_) {
261 rr->set_size(1);
262 buf = (char*) dbuf->dbuf_alloc(len + 1);
263 if (len > 0 && conn_.read(buf, (size_t) len) == -1) {
264 logger_error("read error, server: %s",
265 conn.get_peer(true));
266 return NULL;
267 }
268 buf[len] = 0;
269 rr->put(buf, (size_t) len);
270
271 // �� \r\n
272 sbuf.clear();
273 if (! conn_.gets(sbuf)) {
274 logger_error("gets error, server: %s", conn.get_peer(true));
275 return NULL;
276 }
277 return rr;
278 }
279
280 // �����ܷ��صĴ��ڴ�ֳɲ����ӵ��ڴ����洢
281
282#define CHUNK_LENGTH 8192
283
284 size_t size = (size_t) len / CHUNK_LENGTH;
285 if ((size_t) len % CHUNK_LENGTH != 0)
286 size++;
287 rr->set_size(size);
288 int n;
289
290 while (len > 0) {
291 n = len > CHUNK_LENGTH - 1 ? CHUNK_LENGTH - 1 : len;
292 buf = (char*) dbuf->dbuf_alloc((size_t) (n + 1));
293 if (conn_.read(buf, (size_t) n) == -1) {
294 logger_error("read data error, server: %s",
295 conn.get_peer(true));
296 return NULL;
297 }
298 buf[n] = 0;
299 rr->put(buf, (size_t) n);
300 len -= n;

Callers

nothing calls this directly

Calls 9

getsMethod · 0.80
dbuf_allocMethod · 0.80
get_bufMethod · 0.45
clearMethod · 0.45
get_peerMethod · 0.45
set_typeMethod · 0.45
c_strMethod · 0.45
readMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected