MCPcopy Create free account
hub / github.com/Tencent/phxsql / run

Method run

phxsqlproxy/accept_thread.cpp:55–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55void AcceptThread::run() {
56 co_init_curr_thread_env();
57 co_enable_hook_sys();
58
59 static std::default_random_engine random_engine(time (NULL));
60 static std::uniform_int_distribution<unsigned> random_range(0, worker_threads_.size() - 1);
61
62 for (;;) {
63 struct sockaddr_in addr; //maybe sockaddr_un;
64 memset(&addr, 0, sizeof(addr));
65 socklen_t len = sizeof(addr);
66
67 int fd = accept(listen_fd_, (struct sockaddr *) &addr, &len);
68 if (fd < 0) {
69 if (errno != EAGAIN) {
70 MonitorPluginEntry::GetDefault()->GetMonitorPlugin()->AcceptFail();
71 LogError("accept failed, ret fd %d, errno (%d:%s)", fd, errno, strerror(errno));
72 }
73 continue;
74 }
75
76 MonitorPluginEntry::GetDefault()->GetMonitorPlugin()->AcceptSuccess();
77 SetNonBlock(fd);
78
79 int rand_idx = random_range(random_engine);
80 if (worker_threads_[rand_idx]->AssignFD(fd) > 0) {
81 MonitorPluginEntry::GetDefault()->GetMonitorPlugin()->ResumeRoutine();
82 } else {
83 MonitorPluginEntry::GetDefault()->GetMonitorPlugin()->OutOfConn();
84 LogError("%s:%d receive connection but no useful io routine", __func__, __LINE__);
85 close(fd);
86 }
87 }
88 co_eventloop(co_get_epoll_ct(), 0, 0);
89}
90
91}

Callers

nothing calls this directly

Calls 8

LogErrorFunction · 0.85
SetNonBlockFunction · 0.85
AcceptFailMethod · 0.80
GetMonitorPluginMethod · 0.80
AcceptSuccessMethod · 0.80
ResumeRoutineMethod · 0.80
OutOfConnMethod · 0.80
AssignFDMethod · 0.45

Tested by

no test coverage detected