Skip to content

Proposed fix for AsyncUDP and AsyncUDPPacket #3288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ssilverman opened this issue Sep 27, 2019 · 6 comments
Closed

Proposed fix for AsyncUDP and AsyncUDPPacket #3288

ssilverman opened this issue Sep 27, 2019 · 6 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@ssilverman
Copy link

ssilverman commented Sep 27, 2019

Referencing #3287 (comment).

I'll get a pull request done at some point soon, but what do people think of my proposed fix in that comment? It covers both the pass-as-reference and pass-as-copy cases for implementing a AuPacketHandlerFunction. If there is agreement, I'll create a pull request for it.

To summarize the fix:

  1. Add a call to pbuf_ref in the AsyncUDPPacket copy constructor, and
  2. Call pbuf_free regardless (in AsyncUDP::_recv), outside the if and not in an else.

Here are the steps to show why I think my fix works:

  1. The reference count starts at 1, so pbuf_free needs to be called at least once.
  2. Case 1: Pass-as-reference version.
    a. packet gets created and the ref count is now 2.
    b. The packet is handled, then the packet destructor gets called and the ref count is back to 1.
    c. pbuf_free is called regardless. The ref count is zero.
  3. Case 2: Pass-as-copy version.
    a. packet gets created and the ref count is now 2.
    b. The copy is created and the ref count is now 3.
    c. When the handler ends, both the copy and packet destructors get called and the ref count goes back to 1.
    d. pbuf_free is called regardless. The ref count is zero.
ssilverman added a commit to ssilverman/arduino-esp32 that referenced this issue Sep 27, 2019
…ack for both pass-as-reference and pass-as-copy versions. See espressif#3287 and espressif#3288.
@ssilverman
Copy link
Author

ssilverman commented Sep 27, 2019

See #3290.

@stale
Copy link

stale bot commented Nov 26, 2019

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Nov 26, 2019
@ssilverman
Copy link
Author

Another thought: we could also delete the copy constructor and force use of the reference form of the callback.

@stale
Copy link

stale bot commented Nov 26, 2019

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

@stale stale bot removed the Status: Stale Issue is stale stage (outdated/stuck) label Nov 26, 2019
@stale
Copy link

stale bot commented Jan 25, 2020

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Jan 25, 2020
@stale
Copy link

stale bot commented Feb 8, 2020

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Feb 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

1 participant