[Live-devel] Groupsock handling in OnDemandServerMediaSubsession.cpp

David BERTRAND bidibulle at operamail.com
Mon Jun 19 10:06:49 PDT 2006


> Now I'm confused.  I thought you had identified an issue (in the code
> in "OnDemandServerMediaSubsession.cpp" where we check that a
> newly-created 'groupsock' - with no explicitly-specified port number
> - ends up getting an even-numbered port) that might affect *every*
> user of the library (if they're running a unicast RTSP/RTP
> server).  
Actually yes, but it is mainly a performance issue. When trying to get your even RTP port, if you fail twice successfully then you will loop (for a whisle) trying to use the previously failed ports. That's something you don't necessarily see (depending probably on the OS you use and the load of your server) but is a problem for me.
Whisle I was investigating further and trying to fix this by changing the algorithm to get the right port number, I discovered another issue. When you specify the port you want, you may get it, even if the port is used already. Typically, in OnDemandServerMediaSubsession.cpp, when you ask for the RTCP port (RTP port + 1), but also in many test programs (for example testMP3Streamer.cpp). Another thing that is an issue for me (I don't want to receive unexpected data on my UDP sockets).
To fix the first issue, I will specify (in my own code) a "preferred port" number to get my even port number (for example, by trying previous_failed_port + 1) because I think it's the best direction to follow and also because I want to define a range of allowed ports for my server application. But then I will met the second issue for RTP sockets also, which is worst !. 
So, I must fix the second issue. And the the best way to do it is to bind() before setting the socket options. You will then be unable to  receive a UDP port already used.
But doing so means that you must check the whole liveMedia library to verify with a getSourceName() call that you got the socket number you asked. And if not, you have to handle the error correctly. This is typically not an easy task in the case of OnDemandServerMediaSubsession.cpp because if your RTCP port request fails you have to get back to the RTP port  request. So I should change many parts of the code and test all test applications for non-regression. This is too much work, time and risk if I'm te only one complaining about those two issues. Therefore I proposed a minimalist patch that doesn't impact the library code but allow me to keep it used in my server application. 

> If there is (although I, personally, have never
> seen the current code fail), then perhaps the best solution would be
> to have a special new Groupsock constructor just for this case: I.e.,
> for creating one that ends up using an arbitrary, but even-numbered
> port.
> This special new constructor could then omit setting the
> SO_REUSE_* flags, if that's necessary to make it work (although I'm
> not convinced of that either).
This is indeed an alternative to the compilation option. Actually, it would be a new constructor with reuseFlag in argument (default value = 1) and would allow to ask for a specific port number, and to get only if it is free. I can provide this new patch to GroupsockHelper class if agreed.

David

-- 
_______________________________________________
Surf the Web in a faster, safer and easier way:
Download Opera 8 at http://www.opera.com

Powered by Outblaze



More information about the live-devel mailing list