warmcat / libwebsockets

canonical libwebsockets.org networking library
https://libwebsockets.org
Other
4.76k stars 1.48k forks source link

LWS_CALLBACK_RECEIVE Gets called continuously #2115

Closed assistuelectronics closed 3 years ago

assistuelectronics commented 3 years ago

I have modified the websocket server and modified file is protocol_lws_minimal.c.

LWS_CALLBACK_RECEIVE gets called continously even websocket client stopped sending any data.

case LWS_CALLBACK_SERVER_WRITEABLE: if (!vhd->amsg.payload) break;

            if (pss->last == vhd->current)
                    break;

            if (vhd->amsg.payload)
                    __minimal_destroy_message(&vhd->amsg);

            if(user_state != SEND_NONE) {
            vhd->amsg.len = strlen(ocpp_response);
            /* notice we over-allocate by LWS_PRE */
            vhd->amsg.payload = malloc(LWS_PRE + strlen(ocpp_response));

            /* notice we allowed for LWS_PRE in the payload already */
            lwsl_notice("\r\nRESPONSE:%d: %s\r\n", vhd->amsg.len, ocpp_response);
            memcpy((char *)vhd->amsg.payload + LWS_PRE, ocpp_response, strlen(ocpp_response));
            m = lws_write(wsi, ((unsigned char *)vhd->amsg.payload) + LWS_PRE, vhd->amsg.len, LWS_WRITE_TEXT);
            if (m < (int)vhd->amsg.len) {
                    lwsl_err("ERROR %d writing to ws\n", m);
                    return -1;
            }
            user_state = SEND_NONE;
            }
            break;

    case LWS_CALLBACK_RECEIVE:

            if (vhd->amsg.payload)
                    __minimal_destroy_message(&vhd->amsg);

            vhd->amsg.len = len;
            /* notice we over-allocate by LWS_PRE */
            vhd->amsg.payload = malloc(LWS_PRE + len);
            if (!vhd->amsg.payload) {
                    lwsl_user("OOM: dropping\n");
                    break;
   }

            memcpy((char *)vhd->amsg.payload + LWS_PRE, in, len);
            vhd->current++;

            // Gousmodin
            memset(ocpp_received, 0x00, sizeof(ocpp_received));
            memcpy(ocpp_received, (char *)in, len);
            lwsl_notice("\r\nRECVD:%d: %s\r\n", len, ocpp_received);
            process_ocpp_in_messages(ocpp_received, ocpp_response);

            /*
             * let everybody know we want to write something on them
             * as soon as they are ready
             */
            lws_start_foreach_llp(struct per_session_data__minimal **,
                                  ppss, vhd->pss_list) {
                    lws_callback_on_writable((*ppss)->wsi);
            } lws_end_foreach_llp(ppss, pss_list);
            break;
lws-team commented 3 years ago

The unmodified example works well?

lws-team commented 3 years ago

... I am guessing so because the code you pasted is nonsense...

assistuelectronics commented 3 years ago

Sure, may be I haven't communicated properly. But yes let me check in detail about my issue and come back

assistuelectronics commented 3 years ago

The unmodified example works well?

But unmodified code, i can't send my own data, so modified and thought thats the right way, because I am able to get the data now with those modification but ws server throws segmentation the moment i disconnect my ws client running in pc.

lws-team commented 3 years ago

I'm not really here to be some kind of service for dedicating my time to making your code work, that's your job.

I'm here to try to make sure my code works.

assistuelectronics commented 3 years ago

I'm not really here to be some kind of service for dedicating my time to making your code work, that's your job.

I'm here to try to make sure my code works.

Sure can understand...