Skip to content

Commit

Permalink
Minor refactoring for rioConnRead and adding errno (redis#9280)
Browse files Browse the repository at this point in the history
minor refactoring for rioConnRead and adding errno
  • Loading branch information
Ewg-c committed Jul 30, 2021
1 parent 8bf433d commit a403816
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/replication.c
Expand Up @@ -1756,10 +1756,10 @@ void readSyncBulkPayload(connection *conn) {

if (rdbLoadRio(&rdb,RDBFLAGS_REPLICATION,&rsi) != C_OK) {
/* RDB loading failed. */
stopLoading(0);
serverLog(LL_WARNING,
"Failed trying to load the MASTER synchronization DB "
"from socket");
"Failed trying to load the MASTER synchronization DB "
"from socket: %s", strerror(errno));
stopLoading(0);
cancelReplicationHandshake(1);
rioFreeConn(&rdb, NULL);

Expand Down
18 changes: 9 additions & 9 deletions src/rio.c
Expand Up @@ -187,6 +187,14 @@ static size_t rioConnRead(rio *r, void *buf, size_t len) {
r->io.conn.pos = 0;
}

/* 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 != 0 && r->io.conn.read_limit < r->io.conn.read_so_far + len) {
errno = EOVERFLOW;
return 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;
Expand All @@ -198,15 +206,7 @@ static size_t rioConnRead(rio *r, void *buf, size_t len) {
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;
}
toread = r->io.conn.read_limit - r->io.conn.read_so_far - buffered;
}
int retval = connRead(r->io.conn.conn,
(char*)r->io.conn.buf + sdslen(r->io.conn.buf),
Expand Down

0 comments on commit a403816

Please sign in to comment.