mbed official WiflyInterface (interface for Roving Networks Wifly modules)

Dependents:   Wifly_HelloWorld Websocket_Wifly_HelloWorld RPC_Wifly_HelloWorld HTTPClient_Wifly_HelloWorld ... more

Issue: TCPSocketServer does not support non-blocking mode (lib ver 8)

TCPSocketServer::accept( ) is missing support for non-blocking mode.
As the underlying "Socket" API has a set_blocking method, I considered the lack of this support a defect, not an enhancement request. I have tested and use the proposed mods in my derived WiflyInterface.

TCPSocketServer.cpp - mbed WiflyInterface (official version 8)

int TCPSocketServer::accept(TCPSocketConnection& connection)
    ...
    while (1) {
        while(!wifi->readable());
        nb_available = wifi->readable();
        for (int i = 0; i < nb_available; i++) {
    ...

TCPSocketServer.cpp - proposed

int TCPSocketServer::accept(TCPSocketConnection& connection)
    ...
    acceptTimerStart();
    while (1) {
        nb_available = wifi->readable();
        if (nb_available == 0 && !_blocking && acceptTimeout())
            return -1;
        for (int i = 0; i < nb_available; i++) {
     ...

// add supporting methods:
void TCPSocketServer::acceptTimerStart()
{
    acceptTimer.start();
}

bool TCPSocketServer::acceptTimeout()
{
    if ((_timeout == 0) || (acceptTimer.read_ms() >= _timeout))
        return true;
    else
        return false;
}

TCPSocketServer.h - proposed

  private:
    Timer acceptTimer;
    
    void acceptTimerStart();
    bool acceptTimeout();