忽略SIGPIPE信号

This commit is contained in:
xiongziliang 2022-02-05 20:39:24 +08:00
parent 0402646f7c
commit 1dd3d6f1ac

View File

@ -8,11 +8,13 @@
* may be found in the AUTHORS file in the root of the source tree. * may be found in the AUTHORS file in the root of the source tree.
*/ */
#include <csignal>
#include "HttpBody.h" #include "HttpBody.h"
#include "Util/util.h" #include "Util/util.h"
#include "Util/File.h" #include "Util/File.h"
#include "Util/uv_errno.h" #include "Util/uv_errno.h"
#include "Util/logger.h" #include "Util/logger.h"
#include "Util/onceToken.h"
#include "HttpClient.h" #include "HttpClient.h"
#ifndef _WIN32 #ifndef _WIN32
#include <sys/mman.h> #include <sys/mman.h>
@ -70,6 +72,9 @@ HttpFileBody::HttpFileBody(const std::shared_ptr<FILE> &fp, size_t offset, size_
#endif #endif
int HttpFileBody::sendFile(int fd) { int HttpFileBody::sendFile(int fd) {
static onceToken s_token([]() {
signal(SIGPIPE, SIG_IGN);
});
#if defined(__linux__) || defined(__linux) #if defined(__linux__) || defined(__linux)
off_t off = _file_offset; off_t off = _file_offset;
return sendfile(fd, fileno(_fp.get()), &off, _max_size); return sendfile(fd, fileno(_fp.get()), &off, _max_size);