Use send/sendmsg and don't ignore SIGPIPE
This commit is contained in:
@@ -134,7 +134,11 @@ bool Connection::writeBytes() {
|
||||
|
||||
ssize_t w;
|
||||
for (;;) {
|
||||
w = writev(fd_, iov, iov_count);
|
||||
struct msghdr msg = {};
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = iov_count;
|
||||
|
||||
w = sendmsg(fd_, &msg, MSG_NOSIGNAL);
|
||||
if (w == -1) {
|
||||
if (errno == EINTR) {
|
||||
continue; // Standard practice: retry on signal interruption
|
||||
@@ -148,7 +152,7 @@ bool Connection::writeBytes() {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
perror("writev");
|
||||
perror("sendmsg");
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -264,7 +264,6 @@ int main(int argc, char *argv[]) {
|
||||
g_server = server.get();
|
||||
|
||||
// Setup signal handling
|
||||
std::signal(SIGPIPE, SIG_IGN);
|
||||
std::signal(SIGTERM, signal_handler);
|
||||
std::signal(SIGINT, signal_handler);
|
||||
|
||||
|
||||
@@ -300,7 +300,7 @@ struct Connection {
|
||||
bool writeBytes() {
|
||||
for (;;) {
|
||||
assert(!request.empty());
|
||||
int w = write(fd, request.data(), request.size());
|
||||
int w = send(fd, request.data(), request.size(), MSG_NOSIGNAL);
|
||||
if (w == -1) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
@@ -610,7 +610,6 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user