diff --git a/lib/packet_mosq.c b/lib/packet_mosq.c index 6d0a8183..f42a2c32 100644 --- a/lib/packet_mosq.c +++ b/lib/packet_mosq.c @@ -148,10 +148,10 @@ int packet__queue(struct mosquitto *mosq, struct mosquitto__packet *packet) #if defined(WITH_BROKER) && defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS if(mosq->wsi){ - packet->pos = 0; - packet->to_process = packet->packet_length; - packet->next = NULL; + packet->pos = WS_PACKET_OFFSET; + packet->to_process = packet->packet_length - WS_PACKET_OFFSET; + pthread_mutex_lock(&mosq->out_packet_mutex); if(mosq->out_packet){ mosq->out_packet_last->next = packet; diff --git a/src/websockets.c b/src/websockets.c index 070d8430..03cd49ea 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -218,17 +218,6 @@ static int callback_mqtt( while(mosq->out_packet && !lws_send_pipe_choked(mosq->wsi)){ packet = mosq->out_packet; - - if(packet->pos == 0 && packet->to_process == packet->packet_length){ - /* First time this packet has been dealt with. - * libwebsockets requires that the payload has - * LWS_PRE space available before the - * actual data. - * We've already made the payload big enough to allow this, - * but need to move it into position here. */ - memmove(&packet->payload[LWS_PRE], packet->payload, packet->packet_length); - packet->pos += LWS_PRE; - } count = lws_write(wsi, &packet->payload[packet->pos], packet->to_process, LWS_WRITE_BINARY); if(count < 0){ if (mosq->state == mosq_cs_disconnect_ws