<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 3) Report Client設計與實現 ? report client主要是實現thread_queue的回調業務,udp server會定期的上傳上報數據到reporter,那么請求對于report client就是透傳給reporter serivce即可。 > lars_loadbalance_agent/src/reporter_client.cpp ```c #include "lars_reactor.h" #include "main_server.h" #include <string> #include <pthread.h> //typedef void io_callback(event_loop *loop, int fd, void *args); //只要thread_queue有數據,loop就會觸發此回調函數來處理業務 void new_report_request(event_loop *loop, int fd, void *args) { tcp_client *client = (tcp_client*)args; //1. 將請求數據從thread_queue中取出, std::queue<lars::ReportStatusRequest> msgs; //2. 將數據放在queue隊列中 report_queue->recv(msgs); //3. 遍歷隊列,通過client依次將每個msg發送給reporter service while (!msgs.empty()) { lars::ReportStatusRequest req = msgs.front(); msgs.pop(); std::string requestString; req.SerializeToString(&requestString); //client 發送數據 client->send_message(requestString.c_str(), requestString.size(), lars::ID_ReportStatusRequest); } } void *report_client_thread(void* args) { printf("report client thread start\n"); event_loop loop; //1 加載配置文件得到repoter ip + port std::string ip = config_file::instance()->GetString("reporter", "ip", ""); short port = config_file::instance()->GetNumber("reporter", "port", 0); //2 創建客戶端 tcp_client client(&loop, ip.c_str(), port, "reporter client"); //3 將 thread_queue消息回調事件,綁定到loop中 report_queue->set_loop(&loop); report_queue->set_callback(new_report_request, &client); //4 啟動事件監聽 loop.event_process(); return NULL; } void start_report_client() { //開辟一個線程 pthread_t tid; //啟動線程業務函數 int ret = pthread_create(&tid, NULL, report_client_thread, NULL); if (ret == -1) { perror("pthread_create"); exit(1); } //設置分離模式 pthread_detach(tid); } ``` ## 4) Dns Client設計與實現 ? dns client 和report client的業務十分相似,只是針對的協議不同了。dns client的thread_queue 回調業務主要是透傳`lars::GetRouteRequest`數據包。 > lars_loadbalance_agent/src/dns_client.cpp ```c #include "lars_reactor.h" #include "main_server.h" #include <pthread.h> //typedef void io_callback(event_loop *loop, int fd, void *args); //只要thread_queue有數據,loop就會觸發此回調函數來處理業務 void new_dns_request(event_loop *loop, int fd, void *args) { tcp_client *client = (tcp_client*)args; //1. 將請求數據從thread_queue中取出, std::queue<lars::GetRouteRequest> msgs; //2. 將數據放在queue隊列中 dns_queue->recv(msgs); //3. 遍歷隊列,通過client依次將每個msg發送給reporter service while (!msgs.empty()) { lars::GetRouteRequest req = msgs.front(); msgs.pop(); std::string requestString; req.SerializeToString(&requestString); //client 發送數據 client->send_message(requestString.c_str(), requestString.size(), lars::ID_GetRouteRequest); } } void *dns_client_thread(void* args) { printf("dns client thread start\n"); event_loop loop; //1 加載配置文件得到dns service ip + port std::string ip = config_file::instance()->GetString("dnsserver", "ip", ""); short port = config_file::instance()->GetNumber("dnsserver", "port", 0); //2 創建客戶端 tcp_client client(&loop, ip.c_str(), port, "dns client"); //3 將thread_queue消息回調事件,綁定到loop中 dns_queue->set_loop(&loop); dns_queue->set_callback(new_dns_request, &client); //4 啟動事件監聽 loop.event_process(); return NULL; } void start_dns_client() { //開辟一個線程 pthread_t tid; //啟動線程業務函數 int ret = pthread_create(&tid, NULL, dns_client_thread, NULL); if (ret == -1) { perror("pthread_create"); exit(1); } //設置分離模式 pthread_detach(tid); } ``` --- ### 關于作者: 作者:`Aceld(劉丹冰)` mail: [danbing.at@gmail.com](mailto:danbing.at@gmail.com) github: [https://github.com/aceld](https://github.com/aceld) 原創書籍: [http://www.hmoore.net/@aceld](http://www.hmoore.net/@aceld) ![](https://img.kancloud.cn/b0/d1/b0d11a21ba62e96aef1c11d5bfff2cf8_227x227.jpg) >**原創聲明:未經作者允許請勿轉載, 如果轉載請注明出處**
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看