Commit 1c260a3a authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont Committed by Jean-Baptiste Kempf

en50221: avoid one memory copy (refs #12307)

(cherry picked from commit 34c1ae55153af567ee6d51f53046bbbc3ef39c0c)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 9d6da84e
......@@ -34,6 +34,7 @@
#include <assert.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include <poll.h>
#include <netinet/in.h>
......@@ -243,64 +244,29 @@ static void Dump( bool b_outgoing, uint8_t *p_data, int i_size )
* TPDUSend
*****************************************************************************/
static int TPDUSend( cam_t * p_cam, uint8_t i_slot, uint8_t i_tag,
const uint8_t *p_content, int i_length )
const uint8_t *p_content, size_t i_length )
{
uint8_t i_tcid = i_slot + 1;
uint8_t p_data[MAX_TPDU_SIZE];
int i_size;
i_size = 0;
p_data[0] = i_slot;
p_data[1] = i_tcid;
p_data[2] = i_tag;
switch ( i_tag )
{
case T_RCV:
case T_CREATE_TC:
case T_CTC_REPLY:
case T_DELETE_TC:
case T_DTC_REPLY:
case T_REQUEST_TC:
p_data[3] = 1; /* length */
p_data[4] = i_tcid;
i_size = 5;
break;
case T_NEW_TC:
case T_TC_ERROR:
p_data[3] = 2; /* length */
p_data[4] = i_tcid;
p_data[5] = p_content[0];
i_size = 6;
break;
uint8_t p_data[9], *p = p_data;
case T_DATA_LAST:
case T_DATA_MORE:
{
/* i_length <= MAX_TPDU_DATA */
uint8_t *p = p_data + 3;
p = SetLength( p, i_length + 1 );
*p++ = i_tcid;
*(p++) = i_slot;
*(p++) = i_slot + 1; /* TCID */
*(p++) = i_tag;
p = SetLength( p, i_length + 1 );
if ( i_length )
memcpy( p, p_content, i_length );
i_size = i_length + (p - p_data);
break;
}
*(p++) = i_slot + 1;
Dump( true, p_data, p - p_data );
default:
break;
}
Dump( true, p_data, i_size );
const struct iovec iov[2] = {
{ p_data, p - p_data },
{ (void *)p_content, i_length },
};
if ( write( p_cam->fd, p_data, i_size ) != i_size )
if ( writev( p_cam->fd, iov, 2 ) <= 0 )
{
msg_Err( p_cam->obj, "cannot write to CAM device: %s",
vlc_strerror_c(errno) );
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
......
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