Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit d27d5ba

Browse files
committed
fix nonblock_read errno setting
nonblock_read() relies errno being 0 upon entering, and also does not want to return -EINTR. Signed-off-by: Peng Tao <bergwolf@gmail.com>
1 parent ea8275b commit d27d5ba

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/init.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,8 +1019,10 @@ static ssize_t hyper_channel_read(struct hyper_event *he, int efd, int len, int
10191019
ssize_t size;
10201020

10211021
size = nonblock_read(he->fd, buf->data + buf->get, len);
1022-
if (size < 0)
1022+
if (size < 0) {
1023+
fprintf(stderr, "%s failed with %d\n", __func__, (int)size);
10231024
goto out;
1025+
}
10241026

10251027
// check if peer is dissapeared
10261028
if ((size == 0) && (events & EPOLLHUP)) {

src/util.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,12 @@ ssize_t nonblock_read(int fd, void *buf, size_t count)
699699
{
700700
ssize_t len = 0, ret = 0;
701701

702+
errno = 0;
702703
while (len < count) {
703704
ret = read(fd, buf + len, count - len);
704705
if (ret <= 0) {
705706
if (errno == EINTR) {
707+
errno = 0;
706708
continue;
707709
}
708710
if (errno == EAGAIN) {

0 commit comments

Comments
 (0)