Skip to content

Allow to stop receiving message from on_msg_recv_callback #22

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/includes/wslay/wslay.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,12 @@ struct wslay_event_on_msg_recv_arg {
/*
* Callback function invoked by wslay_event_recv() when a message is
* completely received.
*
* Return 0 if you want to continue to receive messages. Non-zero
* value will stop message processing and will cause
* wslay_event_recv() to return.
*/
typedef void (*wslay_event_on_msg_recv_callback)
typedef int (*wslay_event_on_msg_recv_callback)
(wslay_event_context_ptr ctx,
const struct wslay_event_on_msg_recv_arg *arg, void *user_data);

Expand Down
5 changes: 3 additions & 2 deletions lib/wslay_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ int wslay_event_recv(wslay_event_context_ptr ctx)
{
struct wslay_frame_iocb iocb;
ssize_t r;
while(ctx->read_enabled) {
int stop = 0;
while(ctx->read_enabled && !stop) {
memset(&iocb, 0, sizeof(iocb));
r = wslay_frame_recv(ctx->frame_ctx, &iocb);
if(r >= 0) {
Expand Down Expand Up @@ -715,7 +716,7 @@ int wslay_event_recv(wslay_event_context_ptr ctx)
arg.msg_length = msg_length;
arg.status_code = status_code;
ctx->error = 0;
ctx->callbacks.on_msg_recv_callback(ctx, &arg, ctx->user_data);
stop = ctx->callbacks.on_msg_recv_callback(ctx, &arg, ctx->user_data);
}
free(msg);
}
Expand Down