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: TCPServer.cpp
- Revision:
- 10:97d166c4a193
- Parent:
- 9:1600369a29dd
- Child:
- 15:94e2cf3a06be
--- a/TCPServer.cpp Tue Apr 05 12:52:07 2016 -0500
+++ b/TCPServer.cpp Tue Apr 05 13:09:43 2016 -0500
@@ -15,6 +15,7 @@
*/
#include "TCPServer.h"
+#include "Timer.h"
TCPServer::TCPServer(NetworkInterface *iface)
: Socket(iface, NetworkInterface::TCP)
@@ -41,20 +42,29 @@
int TCPServer::accept(TCPSocket *connection)
{
- if (!_socket) {
- return NSAPI_ERROR_NO_SOCKET;
- }
+ mbed::Timer timer;
+ timer.start();
void *socket = connection->_socket;
connection->_socket = 0;
_iface->socket_destroy(socket);
- int err = _iface->socket_accept(_socket, &socket);
- if (!err) {
- connection->_socket = socket;
+ while (true) {
+ if (!_socket) {
+ return NSAPI_ERROR_NO_SOCKET;
+ }
+
+ int err = _iface->socket_accept(_socket, &socket);
+
+ if (err > 0) {
+ connection->_socket = socket;
+ }
+
+ if (err != NSAPI_ERROR_WOULD_BLOCK || !_blocking ||
+ (_timeout && timer.read_ms() > _timeout)) {
+ return err;
+ }
}
-
- return err;
}