| 10 | #ifdef _unix_ |
| 11 | template <typename Func> |
| 12 | static bool ProcessBuffer(Func&& func, void* bufin, size_t size) { |
| 13 | char* buf = (char*)bufin; |
| 14 | do { |
| 15 | const ssize_t bytesDone = func(buf, size); |
| 16 | if (bytesDone == 0) { |
| 17 | return false; |
| 18 | } |
| 19 | |
| 20 | if (bytesDone < 0) { |
| 21 | if (errno == EAGAIN || errno == EINTR) { |
| 22 | continue; |
| 23 | } else { |
| 24 | return false; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | buf += bytesDone; |
| 29 | size -= bytesDone; |
| 30 | } while (size != 0); |
| 31 | |
| 32 | return true; |
| 33 | } |
| 34 | |
| 35 | const int size = 1024 * 4; |
| 36 | const int pagesSize = sizeof(int) * size; |