@@ -325,6 +325,26 @@ int init_rtpp_notify(void)
325325 return 0 ;
326326}
327327
328+ static rtp_io_getrnsock_t
329+ rtp_io_rnsock_f (void )
330+ {
331+ static rtp_io_getrnsock_t _rtp_io_getrnsock = {0 };
332+ if (_rtp_io_getrnsock == NULL )
333+ _rtp_io_getrnsock = (rtp_io_getrnsock_t )find_export ("rtp_io_getrnsock" , 0 );
334+ return _rtp_io_getrnsock ;
335+ }
336+
337+ int fill_rtp_io_rnsock (void )
338+ {
339+
340+ rtp_io_getrnsock_t rtp_io_rnsock = rtp_io_rnsock_f ();
341+ if (rtp_io_rnsock == NULL )
342+ return -1 ;
343+ if (rtp_io_rnsock (& rtpp_notify_cfg ) != 0 )
344+ return -1 ;
345+ return 0 ;
346+ }
347+
328348void notification_listener_process (int rank )
329349{
330350 struct sockaddr_un saddr_un ;
@@ -335,12 +355,19 @@ void notification_listener_process(int rank)
335355 struct sockaddr * saddr ;
336356 int len , n ;
337357 int optval = 1 ;
338- int socket_fd ;
358+ int socket_fd = -1 ;
339359 str * rn_name = & rtpp_notify_cfg .name ;
360+ struct rtpp_sock * rn_sock = & rtpp_notify_cfg .sock ;
361+
362+ if (rn_name -> s == NULL ) {
363+ if (fill_rtp_io_rnsock () != 0 )
364+ goto serve ;
365+ }
340366
341367 * rtpp_notify_process_no = process_no ;
342368
343- if (rtpp_notify_cfg .sock .rn_umode == CM_TCP ) {
369+ switch (rn_sock -> rn_umode ) {
370+ case CM_TCP :
344371 p = strrchr (rn_name -> s , ':' );
345372 if (!p ) {
346373 LM_ERR ("invalid udp address <%.*s>\n" , rn_name -> len , rn_name -> s );
@@ -371,7 +398,8 @@ void notification_listener_process(int rank)
371398 saddr = (struct sockaddr * )& saddr_in ;
372399 len = sizeof (saddr_in );
373400 LM_DBG ("binding socket %d to %s:%d\n" , socket_fd , rn_name -> s , port );
374- } else {
401+ break ;
402+ case CM_UNIX :
375403 /* create socket */
376404 socket_fd = socket (AF_UNIX , SOCK_STREAM , 0 );
377405 if (socket_fd == -1 ) {
@@ -386,34 +414,50 @@ void notification_listener_process(int rank)
386414 saddr = (struct sockaddr * )& saddr_un ;
387415 len = sizeof (saddr_un );
388416 LM_DBG ("binding unix socket %s\n" , rn_name -> s );
417+ break ;
418+ case CM_RTPIO :
419+ socket_fd = rn_sock -> fd ;
420+ len = -1 ;
421+ saddr = NULL ;
422+ LM_DBG ("using rtp.io notification socket %d\n" , socket_fd );
423+ break ;
424+ default :
425+ abort ();
389426 }
390427
391- if (setsockopt (socket_fd , SOL_SOCKET , SO_REUSEADDR , (void * )& optval ,
428+ if (rn_sock -> rn_umode != CM_RTPIO ) {
429+ if (setsockopt (socket_fd , SOL_SOCKET , SO_REUSEADDR , (void * )& optval ,
392430 sizeof (optval )) == -1 ) {
393- LM_ERR ("setsockopt failed %s\n" , strerror (errno ));
394- return ;
395- }
431+ LM_ERR ("setsockopt failed %s\n" , strerror (errno ));
432+ return ;
433+ }
396434
397- if (bind (socket_fd , saddr , len ) == -1 ) {
398- LM_ERR ("failed to bind to socket: %s\n" , strerror (errno ));
399- return ;
400- }
435+ if (bind (socket_fd , saddr , len ) == -1 ) {
436+ LM_ERR ("failed to bind to socket: %s\n" , strerror (errno ));
437+ return ;
438+ }
401439
402- /* open socket for listening */
403- if (listen (socket_fd , 10 ) == -1 ) {
404- LM_ERR ("socket listen failed: %s(%d)\n" , strerror (errno ), errno );
405- close (socket_fd );
406- return ;
440+ /* open socket for listening */
441+ if (listen (socket_fd , 10 ) == -1 ) {
442+ LM_ERR ("socket listen failed: %s(%d)\n" , strerror (errno ), errno );
443+ close (socket_fd );
444+ return ;
445+ }
407446 }
408447
448+ serve :
409449 if (reactor_proc_init ("RTPProxy events" ) < 0 ) {
410450 LM_ERR ("failed to init the RTPProxy events\n" );
411451 return ;
412452 }
413453
414- if (reactor_proc_add_fd ( socket_fd , rtpproxy_io_new_callback , NULL ) < 0 ) {
415- LM_CRIT ("failed to add RTPProxy listen socket to reactor\n" );
416- return ;
454+ if (socket_fd != -1 ) {
455+ reactor_proc_cb_f cb_f = (rn_sock -> rn_umode != CM_RTPIO ) ? rtpproxy_io_new_callback :
456+ rtpproxy_io_callback ;
457+ if (reactor_proc_add_fd (socket_fd , cb_f , NULL ) < 0 ) {
458+ LM_CRIT ("failed to add RTPProxy listen socket to reactor\n" );
459+ return ;
460+ }
417461 }
418462
419463 reactor_proc_loop ();
0 commit comments