[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Linphone-developers] ortp: using port used by other process

From: Petr Kuba
Subject: Re: [Linphone-developers] ortp: using port used by other process
Date: Tue, 07 Apr 2009 17:00:00 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv: Gecko/20070111 SeaMonkey/1.1


We've finally managed to prepare the patch to make SO_REUSEADDR configurable in rtp_session_set_local_addr(). Please find it attached.

The patch introduce new #define SO_REUSE_ADDR which is handled by --enable-so-reuseaddr configure argument.

By default, SO_REUSE_ADDR is used, i.e. behavior of ortp remains unchanged.


P.S.: We also had to do some changes to compile ortp under solaris. We will send a patch later.

   Petr Kuba, Project Manager
   OptimSys, s.r.o
   Tel: +420 541 143 065
   Fax: +420 541 143 066

Simon Morlat wrote:
Yes I think SO_REUSEADDR should be made configurable. This makes sense the case you describe.
Would you like to send a patch ?


Le Tuesday 24 March 2009 15:24:10 Petr Kuba, vous avez écrit :
Hello Simon,

I haven't received any response to my email below. I would like to know
what is your opinion about the problem I've described. Would it be
possible to make SO_REUSEADDR configurable (i.e. use #define for it) or
do you find it absolutely useless?


Petr Kuba wrote:
Hello Simon,
thank you for your quick response.

Yes, we are setting explicitly the port using

Our application is a media server which can open many rtp streams. We
use a pool (range) of ports which are used iteratively for rtp streams.
The problem appears when two instances of the server are run
simultaneously (which can be sometimes useful). In this case we need to
detect that we are trying to open a socket which is already in use and
report an error. SO_REUSEADDR seems to be dangerous in this case.

We don't want to use random ports because with large number of ports
(e.g. more than 1000) the pool is faster. We just need to get informed
about error in some specific cases (such as two instances running with
the same pool).

According to what I found out about close() the socket should become
available again after some (unspecified) time so with large enough pool
I believe this should not be a problem. BTW have you considered calling
shutdown() and receiving FD_CLOSE before calling close()? It looks like
it might help a little bit (but I might be wrong).

Do you think that it would be possible at least to make use SO_REUSEADDR

BTW, one more (very minor from our point of view) problem we met while
inspecting this problem:

When calling rtp_session_set_local_addr() for the first time
session->rtp.socket seems to have uninitialized (random) value. It
causes calling of the following code at the beginning of
rtp_session_set_local_addr() which is probably not desired:

    /* don't rebind, but close before*/


Simon Morlat wrote:

Are you setting explicitely the port using rtp_session_set_local_addr()
? In lastest version of oRTP, if rtp_session_set_local_addr() is used,
SO_REUSEADDR is used to allow the socket to be reused later (after
If rtp_session_set_local_addr() is NOT used, then a random port is
choosen by oRTP, and in this case SO_REUSEADDR is not used to avoid
binding on a busy port.
Does it solve your problem ?


Le Thursday 19 March 2009 13:36:38 Petr Kuba, vous avez écrit :

We met the following problem with ortp in our application: if the local
port we want to use is already used by some other process no error is
reported. Therefore we do not hear any audio without being informed
about the problem.

We believe that this is caused by the following line in the
create_and_bind() function:

err = setsockopt (sock, SOL_SOCKET, SO_REUSEADDR,
        (SOCKET_OPTION_VALUE)&optval, sizeof (optval));

The create_and_bind() function is called from the
rtp_session_set_local_addr() function.

We met this problem in ortp 0.13.1 (under Windows XP) but after quick
check it looks like the same would happen with 0.15.0.

Could you explain us why SO_REUSEADDR option is used and suggest some
way to detect problems? Our idea is to make use of SO_REUSEADDR


Index: ortp-0.15.0/src/rtpsession_inet.c
--- ortp-0.15.0/src/rtpsession_inet.c   (revision 3022)
+++ ortp-0.15.0/src/rtpsession_inet.c   (revision 3080)
@@ -246,13 +246,19 @@
        ortp_socket_t sock;
        int sockfamily;
+       bool_t reuse_addr;
        if (session->rtp.socket>=0){
                /* don't rebind, but close before*/
+       reuse_addr=TRUE;
+       reuse_addr=FALSE;
        /* try to bind the rtp port */
        if (port>0)
-               sock=create_and_bind(addr,port,&sockfamily,TRUE);
+               sock=create_and_bind(addr,port,&sockfamily,reuse_addr);
        if (sock!=-1){
@@ -261,7 +267,7 @@
                /*try to bind rtcp port */
-               sock=create_and_bind(addr,port+1,&sockfamily,TRUE);
+               sock=create_and_bind(addr,port+1,&sockfamily,reuse_addr);
                if (sock!=-1){
Index: ortp-0.15.0/src/ortp-config-win32.h
--- ortp-0.15.0/src/ortp-config-win32.h (revision 3022)
+++ ortp-0.15.0/src/ortp-config-win32.h (revision 3080)
@@ -28,4 +28,7 @@
 /* define the debug mode */
 #define RTP_DEBUG 1
 #define HAVE_SRTP 1
+/* enables SO_REUSEADDR socket option in the rtp_session_set_local_addr() 
function */
+#define SO_REUSE_ADDR 1
Index: ortp-0.15.0/
--- ortp-0.15.0/    (revision 3022)
+++ ortp-0.15.0/    (revision 3080)
@@ -202,6 +202,20 @@
+                               [  --enable-so-reuseaddr=[yes/no]   enables 
SO_REUSEADDR socket option in the rtp_session_set_local_addr() function.],
+                               [case "${enableval}" in
+                                       yes) so_reuseaddr_enabled=yes;;
+                                       no) so_reuseaddr_enabled=no;;
+                                       *) AC_MSG_ERROR("Bad value for 
+                               esac],
+                               [so_reuseaddr_enabled=yes])
+if test "$so_reuseaddr_enabled" = "yes" ; then
+       AC_DEFINE(SO_REUSE_ADDR,1,[Defined when SO_REUSEADDR socket option in 
the rtp_session_set_local_addr() function is enabled])
 dnl Checks for header files.
 AC_CHECK_HEADERS(poll.h sys/poll.h sys/uio.h fcntl.h sys/time.h unistd.h 
sys/audio.h linux/soundcard.h)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]