[Live-devel] RTP over TCP sometimes locks up the server

peterleese at lineone.net peterleese at lineone.net
Mon Sep 10 08:30:55 PDT 2007


In live555 release 0.18 (1st July 2007), I have occassional found that 
the server can "appear" to lock up when streaming RTP over TCP. After 
much analysis I think I have traced the problem to the tcpReaderHandler 
method in RTP_Interface.cpp.

Specifically lines 332 to 337

do {
      if (readSocket(env, socketNum, &c, 1, fromAddress) != 1) { // 
error reading TCP socket
	env.taskScheduler().turnOffBackgroundReadHandling(socketNum); // 
stops further calls to us
	return;
      }
    } while (c != '$');

The problem is that the readSocket() function can block and will block 
if the next (and last) character to read is not a '$'. That is the 
function gets 'tcpReadHandler' gets called from the scheduler because 
there is something to read. The function reads the characters and that 
could be some RTSP command from the client which is discarded (I'm 
happy with that) but if there is no '$' then we are stuck in that do 
while loop forever (no return back to the scheduler) until the socket 
dies. My suggested solution is to pass a timeout to the readSocket() of 
0 seconds (as opposed to the default of NULL - i.e. infinity) something 
like so:

struct timeval wait;
wait.tv_sec = 0;
wait.tv_usec = 0;

do {
      int retval =  readSocket(env, socketNum, &c, 1, fromAddress, 
&wait);
     if(retVal != 1) { // error reading TCP socket
        if(retVal < 0) {
	env.taskScheduler().turnOffBackgroundReadHandling(socketNum); // 
stops further calls to us
       }
	return;
      }
    } while (c != '$');

This will make sure that if there is nothing left to read then at 
least the function will return.

P.S. I've using real-player as the client so you may say that's a bad 
idea, but I think the above change should be done?

regards Peter




lines



__________________________________________________
Tiscali Broadband only £7.99 a month for your first 3 months! http://www.tiscali.co.uk/products/broadband/


More information about the live-devel mailing list