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