9 years, 8 months ago.

UDPSocket implementation question

I'm using mbed's release of the SDK dated 2014-06-25 and I'm having a problem understanding the implementation of the sendto() and recvfrom() methods in the UDPSocket class.

In particular the timeout functionality used for the blocking/non-blocking feature.

Here is the code in mbed:

Code snippet from UDPSocket.cpp

int UDPSocket::receiveFrom(Endpoint &remote, char *buffer, int length) {
    if (_sock_fd < 0)
        return -1;

    if (!_blocking) {
        TimeInterval timeout(_timeout);
        if (wait_readable(timeout) != 0)
            return 0;
    }

    remote.reset_address();
    socklen_t remoteHostLen = sizeof(remote._remoteHost);
    return lwip_recvfrom(_sock_fd, buffer, length, 0, (struct sockaddr*) &remote._remoteHost, &remoteHostLen);
}

Now, if "_blocking" is set to true, you do not test for the timeout interval... correct? What am I missing? Shouldn't the "!" character be removed?

Cheers!!

Sorry for the format, it appears your widget removed a lot of CR characters. If you can browse your own repo then have a look at file: UDPSocket.cpp and either method at line: 68 or line 82.

Cheers!!

Fixed it!!

Cheers!!

posted by John Dowd 22 Aug 2014
Be the first to answer this question.