| 71 | |
| 72 | template<class T> |
| 73 | int StartWorker(PHXSqlProxyConfig * config, WorkerConfig_t * worker_config) { |
| 74 | const char * listen_ip = worker_config->listen_ip_; |
| 75 | int fork_proc_count = worker_config->fork_proc_count_; |
| 76 | int worker_thread_count = worker_config->worker_thread_count_; |
| 77 | |
| 78 | int listen_fd[2]; |
| 79 | int port[2] = {worker_config->port_, worker_config->proxy_port_}; |
| 80 | for (int i = 0; i < 2; ++i) { |
| 81 | listen_fd[i] = CreateTcpSocket(port[i], listen_ip, true); |
| 82 | if (listen_fd[i] <= 0) { |
| 83 | LogError("creat tcp socket failed ret %d, errno (%d:%s)", listen_fd[i], errno, strerror(errno)); |
| 84 | printf("creat tcp socket failed ret %d, errno (%d:%s)", listen_fd[i], errno, strerror(errno)); |
| 85 | return -__LINE__; |
| 86 | } |
| 87 | |
| 88 | int ret = listen(listen_fd[i], 1024); |
| 89 | if (ret < 0) { |
| 90 | LogError("listen in [%s:%d] fd %d ret %d errno (%d:%s)", listen_ip, port[i], listen_fd[i], ret, |
| 91 | errno, strerror(errno)); |
| 92 | printf("creat tcp socket failed ret %d, errno (%d:%s)", listen_fd[i], errno, strerror(errno)); |
| 93 | return -__LINE__; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | //SetNonBlock( listen_fd ); |
| 98 | for (int i = 0; i < fork_proc_count; ++i) { |
| 99 | pid_t pid = fork(); |
| 100 | if (pid > 0) { |
| 101 | continue; |
| 102 | } else if (pid < 0) { |
| 103 | break; |
| 104 | } |
| 105 | //co_init_curr_thread_env(); |
| 106 | co_enable_hook_sys(); |
| 107 | |
| 108 | if (config->Sleep()) { |
| 109 | ::sleep(config->Sleep()); |
| 110 | } |
| 111 | |
| 112 | MonitorPluginEntry * monitor_plugin = MonitorPluginEntry::GetDefault(); |
| 113 | monitor_plugin->SetConfig(config, worker_config); |
| 114 | |
| 115 | RequestFilterPluginEntry * requestfilter_plugin = RequestFilterPluginEntry::GetDefault(); |
| 116 | requestfilter_plugin->SetConfig(config, worker_config); |
| 117 | |
| 118 | //if is master, send heart beat to phxbinlogsvr |
| 119 | if (worker_config->is_master_port_) { |
| 120 | HeartBeatThread * heartbeat_thread = new HeartBeatThread(config, worker_config); |
| 121 | heartbeat_thread->start(); |
| 122 | } |
| 123 | |
| 124 | GroupStatusCache * group_status_cache = new GroupStatusCache(config, worker_config); |
| 125 | group_status_cache->start(); |
| 126 | |
| 127 | vector<WorkerThread *> worker_threads; |
| 128 | for (int j = 0; j < worker_thread_count; ++j) { |
| 129 | WorkerThread * worker_thread = new WorkerThread(config, worker_config); |
| 130 | worker_thread->InitRoutines<T>(group_status_cache); |
nothing calls this directly
no test coverage detected