Skip to content

Clearing pending events on Socket instances #2426

Closed
@tommikas

Description

@tommikas

In blocking mode, for example:

  1. create, open and bind a UDP socket
  2. attach the socket to a callback function
  3. receiving a UDP packet on the listening port triggers the callback
  4. call recvfrom to retrieve the data
  5. an event seems to be pending, which blocks any subsequently received UDP packets from triggering the callback

In step 4, it seems that the _pending flag is cleared before socket_recvfrom() is called, which in turn triggers the event callback again setting the _pending flag again.

In non-blocking mode the recvfrom call in step 4 also triggers another callback, but a 2nd recvfrom call (which returns NSAPI_ERROR_WOULD_BLOCK) clears the flag, allowing new events to trigger the callback.

The same thing seems to happen with at least UDPSocket::recvfrom, TCPSocket::recv and TCPServer::accept.

Is this the intended behaviour? Have to use non-blocking sockets and make the call twice to clear the pending event to be able to receive new ones?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions