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

Function CoWrite

phxqueue/comm/utils/co_util.cpp:33–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31
32
33bool CoWrite(const int fd, const char *buf, const int buf_len) {
34 int ret = 0;
35 int write_len = 0;
36 int nraise = 0;
37 struct pollfd pf{0};
38 pf.fd = fd;
39 pf.events = (POLLOUT | POLLERR | POLLHUP);
40 while (1) {
41 errno = 0;
42 ret = write(fd, buf + write_len, buf_len - write_len);
43 if (0 == ret) return false;
44 if (0 > ret) {
45 if (errno == EINTR || errno == EAGAIN) {
46 //while (0 == (nraise = co_poll(co_get_epoll_ct(), &pf, 1, 10000))); // for co_poll not support timeout = -1 yet
47 while (0 == (nraise = poll(&pf, 1, 10000))); // for co_poll not support timeout = -1 yet
48 if (nraise < 0) {
49 NLErr("co_poll ret %d", nraise);
50 return false;
51 }
52 continue;
53 }
54 NLErr("write ret %d err %s", ret, strerror(errno));
55 return false;
56 }
57 write_len += ret;
58 if (write_len == buf_len) return true;
59 }
60 return false;
61}
62
63bool CoRead(const int fd, char *buf, const int buf_len) {
64 int ret = 0;

Callers 2

TaskDispatchMethod · 0.85
NotifyMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected