From 6fdc283cc415e4f0c31c103d4ab8c6bdbd0a731f Mon Sep 17 00:00:00 2001 From: ngn Date: Fri, 9 Aug 2024 03:29:50 +0300 Subject: [PATCH] fix: add MSG_WAITALL flag for recv function --- locale/tr/LC_MESSAGES/libmp.po | 2 +- src/mptp/client.c | 1 + src/mptp/mptp.c | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/locale/tr/LC_MESSAGES/libmp.po b/locale/tr/LC_MESSAGES/libmp.po index be552ae..e96703f 100644 --- a/locale/tr/LC_MESSAGES/libmp.po +++ b/locale/tr/LC_MESSAGES/libmp.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-08-09 03:16+0300\n" +"POT-Creation-Date: 2024-08-09 03:26+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/src/mptp/client.c b/src/mptp/client.c index 2e2e905..033319c 100644 --- a/src/mptp/client.c +++ b/src/mptp/client.c @@ -98,5 +98,6 @@ bool lm_mptp_client_recv(int sock, lm_mptp_t *packet) { return false; // error set by function } + pdebug_binary((char*)&packet->header, sizeof(packet->header)); return true; } diff --git a/src/mptp/mptp.c b/src/mptp/mptp.c index f7f49ff..e55ebbc 100644 --- a/src/mptp/mptp.c +++ b/src/mptp/mptp.c @@ -84,7 +84,7 @@ bool lm_mptp_socket_opts(int sock){ lm_mptp_close(sock); return false; } - + if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &flags, sizeof(int)) < 0) { lm_error_set(LM_ERR_MPTPSetsockopt); lm_mptp_close(sock); @@ -221,7 +221,7 @@ void lm_mptp_copy(lm_mptp_t *dst, lm_mptp_t *src) { } bool lm_mptp_recv(int sock, lm_mptp_t *packet) { - if (recv(sock, &packet->header, sizeof(packet->header), 0) <= 0) { + if (recv(sock, &packet->header, sizeof(packet->header), MSG_WAITALL) <= 0) { if (ETIMEDOUT == errno || EAGAIN == errno) { lm_error_set(LM_ERR_MPTPTimeout); return false; @@ -229,13 +229,13 @@ bool lm_mptp_recv(int sock, lm_mptp_t *packet) { lm_error_set(LM_ERR_MPTPRecvFail, strerror(errno)); return false; } - + packet->header.flags = ntohs(packet->header.flags); // packet->header.host_size = ntohs(packet->header.host_size); // packet->header.data_size = ntohs(packet->header.data_size); if (packet->header.host_size <= MPTP_HOST_MAX && packet->header.host_size != 0){ - if(recv(sock, packet->host, packet->header.host_size, 0) <= 0){ + if(recv(sock, packet->host, packet->header.host_size, MSG_WAITALL) <= 0){ if (ETIMEDOUT == errno || EAGAIN == errno) { lm_error_set(LM_ERR_MPTPTimeout); return false; @@ -246,7 +246,7 @@ bool lm_mptp_recv(int sock, lm_mptp_t *packet) { } if (packet->header.data_size <= MPTP_DATA_MAX && packet->header.data_size != 0){ - if(recv(sock, packet->data, packet->header.data_size, 0) <= 0){ + if(recv(sock, packet->data, packet->header.data_size, MSG_WAITALL) <= 0){ if (ETIMEDOUT == errno || EAGAIN == errno) { lm_error_set(LM_ERR_MPTPTimeout); return false;