| 42 | } |
| 43 | |
| 44 | int ConnectionDispatcher::run() { |
| 45 | co_enable_hook_sys(); |
| 46 | while (true) { |
| 47 | char buffer[512] = { 0 }; |
| 48 | int n = RoutineReadWithTimeout(socket_pair_fd_[1], buffer, sizeof(buffer), 1000); |
| 49 | if (n > 0) { |
| 50 | for (int i = 0; i < n; i += sizeof(int)) { |
| 51 | int fd = 0; |
| 52 | memcpy(&fd, buffer + i, sizeof(int)); |
| 53 | if (fd) { |
| 54 | SetNonBlock(fd); |
| 55 | IORoutine * io_routine = NULL; |
| 56 | int get_routine_ret = io_routine_mgr_->GetIORoutine(&io_routine); |
| 57 | if (get_routine_ret == 0 && io_routine != NULL) { |
| 58 | MonitorPluginEntry::GetDefault()->GetMonitorPlugin()->ResumeRoutine(); |
| 59 | io_routine->SetClientFD(fd); |
| 60 | io_routine->resume(); |
| 61 | } else { |
| 62 | MonitorPluginEntry::GetDefault()->GetMonitorPlugin()->OutOfConn(); |
| 63 | LogError("%s:%d receive connection but no useful io routine", __func__, __LINE__); |
| 64 | close(fd); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | int ConnectionDispatcher::AssignFD(int fd) { |
| 74 | return RoutineWriteWithTimeout(socket_pair_fd_[0], (const char *) (&fd), sizeof(int), 1000); |
nothing calls this directly
no test coverage detected