| 31 | |
| 32 | |
| 33 | bool 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 | |
| 63 | bool CoRead(const int fd, char *buf, const int buf_len) { |
| 64 | int ret = 0; |
no outgoing calls
no test coverage detected