MCPcopy Create free account
hub / github.com/Tencent/phxqueue / CoRead

Function CoRead

phxqueue/comm/utils/co_util.cpp:63–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61}
62
63bool CoRead(const int fd, char *buf, const int buf_len) {
64 int ret = 0;
65 int read_len = 0;
66 int nraise = 0;
67 struct pollfd pf = {0};
68 pf.fd = fd;
69 pf.events = (POLLIN | POLLERR | POLLHUP);
70 while (1) {
71 //if (0 == (nraise = co_poll(co_get_epoll_ct(), &pf, 1, 10000))) continue; // for co_poll not support timeout = -1 yet
72 if (0 == (nraise = poll(&pf, 1, 10000))) continue; // for co_poll not support timeout = -1 yet
73 if (nraise < 0) {
74 NLErr("co_poll ret %d", nraise);
75 return false;
76 }
77 ret = read(fd, buf + read_len, buf_len - read_len);
78 if (0 == ret) return false;
79 if (0 > ret) {
80 if (errno == EINTR || errno == EAGAIN) continue;
81 NLErr("read ret %d err %s", ret, strerror(errno));
82 return false;
83 }
84 read_len += ret;
85 if (read_len == buf_len) return true;
86 }
87 return false;
88}
89
90
91} // namespace utils

Callers 2

TaskDispatchMethod · 0.85
WaitMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected