Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

How to get a flag specifies of the frame type?

I geting a text frame, but periodically I need to get a binary frame. How to get a flag which at once specifies of the frame type? I tried to get

struct websocket_message * wm = (struct websocket_message *) ev_data;
wm-> the flag.

for to do something like this:
case MG_EV_WEBSOCKET_FRAME: {
iff (flag == WEBSOCKET_OP_TEXT)
// Process the text_frame_data
................................................
} else if (flag == WEBSOCKET_OP_BINARY) {
// Process binary_frame_data
................................................
}
break;
}
Is it it? Or is it possible to get more elegant and without parsing?.

Comments

  • Found in mongoose.c
    static int mg_is_ws_control_frame(unsigned char flags) {
    unsigned char op = (flags & FLAGS_MASK_OP);
    return op == WEBSOCKET_OP_CLOSE || op == WEBSOCKET_OP_PING ||
    op == WEBSOCKET_OP_PONG;
    }
    and wrote according to the sample

    static int mg_is_ws_control_frame_type(unsigned char flags) {
    unsigned char op = (flags & FLAGS_MASK_OP);
    return op == WEBSOCKET_OP_TEXT || op == WEBSOCKET_OP_BINARY ||
    op == WEBSOCKET_OP_PING;
    }

Sign In or Register to comment.