当前位置:网站首页>[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 .边栏推荐
- d具体化函数参数
- [proteus simulation] 51 single chip microcomputer +lcd1602+ external memory calculator
- 【LeetCode】剑指 Offer II 016. 不含重复字符的最长子字符串
- Allan方差定义与计算方法简介
- Inftnews | the future of NFT in Web3 economy
- Industrial practice example of industrial defect detection based on openvino deployment
- 【LeetCode】接雨水
- Luogu p2657 [scoi2009]windy number problem solving digit DP
- 投资新手买收益率多少的理财产品合适?
- 网络中的拥塞控制与数据传输
猜你喜欢

地图瓦片数据的多种利用形式以及瓦片数据的浏览显示

What are the good techniques for domestic spot silver: simple usage of common indicators

985毕业,35岁创业失败,36岁回炉40岁被裁,中年夫妻无业咋办?

You're not still using xshell, are you? This open source terminal tool is yyds!

Teaching Broad Reasoning Skills via Decomposition-Guided Contexts

From the perspective of advanced automated testing, one article with 7 stages and 5000 words will give you a comprehensive understanding of automated testing
![[no title] 416 Split equal sum subset](/img/23/b45eab1be07dea23bcf6aed75e6b2e.png)
[no title] 416 Split equal sum subset

Leetcode 700: search in binary search tree

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

iNFTnews | NFT在Web3经济里的未来
随机推荐
自定义操作日志记录注解
You're not still using xshell, are you? This open source terminal tool is yyds!
What are the reasons for frequent channel drops in easycvr cascaded video convergence platform?
d具体化函数参数
[email protected] 项目实训
The transfer of production lines to Vietnam may not be a good choice. Samsung mobile phones have been affected and plan to return to South Korea
D mapping instructions in memory and executing
地图瓦片数据的多种利用形式以及瓦片数据的浏览显示
【LeetCode】461. Hamming distance
Keep alive in TCP connection
网络中的拥塞控制与数据传输
How can I right-click win11 to open all options directly?
MySQL script for Linux Installation
Which of DV and ov SSL certificates is suitable for purchase on the company's website
The IPO meeting of xinghuan science and Technology Innovation Board: the gross profit margin remains at a high level, with Tencent and other major shareholders
What is the difference between encryptors and database encryption products?
SQL语句编写
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
51单片机学习记录(六)IIC,ADC部分