Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: UDPSocket.cpp
- Revision:
- 10:97d166c4a193
- Parent:
- 9:1600369a29dd
- Child:
- 14:7ca9776b9cc0
--- a/UDPSocket.cpp Tue Apr 05 12:52:07 2016 -0500
+++ b/UDPSocket.cpp Tue Apr 05 13:09:43 2016 -0500
@@ -15,6 +15,7 @@
*/
#include "UDPSocket.h"
+#include "Timer.h"
UDPSocket::UDPSocket(NetworkInterface *iface)
: Socket(iface, NetworkInterface::UDP)
@@ -32,20 +33,38 @@
int UDPSocket::sendto(const SocketAddress &address, const void *data, unsigned size)
{
- if (!_socket) {
- return NSAPI_ERROR_NO_SOCKET;
+ mbed::Timer timer;
+ timer.start();
+
+ while (true) {
+ if (!_socket) {
+ return NSAPI_ERROR_NO_SOCKET;
+ }
+
+ int sent = _iface->socket_sendto(_socket, address, data, size);
+ if (sent != NSAPI_ERROR_WOULD_BLOCK || !_blocking ||
+ (_timeout && timer.read_ms() > _timeout)) {
+ return sent;
+ }
}
-
- return _iface->socket_sendto(_socket, address, data, size);
}
int UDPSocket::recvfrom(SocketAddress *address, void *buffer, unsigned size)
{
- if (!_socket) {
- return NSAPI_ERROR_NO_SOCKET;
+ mbed::Timer timer;
+ timer.start();
+
+ while (true) {
+ if (!_socket) {
+ return NSAPI_ERROR_NO_SOCKET;
+ }
+
+ int recv = _iface->socket_recvfrom(_socket, address, buffer, size);
+ if (recv != NSAPI_ERROR_WOULD_BLOCK || !_blocking ||
+ (_timeout && timer.read_ms() > _timeout)) {
+ return recv;
+ }
}
-
- return _iface->socket_recvfrom(_socket, address, buffer, size);
}