Commit ed7660f5 authored by Steve Lhomme's avatar Steve Lhomme Committed by Jean-Baptiste Kempf

chromecast: make sure we send all the message data

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 43ef6f5e
......@@ -116,7 +116,7 @@ intf_sys_t::~intf_sys_t()
// Use here only C linkage and POD types as this function is a cancelation point.
extern "C" int recvPacket(sout_stream_t *p_stream, bool &b_msgReceived,
uint32_t &i_payloadSize, int i_sock_fd, vlc_tls_t *p_tls,
unsigned *pi_received, char *p_data, bool *pb_pingTimeout,
unsigned *pi_received, uint8_t *p_data, bool *pb_pingTimeout,
int *pi_wait_delay, int *pi_wait_retries)
{
struct pollfd ufd[1];
......@@ -161,47 +161,32 @@ extern "C" int recvPacket(sout_stream_t *p_stream, bool &b_msgReceived,
* +------------------------------------+------------------------------+
* | Payload size (uint32_t big endian) | Payload data |
* +------------------------------------+------------------------------+ */
if (*pi_received < PACKET_HEADER_LEN)
while (*pi_received < PACKET_HEADER_LEN)
{
// We receive the header.
i_ret = tls_Recv(p_tls, p_data, PACKET_HEADER_LEN - *pi_received);
i_ret = tls_Recv(p_tls, p_data + *pi_received, PACKET_HEADER_LEN - *pi_received);
if (i_ret <= 0)
return i_ret;
*pi_received += i_ret;
}
else
{
// We receive the payload.
// Get the size of the payload
memcpy(&i_payloadSize, p_data, PACKET_HEADER_LEN);
i_payloadSize = hton32(i_payloadSize);
const uint32_t i_maxPayloadSize = PACKET_MAX_LEN - PACKET_HEADER_LEN;
if (i_payloadSize > i_maxPayloadSize)
{
// Error case: the packet sent by the Chromecast is too long: we drop it.
msg_Err(p_stream, "Packet too long: droping its data");
uint32_t i_size = i_payloadSize - (*pi_received - PACKET_HEADER_LEN);
if (i_size > i_maxPayloadSize)
i_size = i_maxPayloadSize;
// We receive the payload.
i_ret = tls_Recv(p_tls, p_data + PACKET_HEADER_LEN, i_size);
if (i_ret <= 0)
return i_ret;
*pi_received += i_ret;
// Get the size of the payload
memcpy(&i_payloadSize, p_data, PACKET_HEADER_LEN);
i_payloadSize = hton32(i_payloadSize);
const uint32_t i_maxPayloadSize = PACKET_MAX_LEN - PACKET_HEADER_LEN;
if (*pi_received < i_payloadSize + PACKET_HEADER_LEN)
return i_ret;
if (i_payloadSize > i_maxPayloadSize)
{
// Error case: the packet sent by the Chromecast is too long: we drop it.
msg_Err(p_stream, "Packet too long: droping its data");
*pi_received = 0;
return -1;
}
uint32_t i_size = i_payloadSize - (*pi_received - PACKET_HEADER_LEN);
if (i_size > i_maxPayloadSize)
i_size = i_maxPayloadSize;
// Normal case
i_ret = tls_Recv(p_tls, p_data + *pi_received,
i_payloadSize - (*pi_received - PACKET_HEADER_LEN));
i_ret = tls_Recv(p_tls, p_data + PACKET_HEADER_LEN, i_size);
if (i_ret <= 0)
return i_ret;
*pi_received += i_ret;
......@@ -209,12 +194,26 @@ extern "C" int recvPacket(sout_stream_t *p_stream, bool &b_msgReceived,
if (*pi_received < i_payloadSize + PACKET_HEADER_LEN)
return i_ret;
assert(*pi_received == i_payloadSize + PACKET_HEADER_LEN);
*pi_received = 0;
b_msgReceived = true;
return i_ret;
return -1;
}
// Normal case
i_ret = tls_Recv(p_tls, p_data + *pi_received,
i_payloadSize - (*pi_received - PACKET_HEADER_LEN));
if (i_ret <= 0)
return i_ret;
*pi_received += i_ret;
if (*pi_received < i_payloadSize + PACKET_HEADER_LEN)
return i_ret;
assert(*pi_received == i_payloadSize + PACKET_HEADER_LEN);
*pi_received = 0;
b_msgReceived = true;
return i_ret;
return i_ret;
}
......@@ -509,7 +508,7 @@ int intf_sys_t::sendMessages()
void intf_sys_t::handleMessages()
{
unsigned i_received = 0;
char p_packet[PACKET_MAX_LEN];
uint8_t p_packet[PACKET_MAX_LEN];
bool b_pingTimeout = false;
int i_waitdelay = PING_WAIT_TIME;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment