From 9a0669367302bff25f321cec6c37d789207dee4c Mon Sep 17 00:00:00 2001 From: Edward Emelianov Date: Thu, 24 Mar 2022 12:16:41 +0300 Subject: [PATCH] remove bug with sockets: write->send(..., MSG_NOSIGNAL) --- Socket_CAN/cansock.c | 2 +- Socket_snippet/socket.c | 2 +- netdaemon/socket.c | 2 +- serialsock/sersock.c | 4 ++-- sockmsgs.c | 6 +++--- stellarium_emul/main.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Socket_CAN/cansock.c b/Socket_CAN/cansock.c index 84fc7c4..2d2a11f 100644 --- a/Socket_CAN/cansock.c +++ b/Socket_CAN/cansock.c @@ -68,7 +68,7 @@ frame.can_dlc = 6; frame.can_id = 0xaa; const uint8_t d[] = {1, 2, 3, 4, 5, 6, 0, 0}; memcpy(&frame.data, d, 8); -int n = write(sock, &frame, sizeof(struct can_frame)); +int n = send(sock, &frame, sizeof(struct can_frame), MSG_NOSIGNAL); if(sizeof(struct can_frame) != n){ printf("n=%d\n", n); WARN("write()"); diff --git a/Socket_snippet/socket.c b/Socket_snippet/socket.c index 508543f..25e2e9f 100644 --- a/Socket_snippet/socket.c +++ b/Socket_snippet/socket.c @@ -123,7 +123,7 @@ void sendmessage(int fd, const char *msg, int l){ char *tmpbuf = MALLOC(char, l+1); memcpy(tmpbuf, msg, l); if(msg[l-1] != '\n') tmpbuf[l++] = '\n'; - if(l != write(fd, tmpbuf, l)){ + if(l != send(fd, tmpbuf, l, MSG_NOSIGNAL)){ LOGWARN("write()"); WARN("write()"); }else{ diff --git a/netdaemon/socket.c b/netdaemon/socket.c index c249aff..e35aa28 100644 --- a/netdaemon/socket.c +++ b/netdaemon/socket.c @@ -97,7 +97,7 @@ static int send_data(int sock, int webquery, char *textbuf){ WARN("sprintf()"); return 0; } - if(L != write(sock, tbuf, L)){ + if(L != send(sock, tbuf, L, MSG_NOSIGNAL)){ WARN("write"); return 0; } diff --git a/serialsock/sersock.c b/serialsock/sersock.c index 11cdb17..22de8cd 100644 --- a/serialsock/sersock.c +++ b/serialsock/sersock.c @@ -39,7 +39,7 @@ static int handle_socket(int sock, TTY_descr *d){ buff[rd] = 0; DBG("GOT: %s", buff); ssize_t blen = strlen(buff); - if(blen != write(d->comfd, buff, blen)){ + if(blen != send(d->comfd, buff, blen, MSG_NOSIGNAL)){ LOGWARN("write()"); WARN("write()"); } @@ -193,7 +193,7 @@ static void server_(int sock, TTY_descr *d){ } if(serdata){ for(int i = 1; i < nfd; ++i) - if(l != write(poll_set[i].fd, serdata, l)){ + if(l != send(poll_set[i].fd, serdata, l, MSG_NOSIGNAL)){ LOGWARN("write()"); WARN("write()"); } diff --git a/sockmsgs.c b/sockmsgs.c index 8a4a45d..4ed9829 100644 --- a/sockmsgs.c +++ b/sockmsgs.c @@ -119,17 +119,17 @@ void *handle_socket(void *asock){ "Content-type: text/html\r\nContent-Length: %d\r\n\r\n" "sum=%d\n", l, newx); }else L = l; - if(L != (size_t)write(sock, obuff, L)) WARN("write"); + if(L != (size_t)send(sock, obuff, L, MSG_NOSIGNAL)) WARN("write"); DBG("\nWRITE TO client: %s\n", obuff); }else{ // simply copy back all data size_t blen = strlen(buff); if(webquery){ L = snprintf(obuff, BUFLEN, "HTTP/2.0 200 OK\r\nContent-type: text/html\r\n" "Content-Length: %zd\r\n\r\n", blen); - if(L != write(sock, obuff, L)) WARN("write()"); + if(L != send(sock, obuff, L, MSG_NOSIGNAL)) WARN("write()"); } ++blen; - if(blen != write(sock, buff, blen)) WARN("write()"); + if(blen != send(sock, buff, blen, MSG_NOSIGNAL)) WARN("write()"); } if(webquery) break; // close connection if this is a web query } diff --git a/stellarium_emul/main.c b/stellarium_emul/main.c index ac73f61..206783a 100644 --- a/stellarium_emul/main.c +++ b/stellarium_emul/main.c @@ -95,7 +95,7 @@ char* stringscan(char *str, char *needle){ * @return 0 if failed */ int send_data(uint8_t *data, size_t dlen, int sockfd){ - size_t sent = write(sockfd, data, dlen); + size_t sent = send(sockfd, data, dlen, MSG_NOSIGNAL); if(sent != dlen){ WARN("write()"); return 0;