Skip to content

examples/websocket.c: check for CURLE_AGAIN on recv_pong()#12980

Closed
Theldus wants to merge 4 commits intocurl:masterfrom
Theldus:fix_eagain_websocket
Closed

examples/websocket.c: check for CURLE_AGAIN on recv_pong()#12980
Theldus wants to merge 4 commits intocurl:masterfrom
Theldus:fix_eagain_websocket

Conversation

@Theldus
Copy link

@Theldus Theldus commented Feb 24, 2024

Description

The example file docs/examples/websocket.c does not work out of the box, because the recv_pong() function does not consider that the curl_ws_recv() function might return CURLE_AGAIN if there is no data to read, causing the program to terminate prematurely.

This commit addresses this by using select(2) to make receiving pong blocking, and thus being able to continue with the main loop.

This also occurs in the example file sendrecv.c, which also makes use of select(2) for sending and receiving data, which I based on for this commit.

The example file docs/examples/websocket.c does not work out of the
box, because the recv_pong() function does not consider that the
curl_ws_recv() function might return CURLE_AGAIN if there is no data
to read, causing the program to terminate prematurely.

This commit addresses this by using select(2) to make receiving pong
blocking, and thus being able to continue with the main loop.

This also occurs in the example file sendrecv.c, which also makes use
of select(2) for sending and receiving data, which I based on for
this commit.
Co-authored-by: Viktor Szakats <vszakats@users.noreply.github.com>
Theldus and others added 2 commits April 18, 2025 21:33
Co-authored-by: Viktor Szakats <vszakats@users.noreply.github.com>
Co-authored-by: Viktor Szakats <vszakats@users.noreply.github.com>
@vszakats
Copy link
Member

vszakats commented Jul 8, 2025

websocket example's ping received retries and waits in fa0ed1f #17860,
implementing what seems to be the goal of this PR.

Closing this in favor of the above.

In any case if you'd like continue this effort, please rebase it, or create a new PR from the fresh source.


diff without whitespace changes: https://github.com/curl/curl/pull/12980/files?w=1

@vszakats vszakats closed this Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants