Skip to content
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

[TW#15775] UDP sockets always close with an error #1094

Closed
dpgeorge opened this issue Oct 10, 2017 · 3 comments
Closed

[TW#15775] UDP sockets always close with an error #1094

dpgeorge opened this issue Oct 10, 2017 · 3 comments

Comments

@dpgeorge
Copy link

It seems that calling close(s) on a UDP (SOCK_DGRAM) socket always returns -1, meaning an error occurred. This happens right after creating a socket and also after sending/receiving data. There is no such problem with SOCK_STREAM sockets.

Simple test code (placed eg in http_request example's main loop):

int s = socket(AF_INET, SOCK_DGRAM, 0); 
int ret = close(s);
printf("UDP: s=%d ret=%d\n", s, ret);

The above code prints -1 for the ret value, whereas I would expect it to print 0.

@projectgus
Copy link
Contributor

Thanks for reporting this, @dpgeorge .

I think I can see the underlying problem: lwip_netconn_do_delconn() in api_msg.c doesn't set the return "err" to pass back to the the calling task when deleting a UDP socket. But tcpip_apimsg() in api_lib.c:80 sets ERR_VAL as a catch-all for API functions which don't set the error value correctly. This comes back to lwip_close() in sockets.c and results in the failure.

We will work on producing a fix.

@FayeY FayeY changed the title UDP sockets always close with an error [TW#15775] UDP sockets always close with an error Oct 11, 2017
@projectgus
Copy link
Contributor

This issue should be fixed as of e2d077c.

@dpgeorge
Copy link
Author

Thanks @projectgus. I will check it in due course when we update the IDF.

0xFEEDC0DE64 pushed a commit to 0xFEEDC0DE64/esp-idf that referenced this issue May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants