fix: add MSG_WAITALL flag for recv function
This commit is contained in:
parent
cb9f5da339
commit
6fdc283cc4
@ -8,7 +8,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \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"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
@ -98,5 +98,6 @@ bool lm_mptp_client_recv(int sock, lm_mptp_t *packet) {
|
|||||||
return false; // error set by function
|
return false; // error set by function
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pdebug_binary((char*)&packet->header, sizeof(packet->header));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ bool lm_mptp_socket_opts(int sock){
|
|||||||
lm_mptp_close(sock);
|
lm_mptp_close(sock);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &flags, sizeof(int)) < 0) {
|
if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &flags, sizeof(int)) < 0) {
|
||||||
lm_error_set(LM_ERR_MPTPSetsockopt);
|
lm_error_set(LM_ERR_MPTPSetsockopt);
|
||||||
lm_mptp_close(sock);
|
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) {
|
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) {
|
if (ETIMEDOUT == errno || EAGAIN == errno) {
|
||||||
lm_error_set(LM_ERR_MPTPTimeout);
|
lm_error_set(LM_ERR_MPTPTimeout);
|
||||||
return false;
|
return false;
|
||||||
@ -229,13 +229,13 @@ bool lm_mptp_recv(int sock, lm_mptp_t *packet) {
|
|||||||
lm_error_set(LM_ERR_MPTPRecvFail, strerror(errno));
|
lm_error_set(LM_ERR_MPTPRecvFail, strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
packet->header.flags = ntohs(packet->header.flags);
|
packet->header.flags = ntohs(packet->header.flags);
|
||||||
// packet->header.host_size = ntohs(packet->header.host_size);
|
// packet->header.host_size = ntohs(packet->header.host_size);
|
||||||
// packet->header.data_size = ntohs(packet->header.data_size);
|
// packet->header.data_size = ntohs(packet->header.data_size);
|
||||||
|
|
||||||
if (packet->header.host_size <= MPTP_HOST_MAX && packet->header.host_size != 0){
|
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) {
|
if (ETIMEDOUT == errno || EAGAIN == errno) {
|
||||||
lm_error_set(LM_ERR_MPTPTimeout);
|
lm_error_set(LM_ERR_MPTPTimeout);
|
||||||
return false;
|
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 (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) {
|
if (ETIMEDOUT == errno || EAGAIN == errno) {
|
||||||
lm_error_set(LM_ERR_MPTPTimeout);
|
lm_error_set(LM_ERR_MPTPTimeout);
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user