Skip to content

Commit 163b0a5

Browse files
authored
handle pipe signal (#613)
1 parent 3896424 commit 163b0a5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

include/cinatra/ylt/coro_io/coro_io.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,11 @@ inline std::error_code connect(executor_t &executor,
518518
}
519519

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

522527
inline async_simple::coro::Lazy<std::pair<std::error_code, std::size_t>>
523528
async_sendfile(asio::ip::tcp::socket &socket, int fd, off_t offset,
@@ -534,8 +539,8 @@ async_sendfile(asio::ip::tcp::socket &socket, int fd, off_t offset,
534539
while (true) {
535540
// Try the system call.
536541
errno = 0;
537-
int n = ::sendfile(socket.native_handle(), fd, &offset,
538-
std::min(std::size_t{65536}, least_bytes));
542+
ssize_t n = ::sendfile(socket.native_handle(), fd, &offset,
543+
std::min(std::size_t{65536}, least_bytes));
539544
ec = asio::error_code(n < 0 ? errno : 0,
540545
asio::error::get_system_category());
541546
least_bytes -= ec ? 0 : n;

0 commit comments

Comments
 (0)