Commit 34c1ae55 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

en50221: avoid one memory copy (refs #12307)

parent 426d8273
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <assert.h> #include <assert.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/uio.h>
#include <poll.h> #include <poll.h>
#include <netinet/in.h> #include <netinet/in.h>
...@@ -243,64 +244,29 @@ static void Dump( bool b_outgoing, uint8_t *p_data, int i_size ) ...@@ -243,64 +244,29 @@ static void Dump( bool b_outgoing, uint8_t *p_data, int i_size )
* TPDUSend * TPDUSend
*****************************************************************************/ *****************************************************************************/
static int TPDUSend( cam_t * p_cam, uint8_t i_slot, uint8_t i_tag, 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[9], *p = p_data;
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;
case T_DATA_LAST: *(p++) = i_slot;
case T_DATA_MORE: *(p++) = i_slot + 1; /* TCID */
{ *(p++) = i_tag;
/* i_length <= MAX_TPDU_DATA */ p = SetLength( p, i_length + 1 );
uint8_t *p = p_data + 3;
p = SetLength( p, i_length + 1 );
*p++ = i_tcid;
if ( i_length ) *(p++) = i_slot + 1;
memcpy( p, p_content, i_length ); Dump( true, p_data, p - p_data );
i_size = i_length + (p - p_data);
break;
}
default: const struct iovec iov[2] = {
break; { p_data, p - p_data },
} { (void *)p_content, i_length },
Dump( true, p_data, i_size ); };
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", msg_Err( p_cam->obj, "cannot write to CAM device: %s",
vlc_strerror_c(errno) ); vlc_strerror_c(errno) );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
return VLC_SUCCESS; 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