Commit 494933e1 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Use net_ConnectUDP

parent 544ad949
...@@ -180,8 +180,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -180,8 +180,7 @@ static int Open( vlc_object_t *p_this )
char *psz_dst_addr; char *psz_dst_addr;
int i_dst_port; int i_dst_port;
module_t *p_network; int i_handle;
network_socket_t socket_desc;
vlc_value_t val; vlc_value_t val;
...@@ -249,37 +248,16 @@ static int Open( vlc_object_t *p_this ) ...@@ -249,37 +248,16 @@ static int Open( vlc_object_t *p_this )
p_sys->p_thread->i_empty_depth = 0; p_sys->p_thread->i_empty_depth = 0;
vlc_mutex_init( p_access, &p_sys->p_thread->blocks_lock ); vlc_mutex_init( p_access, &p_sys->p_thread->blocks_lock );
/* FIXME: use net_OpenUDP API */
socket_desc.psz_server_addr = psz_dst_addr;
socket_desc.i_server_port = i_dst_port;
socket_desc.psz_bind_addr = "";
socket_desc.i_bind_port = 0;
socket_desc.i_handle = -1;
socket_desc.v6only = 0;
var_Get( p_access, SOUT_CFG_PREFIX "ttl", &val ); var_Get( p_access, SOUT_CFG_PREFIX "ttl", &val );
socket_desc.i_ttl = val.i_int; i_handle = net_ConnectUDP( p_this, psz_dst_addr, i_dst_port, val.i_int );
if( i_handle == -1 )
p_sys->p_thread->p_private = (void*)&socket_desc;
p_network = module_Need( p_sys->p_thread, "network", "ipv4", VLC_TRUE );
if( p_network != NULL )
module_Unneed( p_sys->p_thread, p_network );
if( socket_desc.i_handle == -1 )
{ {
p_network = module_Need( p_sys->p_thread, "network", "ipv6", VLC_TRUE ); msg_Err( p_access, "failed to open a connection (udp)" );
if( p_network != NULL ) return VLC_EGENERIC;
module_Unneed( p_sys->p_thread, p_network );
if( socket_desc.i_handle == -1 )
{
msg_Err( p_access, "failed to open a connection (udp)" );
return VLC_EGENERIC;
}
} }
p_sys->p_thread->i_handle = socket_desc.i_handle; p_sys->p_thread->i_handle = i_handle;
net_StopRecv( socket_desc.i_handle ); net_StopRecv( i_handle );
var_Get( p_access, SOUT_CFG_PREFIX "caching", &val ); var_Get( p_access, SOUT_CFG_PREFIX "caching", &val );
p_sys->p_thread->i_caching = (int64_t)val.i_int * 1000; p_sys->p_thread->i_caching = (int64_t)val.i_int * 1000;
...@@ -287,7 +265,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -287,7 +265,7 @@ static int Open( vlc_object_t *p_this )
var_Get( p_access, SOUT_CFG_PREFIX "group", &val ); var_Get( p_access, SOUT_CFG_PREFIX "group", &val );
p_sys->p_thread->i_group = val.i_int; p_sys->p_thread->i_group = val.i_int;
p_sys->i_mtu = socket_desc.i_mtu; p_sys->i_mtu = var_CreateGetInteger( p_this, "mtu" );
if( vlc_thread_create( p_sys->p_thread, "sout write thread", ThreadWrite, if( vlc_thread_create( p_sys->p_thread, "sout write thread", ThreadWrite,
VLC_THREAD_PRIORITY_HIGHEST, VLC_FALSE ) ) VLC_THREAD_PRIORITY_HIGHEST, VLC_FALSE ) )
......
...@@ -166,16 +166,9 @@ int __net_ConnectUDP( vlc_object_t *p_this, const char *psz_host, int i_port, ...@@ -166,16 +166,9 @@ int __net_ConnectUDP( vlc_object_t *p_this, const char *psz_host, int i_port,
if( i_hlim < 1 ) if( i_hlim < 1 )
{ {
vlc_value_t val; i_hlim = var_CreateGetInteger( p_this, "ttl" );
if( i_hlim < 1 )
if( var_Get( p_this, "ttl", &val ) != VLC_SUCCESS ) i_hlim = 1;
{
var_Create( p_this, "ttl", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Get( p_this, "ttl", &val );
}
i_hlim = val.i_int;
if( i_hlim < 1 ) i_hlim = 1;
} }
memset( &hints, 0, sizeof( hints ) ); memset( &hints, 0, sizeof( hints ) );
......
...@@ -57,7 +57,6 @@ struct sap_address_t ...@@ -57,7 +57,6 @@ struct sap_address_t
{ {
char *psz_address; char *psz_address;
char psz_machine[NI_MAXNUMERICHOST]; char psz_machine[NI_MAXNUMERICHOST];
int i_port;
int i_rfd; /* Read socket */ int i_rfd; /* Read socket */
int i_wfd; /* Write socket */ int i_wfd; /* Write socket */
...@@ -370,9 +369,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, ...@@ -370,9 +369,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
return VLC_ENOMEM; return VLC_ENOMEM;
} }
p_address->psz_address = strdup( psz_addr ); p_address->psz_address = strdup( psz_addr );
p_address->i_port = 9875; p_address->i_wfd = net_ConnectUDP( p_sap, psz_addr, SAP_PORT, 0 );
p_address->i_wfd = net_OpenUDP( p_sap, "", 0, psz_addr,
p_address->i_port );
if( p_address->i_wfd != -1 ) if( p_address->i_wfd != -1 )
{ {
char *ptr; char *ptr;
...@@ -389,8 +386,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, ...@@ -389,8 +386,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
if( p_sap->b_control == VLC_TRUE ) if( p_sap->b_control == VLC_TRUE )
{ {
p_address->i_rfd = net_OpenUDP( p_sap, psz_addr, p_address->i_rfd = net_OpenUDP( p_sap, psz_addr, SAP_PORT, "", 0 );
p_address->i_port, "", 0 );
if( p_address->i_rfd != -1 ) if( p_address->i_rfd != -1 )
net_StopSend( p_address->i_rfd ); net_StopSend( p_address->i_rfd );
p_address->i_buff = 0; p_address->i_buff = 0;
...@@ -558,7 +554,7 @@ static int announce_SendSAPAnnounce( sap_handler_t *p_sap, ...@@ -558,7 +554,7 @@ static int announce_SendSAPAnnounce( sap_handler_t *p_sap,
i_ret = net_Write( p_sap, p_session->p_address->i_wfd, NULL, i_ret = net_Write( p_sap, p_session->p_address->i_wfd, NULL,
p_session->psz_data, p_session->psz_data,
p_session->i_length ); p_session->i_length );
if( i_ret != p_session->i_length ) if( i_ret != (int)p_session->i_length )
{ {
msg_Warn( p_sap, "SAP send failed on address %s (%i %i)", msg_Warn( p_sap, "SAP send failed on address %s (%i %i)",
p_session->p_address->psz_address, p_session->p_address->psz_address,
...@@ -628,7 +624,7 @@ static char *SDPGenerate( sap_handler_t *p_sap, ...@@ -628,7 +624,7 @@ static char *SDPGenerate( sap_handler_t *p_sap,
psz_group ? "a=x-plgroup:" : "", psz_group ? "a=x-plgroup:" : "",
psz_group ? psz_group : "", psz_group ? "\r\n" : "" ) == -1 ) psz_group ? psz_group : "", psz_group ? "\r\n" : "" ) == -1 )
return NULL; return NULL;
msg_Dbg( p_sap, "Generated SDP (%i bytes):\n%s", strlen(psz_sdp), msg_Dbg( p_sap, "Generated SDP (%i bytes):\n%s", strlen(psz_sdp),
psz_sdp ); psz_sdp );
return psz_sdp; return psz_sdp;
...@@ -679,9 +675,7 @@ static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address ) ...@@ -679,9 +675,7 @@ static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address )
} }
#ifdef EXTRA_DEBUG #ifdef EXTRA_DEBUG
msg_Dbg( p_sap,"%s:%i : Rate=%i, Interval = %i s", msg_Dbg( p_sap,"%s:%i : Rate=%i, Interval = %i s",
p_address->psz_address,p_address->i_port, p_address->psz_address,SAP_PORT, i_rate, p_address->i_interval );
i_rate,
p_address->i_interval );
#endif #endif
p_address->b_ready = VLC_TRUE; p_address->b_ready = VLC_TRUE;
......
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