[vlc-devel] [PATCH 21/33] chromecast: make sure we send all the message data
Steve Lhomme
robux4 at videolabs.io
Wed Dec 23 12:58:40 CET 2015
---
modules/stream_out/chromecast/chromecast_ctrl.cpp | 69 +++++++++++------------
1 file changed, 34 insertions(+), 35 deletions(-)
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 89c7f16..c223a79 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -113,7 +113,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];
@@ -158,47 +158,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;
@@ -206,12 +191,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;
}
@@ -507,7 +506,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;
--
2.6.3
More information about the vlc-devel
mailing list