当前位置:网站首页>[email protected] Project training
[email protected] Project training
2022-06-10 01:41:00 【Ryan-J】
List of articles
One 、 brief introduction
The last article combines echo The server side introduces server How was it created , Next, let's look at how to send data after establishing a connection .
The last article also used this picture , In the middle of the channel That's what we're going to talk about today . The data transmission will be explained in more detail later .
First ,channel What is it? ?
channel, Channels can also be called pipes . It can read and write at the same time , And streams can only read or write , passageway (Channel) It's two-way , Can read operation , You can also write operations .
Channels can read and write data asynchronously .
Channels can read data from the buffer , You can also write data to the buffer .
We see the following client.cpp in , That's what I used channel Realize data interaction . ad locum , The channel represents the communication line from the client to the server .
So this article makes a simple analysis of the channel .
Two 、 The code analysis
First of all channel Base class of , You can see all the channel Are based on protobuf Of RpcChannel and Describable, There are two functions that need to be implemented ,Weight() On behalf of the current Channel The weight of ,CheckHealth() health examination . It's a virtual function because channel There are many forms , such as SelectiveChannel、PartitionChannel etc. .
Then realize ChannelOptions class , Yes channel Summarize the options of .
such as connect_timeout_ms Yes, the connection timed out , Note that the timeout is rpc The connection inside the framework timed out .
timeout_ms The control is once rpc Requested timeout .
The notes are very detailed , I won't list them all .
stay channel.cpp The default parameters are given in .
And then look channel The initialization . Also overloaded multiple versions , It's all called to InitSingle().
The key content is here .GlobalInitializeOrDie() Perform operations such as protocol and load balancing method registration , The global only needs to be executed once . Then this server_addr_and_port Insert into socketmap And put the corresponding socket_id Save to _server_id For subsequent use ,socketmap Save sth IP+port To socket_id Correspondence of .
Then there is the most important and core CallMethod Method . All operations involving pipes will be completed by calling this function here . Every request is bound with a controller, First, initialize according to the passed in attributes cntl, Then set the protocol and retry mechanism , Subsequent operations are basically carried out around it .
This was followed by a response to this request controller Make relevant assignment , It is mainly divided into two parts , First, if each timeout parameter is not set , Just use _options Parameters of , In particular, the connection timed out , As the note says , Because the connection is all rpc Call frequently used , Alone for cntl Setting doesn't make sense , So direct use _options Inside . The second is related to the actual content of this request response、 Packing function 、 Called methods, etc .
Next set up timer And the current request completed _deadline_us, Overtime and backup_request_ms All need to wait timer. There are three situations , One is backup_request_ms Set valid conditions , Second, there is no effective backup_request_ms But there are effective timeout_ms Local conditions , Third, the situation of neither .
The first case will use HandleBackupRequest Set up a for backup_request Of bthread_timer, That is, how long will it take to launch backup request , Will also make use of timeout_out formation deadline_us.( This Handle And the next Handle All belong to the category of system call )
The second is only timeout , Use HandleTimeout As a setting bthread_timer and deadline_us, Processing timeout required after arrival .
When everything is set . You can submit the transmission . Use of is cntl->IssueRPC(), This function is analyzing controller I'll explain it in detail when . The core method is actually through the processing of various settings , Finally, after completing the sending of a request .
Finally, the two methods that implement the base class , It's just a normal channel class .
Weight stay controller Yes lb You'll get his value when you , It is 0. That is, at present Channel All connected server And .
Ordinary Channel Of CheckHealth() By judging the corresponding _lb Whether it can be connected to a valid server Realized .
summary
That's all for today , This paper mainly combines how to send data to channel Detailed source code analysis , Later blogs will continue to analyze other codes .边栏推荐
- 【ACL 2022】Hallucinated but Factual! Inspecting the Factuality of Hallucinations
- Custom action logging annotation
- JS鼠标经过改变字体颜色,离开恢复
- 软件工程期末复习
- Picture batch download + picture mosaic: multiple pictures constitute the Dragon Boat Festival Ankang!
- Rhcsa day 7
- 【LeetCode】剑指 Offer II 016. 不含重复字符的最长子字符串
- Teaching Broad Reasoning Skills via Decomposition-Guided Contexts
- Regular expression does not contain a string
- iNFTnews | 元宇宙进行时:那些跑步入场的互联网大厂在如何谋篇布局?
猜你喜欢

基于OpenVINO部署的工业缺陷检测产业实践范例实战

有机金属多孔材料MOF(Fe)包载喜树碱,藤黄酸、吲哚菁绿|RMOF-3包载紫杉醇定制

【ACL 2022】Hallucinated but Factual! Inspecting the Factuality of Hallucinations
[email protected] 项目实训"/>[email protected] 项目实训

【程序人生】“阶段总结”-不知所措

比你想象中更强大的 reduce 以及对敲码的思考

【图像分类案例】(10) Vision Transformer 动物图像三分类,附Pytorch完整代码

Hoo虎符研究院 | 币圈后浪-类宝可梦的GameFi:EvoVerses

LeetCode 530: 二叉搜索树的最小绝对差
window. Open (URL) opens the download link for many times and is blocked by the browser. JS realizes circular access to multiple download links
随机推荐
【LeetCode】105. 从前序与中序遍历序列构造二叉树
Internet of things engineering design and Implementation
有机金属多孔材料MOF(Fe)包载喜树碱,藤黄酸、吲哚菁绿|RMOF-3包载紫杉醇定制
Hoo Hufu Research Institute | houlang in the coin circle - gamefi like baokemeng: evoverses
Win11怎么直接退回进入桌面?
Niuke.com Huawei question bank (1~10)
Node red series (26): use the dashboard node to develop common table search layouts
国内现货白银有哪些好技术:常见指标的简单用法
【LeetCode】接雨水
Experimental three character type and its operation (New)
Trichview and scalericview set default Chinese
[proteus simulation] 51 single chip microcomputer +lcd1602+ external memory calculator
What are the good techniques for domestic spot silver: simple usage of common indicators
[learn FPGA programming from scratch -16]: quick start chapter - operation steps 2-4- basic syntax of Verilog HDL language description language (both software programmers and hardware engineers can un
[no title] 416 Split equal sum subset
Curriculum Learning and Graph Neural Networks (or Graph Structure Learning)
Eight consecutive championships! Inspur cloud has been the first in China's Government cloud market for 8 consecutive years
【ACL 2022】Hallucinated but Factual! Inspecting the Factuality of Hallucinations
iNFTnews | 元宇宙进行时:那些跑步入场的互联网大厂在如何谋篇布局?
免费批量导入生成sitemap地图的软件