当前位置:网站首页>Gossip about redis source code 121
Gossip about redis source code 121
2022-06-22 20:05:00 【Tao song remains the same】
rio Of connwrite and connread How to write ? Toss me for a long time , After referring to the open source code , Get it done :
static size_t rioConnWrite(rio *r, const void *buf, size_t len) {
UNUSED(r);
UNUSED(buf);
UNUSED(len);
return 0; /* Error, this target does not yet support writing. */
}
/* Returns 1 or 0 for success/failure. */
static size_t rioConnRead(rio *r, void *buf, size_t len) {
size_t avail = sdslen(r->io.conn.buf)-r->io.conn.pos;
/* If the buffer is too small for the entire request: realloc. */
if (sdslen(r->io.conn.buf) + sdsavail(r->io.conn.buf) < len)
r->io.conn.buf = sdsMakeRoomFor(r->io.conn.buf, len - sdslen(r->io.conn.buf));
/* If the remaining unused buffer is not large enough: memmove so that we
* can read the rest. */
if (len > avail && sdsavail(r->io.conn.buf) < len - avail) {
sdsrange(r->io.conn.buf, r->io.conn.pos, -1);
r->io.conn.pos = 0;
}
/* If we don't already have all the data in the sds, read more */
while (len > sdslen(r->io.conn.buf) - r->io.conn.pos) {
size_t buffered = sdslen(r->io.conn.buf) - r->io.conn.pos;
size_t needs = len - buffered;
/* Read either what's missing, or PROTO_IOBUF_LEN, the bigger of
* the two. */
size_t toread = needs < PROTO_IOBUF_LEN ? PROTO_IOBUF_LEN: needs;
if (toread > sdsavail(r->io.conn.buf)) toread = sdsavail(r->io.conn.buf);
if (r->io.conn.read_limit != 0 &&
r->io.conn.read_so_far + buffered + toread > r->io.conn.read_limit)
{
/* Make sure the caller didn't request to read past the limit.
* If they didn't we'll buffer till the limit, if they did, we'll
* return an error. */
if (r->io.conn.read_limit >= r->io.conn.read_so_far + len)
toread = r->io.conn.read_limit - r->io.conn.read_so_far - buffered;
else {
errno = EOVERFLOW;
return 0;
}
}
int retval = connRead(r->io.conn.conn,
(char*)r->io.conn.buf + sdslen(r->io.conn.buf),
toread);
if (retval <= 0) {
if (errno == EWOULDBLOCK) errno = ETIMEDOUT;
return 0;
}
sdsIncrLen(r->io.conn.buf, retval);
}
memcpy(buf, (char*)r->io.conn.buf + r->io.conn.pos, len);
r->io.conn.read_so_far += len;
r->io.conn.pos += len;
return len;
}
边栏推荐
猜你喜欢

如何低成本快速搭建企业知识库?

树和森林的遍历

What can the accelerated implementation of digital economy bring to SMEs?

Nlp-d57-nlp competition D26 & skimming questions D13 & reading papers & finding bugs for more than an hour

【深入理解TcaplusDB技术】入门TcaplusDB 问题汇总
![[deeply understand tcapulusdb knowledge base] common problems in deploying tcapulusdb local](/img/2b/3ab5e247ac103728b4d3579c3c5468.png)
[deeply understand tcapulusdb knowledge base] common problems in deploying tcapulusdb local

Redis中的Multi事务

图的定义及术语

Some problem records of openpnp using process

matplotlib设置坐标轴刻度间隔
随机推荐
B树代码(C语言)
芯和半导体“射频EDA/滤波器设计平台”闪耀IMS2022
【深入理解TcaplusDB技术】入门TcaplusDB 问题汇总
希尔排序
socket的connect函数用法
Goldfish rhca memoirs: do447 managing user and team access -- creating and managing ansible tower users
MySQL的函数
[in depth understanding of tcapulusdb technology] introduction tcapulusdb problem summary
不断重修的计划与变化
[deeply understand tcapulusdb technology] how to start tcapulusdb process
A text to show you the memory leak
误用append案例一则
1.3----- simple setting of 3D slicing software
如何在 FlowUs和Notion 等笔记软件中进行任务管理?
Redis 大 key 问题
【深入理解TcaplusDB技术】运维平台中实现TcaplusDB事务管理
Fibonacci search (golden section)
DynamicDatabaseSource,在应用端支持数据库的主从
记可视化项目代码设计的心路历程以及理解
Implementation of balanced binary tree with C language