Skip to content

Conversation

@wonder-mice
Copy link
Contributor

I need a way to tell wslay to stop calling on_msg_recv_callback (because my message queue is already full and I only can drop message if they will continue to come) and to return. When I decide that I'm ready to receive more messages, I will call wslay_event_recv() once again.

Don't see any existing way to achieve that. Suggesting this patch to address this issue.

@tatsuhiro-t
Copy link
Owner

Changing callback signature will break API compatibility.
I think using wslay_event_set_error() can tell the library to return immediately.
The existing use of wslay_event_set_error() is described in http://wslay.sourceforge.net/man/wslay_event_context_server_init.html.
For example, we use that function to set error code in recv_callback.

@wonder-mice
Copy link
Contributor Author

What do you think about that?

diff --git a/lib/wslay_event.c b/lib/wslay_event.c
index 5d11516..2454d5f 100644
--- a/lib/wslay_event.c
+++ b/lib/wslay_event.c
@@ -716,7 +716,8 @@ int wslay_event_recv(wslay_event_context_ptr ctx)
               arg.msg_length = msg_length;
               arg.status_code = status_code;
               ctx->error = 0;
-              stop = ctx->callbacks.on_msg_recv_callback(ctx, &arg, ctx->user_data);
+              ctx->callbacks.on_msg_recv_callback(ctx, &arg, ctx->user_data);
+              stop = ctx->error;
             }
             free(msg);
           }

@tatsuhiro-t
Copy link
Owner

Yeah, something like that.
I prefer adding new enum value to wslay_error, and check the desired value explicitly here.

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

Successfully merging this pull request may close these issues.

2 participants