Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于客户端源码hiredis读取服务端响应问题 #30

Open
wangfly80 opened this issue Nov 17, 2018 · 0 comments
Open

关于客户端源码hiredis读取服务端响应问题 #30

wangfly80 opened this issue Nov 17, 2018 · 0 comments

Comments

@wangfly80
Copy link

读取服务端响应没有对tcp数据流进行粘包和拆包,这个应该有问题吧

调用read返回的nread长度不一定等于一条完整消息的长度吧,有可能会小于。
int redisBufferRead(redisContext c) {
char buf[1024
16];
int nread;

/* Return early when the context has seen an error. */
if (c->err)
    return REDIS_ERR;

nread = read(c->fd,buf,sizeof(buf));
if (nread == -1) {
    if (errno == EAGAIN && !(c->flags & REDIS_BLOCK)) {
        /* Try again later */
    } else {
        __redisSetError(c,REDIS_ERR_IO,NULL);
        return REDIS_ERR;
    }
} else if (nread == 0) {
    __redisSetError(c,REDIS_ERR_EOF,"Server closed the connection");
    return REDIS_ERR;
} else {
    if (redisReaderFeed(c->reader,buf,nread) != REDIS_OK) {
        __redisSetError(c,c->reader->err,c->reader->errstr);
        return REDIS_ERR;
    }
}
return REDIS_OK;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant