MCPcopy Create free account
hub / github.com/apache/brpc / select_server

Function select_server

test/brpc_load_balancer_unittest.cpp:433–458  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

431};
432
433void* select_server(void* arg) {
434 SelectArg *sa = (SelectArg*)arg;
435 brpc::LoadBalancer* c = sa->lb;
436 brpc::SocketUniquePtr ptr;
437 CountMap *selected_count = new CountMap;
438 brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, NULL };
439 brpc::LoadBalancer::SelectOut out(&ptr);
440 uint32_t rand_seed = rand();
441 if (sa->hash) {
442 uint32_t rd = ++rand_seed;
443 in.has_request_code = true;
444 in.request_code = sa->hash((const char *)&rd, sizeof(uint32_t));
445 }
446 int ret = 0;
447 while (!global_stop && (ret = c->SelectServer(in, &out)) == 0) {
448 if (sa->hash) {
449 uint32_t rd = ++rand_seed;
450 in.has_request_code = true;
451 in.request_code = sa->hash((const char *)&rd, sizeof(uint32_t));
452 }
453 ++(*selected_count)[ptr->id()];
454 }
455 LOG_IF(INFO, ret != 0) << "select_server[" << pthread_self()
456 << "] quits before of " << berror(ret);
457 return selected_count;
458}
459
460brpc::SocketId recycled_sockets[1024];
461butil::atomic<size_t> nrecycle(0);

Callers

nothing calls this directly

Calls 3

berrorFunction · 0.85
SelectServerMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected