multilate源代码解读1 Connection

Connection: represents a new connection to a server endpoint

Connection.h
Connection has two event_bases. One is used to store the dns events. Another is used to represent the read/write events.
在这里插入图片描述
A bufferevent with 2 event_bases;
在这里插入图片描述

Constructor Function

Connection.cc
在这里插入图片描述

initialize the callback functions for read or write events

在这里插入图片描述

Connection maintains a enum status called write_state.

write_state is initialized with write_state.
When write_state changes its state to ISSUING. It invokes the function called issue_something(now) to genuinely send the current request.
在这里插入图片描述

Connection.cc

Issue either a get or set request to the server according to our probability distribution. For example, if we need to send a set request, we first generate the key str of this set request, and then the value str. Afterwards, we invoke the
issue_set function.
在这里插入图片描述
Issue a set request to the server.

在这里插入图片描述
Indeed, it delegates the protocol to send the request in fact at line 187. At line 184, it first push the operation into the stack.

std::queue<Operation> op_queue;

At line 186, it changes the read_state to "waiting for set ", meaning that the connection waits for the response of the set operation. In the meantime, we need to increment the amount of bytes that have been sent at line 188.

Protocol.cc
Finally, the set_reqquest function in Protocol.cc appends the key and value according to the memcached format to the end of the output buffer of the bufferevent. The data would be written to the descriptor automatically as it becomes available for writing.
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值