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

uSockRead should return if a socket is closed by remote #168

Closed
arnoutdekimo opened this issue Nov 17, 2023 · 5 comments
Closed

uSockRead should return if a socket is closed by remote #168

arnoutdekimo opened this issue Nov 17, 2023 · 5 comments
Labels
feature New functionality

Comments

@arnoutdekimo
Copy link

Hi,

Just a comment on the workings of the function uSockRead.
If we set a read timeout of 10s (uSockOptionSet(sock, U_SOCK_OPT_LEVEL_SOCK, U_SOCK_OPT_RCVTIMEO), and poll uSockRead in a loop, we expected indeed after 10s of no data received, that the functions returns.

However, if the socket is closed within that time, the module does report this:

0:00:37:859 - OK
0:00:37:859 -
0:00:37:915 - +UUSOCL: 0
0:00:37:915 -
0:00:37:915 - OK
0:00:37:916 -
0:00:37:916 - +UUSOCL: 0
0:00:37:985 - AT+USORD=0,0
0:00:38:036 -
0:00:38:073 - +CME ERROR: Operation not allowed
0:00:38:074 -
0:00:38:074 - AT+USORD=0,0
0:00:38:191 -
0:00:38:231 - +CME ERROR: Operation not allowed
0:00:38:232 -
0:00:38:232 - AT+USORD=0,0
0:00:38:349 -
0:00:38:389 - +CME ERROR: Operation not allowed
0:00:38:390 -
0:00:38:390 - AT+USORD=0,0
0:00:38:507 -

But ubxlib does not use this information and keeps blocking for the timeout setting. (loop in receive function)

Ideally, a posix socket would directly return in this case, indicating that the connection has closed.

It's possible to work around this behavior, but just letting it know that it is unexpected.

@RobMeades
Copy link
Contributor

Yes, I've wondered about capturing this and reporting it somehow, I will add it to the TODO list.

@RobMeades RobMeades added the feature New functionality label Nov 17, 2023
@RobMeades RobMeades changed the title uSockRead blocks even if socket is closed uSockRead should return if a socket is closed by remote Nov 17, 2023
@arnoutdekimo
Copy link
Author

(FYI, my current workaround is using small socket timeouts (using my own big one externally) + uSockRegisterCallbackClosed, and letting it set a boolean, so I can check after uSockRead returns -1 whether the socket is still alive or not. )

@RobMeades
Copy link
Contributor

RobMeades commented Jan 18, 2024

Hi Arnout: I've pushed a preview branch of the change here 4d29ef0. Is that the kind of change you were expecting? If so I'll push it to master here (then delete the preview branch).

@arnoutdekimo
Copy link
Author

Hi, yup, sounds like what was missing, thanks!

@RobMeades
Copy link
Contributor

The fix is now pushed to master here in commit c315b4f; I will delete the preview branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality
Projects
None yet
Development

No branches or pull requests

2 participants