Skip to content

Commit

Permalink
[src] Improve Reading Func of IoBuffer for ignoring signals by using …
Browse files Browse the repository at this point in the history
…the modern API - recvmsg()
  • Loading branch information
Sigma711 committed Aug 28, 2023
1 parent 10f206b commit aa99824
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/io_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,14 @@ ssize_t IoBuffer::ReadFromFd(int fd, int* tmp_errno) {
discrete_buffers[1].iov_len = 64 * 1024;
// Use extra buffer to receive data if the writable space is not enough
const int iov_seq = writable_bytes < 64 * 1024 ? 2 : 1;
ssize_t n =
::readv(fd, static_cast<const struct iovec*>(discrete_buffers), iov_seq);
// To replace this (because of signals):
// ssize_t n = ::readv(fd, static_cast<const struct iovec*>(discrete_buffers),
// iov_seq);
struct msghdr message;
::memset(&message, 0, sizeof(message)); // clear the structure
message.msg_iov = discrete_buffers;
message.msg_iovlen = iov_seq;
ssize_t n = ::recvmsg(fd, &message, MSG_NOSIGNAL);
if (n < 0) {
*tmp_errno = errno;
LOG_ERROR("Discrete reading in Fd(%d) failed!!!", fd);
Expand Down

0 comments on commit aa99824

Please sign in to comment.