fix: add MSG_WAITALL flag for recv function

This commit is contained in:
ngn 2024-08-09 03:29:50 +03:00
parent cb9f5da339
commit 6fdc283cc4
3 changed files with 7 additions and 6 deletions

View File

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

View File

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

View File

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