Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore SIGPIPE signal when use ::sendfile in linux #712

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions include/ylt/coro_io/coro_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ inline std::error_code connect(executor_t &executor,
}

#ifdef __linux__
// this help us ignore SIGPIPE when send data to a unexpected closed socket.
inline auto pipe_signal_handler = [] {
std::signal(SIGPIPE, SIG_IGN);
return 0;
}();

inline async_simple::coro::Lazy<std::pair<std::error_code, std::size_t>>
async_sendfile(asio::ip::tcp::socket &socket, int fd, off_t offset,
Expand All @@ -523,8 +528,8 @@ async_sendfile(asio::ip::tcp::socket &socket, int fd, off_t offset,
while (true) {
// Try the system call.
errno = 0;
int n = ::sendfile(socket.native_handle(), fd, &offset,
std::min(std::size_t{65536}, least_bytes));
ssize_t n = ::sendfile(socket.native_handle(), fd, &offset,
std::min(std::size_t{65536}, least_bytes));
ec = asio::error_code(n < 0 ? errno : 0,
asio::error::get_system_category());
least_bytes -= ec ? 0 : n;
Expand Down
Loading