Skip to content

Commit 362a960

Browse files
committed
Use send API to send UDP packets if the IP address and port of the last sendto was the same
1 parent 6088fa6 commit 362a960

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/utility/WiFiSocket.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ WiFiSocketClass::WiFiSocketClass()
5555
_info[i].buffer.data = NULL;
5656
_info[i].buffer.head = NULL;
5757
_info[i].buffer.length = 0;
58+
memset(&_info[i]._lastSendtoAddr, 0x00, sizeof(_info[i]._lastSendtoAddr));
5859
}
5960
}
6061

@@ -322,7 +323,13 @@ sint16 WiFiSocketClass::sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLe
322323
return -1;
323324
}
324325

325-
return ::sendto(sock, pvSendBuffer, u16SendLength, flags, pstrDestAddr, u8AddrLen);
326+
if (memcmp(&_info[sock]._lastSendtoAddr, pstrDestAddr, sizeof(_info[sock]._lastSendtoAddr)) != 0) {
327+
memcpy(&_info[sock]._lastSendtoAddr, pstrDestAddr, sizeof(_info[sock]._lastSendtoAddr));
328+
329+
return ::sendto(sock, pvSendBuffer, u16SendLength, flags, pstrDestAddr, u8AddrLen);
330+
} else {
331+
return ::send(sock, pvSendBuffer, u16SendLength, 0);
332+
}
326333
}
327334

328335
sint8 WiFiSocketClass::close(SOCKET sock)
@@ -348,6 +355,7 @@ sint8 WiFiSocketClass::close(SOCKET sock)
348355
_info[sock].buffer.head = NULL;
349356
_info[sock].buffer.length = 0;
350357
_info[sock].recvMsg.s16BufferSize = 0;
358+
memset(&_info[sock]._lastSendtoAddr, 0x00, sizeof(_info[sock]._lastSendtoAddr));
351359

352360
return ::close(sock);
353361
}

src/utility/WiFiSocket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class WiFiSocketClass {
6868
uint8_t* head;
6969
int length;
7070
} buffer;
71+
struct sockaddr _lastSendtoAddr;
7172
} _info[MAX_SOCKET];
7273
};
7374

0 commit comments

Comments
 (0)