remove bug with sockets: write->send(..., MSG_NOSIGNAL)

This commit is contained in:
Edward Emelianov 2022-03-24 12:16:41 +03:00
parent 76a1ec0e81
commit 9a06693673
6 changed files with 9 additions and 9 deletions

View File

@ -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()");

View File

@ -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{

View File

@ -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;
}

View File

@ -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()");
}

View File

@ -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
}

View File

@ -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;