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.
Dependencies: DnsQuery
Fork of NetworkSocketAPI by
Diff: TCPSocket.cpp
- Revision:
- 10:97d166c4a193
- Parent:
- 9:1600369a29dd
- Child:
- 15:94e2cf3a06be
--- a/TCPSocket.cpp Tue Apr 05 12:52:07 2016 -0500
+++ b/TCPSocket.cpp Tue Apr 05 13:09:43 2016 -0500
@@ -15,6 +15,7 @@
*/
#include "TCPSocket.h"
+#include "Timer.h"
TCPSocket::TCPSocket(NetworkInterface *iface)
: Socket(iface, NetworkInterface::TCP)
@@ -47,20 +48,38 @@
int TCPSocket::send(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_send(_socket, data, size);
+ if (sent != NSAPI_ERROR_WOULD_BLOCK || !_blocking ||
+ (_timeout && timer.read_ms() > _timeout)) {
+ return sent;
+ }
}
-
- return _iface->socket_send(_socket, data, size);
}
int TCPSocket::recv(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 recv = _iface->socket_recv(_socket, data, size);
+ if (recv != NSAPI_ERROR_WOULD_BLOCK || !_blocking ||
+ (_timeout && timer.read_ms() > _timeout)) {
+ return recv;
+ }
}
-
- return _iface->socket_recv(_socket, data, size);
}
