| 18 | }; |
| 19 | |
| 20 | void XmonRequest::write(int fd) const { |
| 21 | ALWAYS_ASSERT(message.size() < 1<<16); |
| 22 | XmonRequestHeader header = { |
| 23 | .alertId = alertId, |
| 24 | .quietPeriod = quietPeriod, |
| 25 | .msgType = msgType, |
| 26 | .appType = appType, |
| 27 | .binnable = binnable, |
| 28 | .messageLen = (uint16_t)message.size(), |
| 29 | }; |
| 30 | static thread_local char buf[PIPE_BUF]; |
| 31 | ALWAYS_ASSERT(sizeof(header) + header.messageLen < PIPE_BUF); |
| 32 | memcpy(buf, &header, sizeof(header)); |
| 33 | memcpy(buf+sizeof(header), message.data(), header.messageLen); |
| 34 | { |
| 35 | // pipe writes of < PIPE_BUF are guaranteed to be atomic, see pipe(7) |
| 36 | int written = ::write(fd, buf, sizeof(header)+header.messageLen); |
| 37 | if (written != sizeof(header)+header.messageLen) { |
| 38 | throw SYSCALL_EXCEPTION("write"); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | bool XmonRequest::read(int fd) { |
| 44 | static thread_local char buf[PIPE_BUF]; |
no test coverage detected