*** 09_02_origin/liveMedia/RTSPClient.cpp	2008-09-02 22:45:05.000000000 +0200
--- myLivemedia/liveMedia/RTSPClient.cpp	2008-10-01 13:33:46.000000000 +0200
***************
*** 163,169 ****
  }
  
  char* RTSPClient::describeURL(char const* url, Authenticator* authenticator,
! 			      Boolean allowKasennaProtocol) {
    char* cmd = NULL;
    fDescribeStatusCode = 0;
    do {  
--- 163,169 ----
  }
  
  char* RTSPClient::describeURL(char const* url, Authenticator* authenticator,
! 			      Boolean allowKasennaProtocol, int timeout) {
    char* cmd = NULL;
    fDescribeStatusCode = 0;
    do {  
***************
*** 171,182 ****
      char* username; char* password;
      if (authenticator == NULL
  	&& parseRTSPURLUsernamePassword(url, username, password)) {
!       char* result = describeWithPassword(url, username, password, allowKasennaProtocol);
        delete[] username; delete[] password; // they were dynamically allocated
        return result;
      }
  
!     if (!openConnectionFromURL(url, authenticator)) break;
  
      // Send the DESCRIBE command:
  
--- 171,182 ----
      char* username; char* password;
      if (authenticator == NULL
  	&& parseRTSPURLUsernamePassword(url, username, password)) {
!       char* result = describeWithPassword(url, username, password, allowKasennaProtocol, timeout);
        delete[] username; delete[] password; // they were dynamically allocated
        return result;
      }
  
!     if (!openConnectionFromURL(url, authenticator, timeout)) break;
  
      // Send the DESCRIBE command:
  
***************
*** 283,289 ****
  		    << redirectionURL << "\"\n";
  	  }
  	  reset();
! 	  char* result = describeURL(redirectionURL, authenticator, allowKasennaProtocol);
  	  delete[] redirectionURL;
  	  delete[] serverType;
  	  delete[] cmd;
--- 283,289 ----
  		    << redirectionURL << "\"\n";
  	  }
  	  reset();
! 	  char* result = describeURL(redirectionURL, authenticator, allowKasennaProtocol, timeout);
  	  delete[] redirectionURL;
  	  delete[] serverType;
  	  delete[] cmd;
***************
*** 417,423 ****
        
        if (fKasennaContentType != NULL
  	  && strcmp(fKasennaContentType, "PARTNER_41_MPEG-4") == 0) {
!           char* describeSDP = describeURL(url, authenticator, True);
  	  
  	  delete[] currentWord;
            delete[] cmd;
--- 417,423 ----
        
        if (fKasennaContentType != NULL
  	  && strcmp(fKasennaContentType, "PARTNER_41_MPEG-4") == 0) {
!           char* describeSDP = describeURL(url, authenticator, True, timeout);
  	  
  	  delete[] currentWord;
            delete[] cmd;
***************
*** 471,480 ****
  char* RTSPClient
  ::describeWithPassword(char const* url,
  		       char const* username, char const* password,
! 		       Boolean allowKasennaProtocol) {
    Authenticator authenticator;
    authenticator.setUsernameAndPassword(username, password);
!   char* describeResult = describeURL(url, &authenticator, allowKasennaProtocol);
    if (describeResult != NULL) {
      // We are already authorized
      return describeResult;
--- 471,480 ----
  char* RTSPClient
  ::describeWithPassword(char const* url,
  		       char const* username, char const* password,
! 		       Boolean allowKasennaProtocol, int timeout) {
    Authenticator authenticator;
    authenticator.setUsernameAndPassword(username, password);
!   char* describeResult = describeURL(url, &authenticator, allowKasennaProtocol, timeout);
    if (describeResult != NULL) {
      // We are already authorized
      return describeResult;
***************
*** 487,493 ****
    }
  
    // Try again:
!   describeResult = describeURL(url, &authenticator, allowKasennaProtocol);
    if (describeResult != NULL) {
      // The authenticator worked, so use it in future requests:
      fCurrentAuthenticator = authenticator;
--- 487,493 ----
    }
  
    // Try again:
!   describeResult = describeURL(url, &authenticator, allowKasennaProtocol, timeout);
    if (describeResult != NULL) {
      // The authenticator worked, so use it in future requests:
      fCurrentAuthenticator = authenticator;
***************
*** 498,504 ****
  
  char* RTSPClient::sendOptionsCmd(char const* url,
  				 char* username, char* password,
! 				 Authenticator* authenticator) {
    char* result = NULL;
    char* cmd = NULL;
    Boolean haveAllocatedAuthenticator = False;
--- 498,505 ----
  
  char* RTSPClient::sendOptionsCmd(char const* url,
  				 char* username, char* password,
! 				 Authenticator* authenticator,
! 				 int timeout) {
    char* result = NULL;
    char* cmd = NULL;
    Boolean haveAllocatedAuthenticator = False;
***************
*** 510,516 ****
  	  && parseRTSPURLUsernamePassword(url, username, password)) {
  	Authenticator newAuthenticator;
  	newAuthenticator.setUsernameAndPassword(username, password);
! 	result = sendOptionsCmd(url, username, password, &newAuthenticator);
  	delete[] username; delete[] password; // they were dynamically allocated
  	break;
        } else if (username != NULL && password != NULL) {
--- 511,517 ----
  	  && parseRTSPURLUsernamePassword(url, username, password)) {
  	Authenticator newAuthenticator;
  	newAuthenticator.setUsernameAndPassword(username, password);
! 	result = sendOptionsCmd(url, username, password, &newAuthenticator, timeout);
  	delete[] username; delete[] password; // they were dynamically allocated
  	break;
        } else if (username != NULL && password != NULL) {
***************
*** 519,525 ****
  	haveAllocatedAuthenticator = True;
  	authenticator->setUsernameAndPassword(username, password);
  
! 	result = sendOptionsCmd(url, username, password, authenticator);
  	if (result != NULL) break; // We are already authorized
  
  	// The "realm" field should have been filled in:
--- 520,526 ----
  	haveAllocatedAuthenticator = True;
  	authenticator->setUsernameAndPassword(username, password);
  
! 	result = sendOptionsCmd(url, username, password, authenticator, timeout);
  	if (result != NULL) break; // We are already authorized
  
  	// The "realm" field should have been filled in:
***************
*** 531,537 ****
        }
      }
  
!     if (!openConnectionFromURL(url, authenticator)) break;
  
      // Send the OPTIONS command:
  
--- 532,538 ----
        }
      }
  
!     if (!openConnectionFromURL(url, authenticator, timeout)) break;
  
      // Send the OPTIONS command:
  
***************
*** 646,655 ****
  
  Boolean RTSPClient::announceSDPDescription(char const* url,
  					   char const* sdpDescription,
! 					   Authenticator* authenticator) {
    char* cmd = NULL;
    do {
!     if (!openConnectionFromURL(url, authenticator)) break;
  
      // Send the ANNOUNCE command:
  
--- 647,657 ----
  
  Boolean RTSPClient::announceSDPDescription(char const* url,
  					   char const* sdpDescription,
! 					   Authenticator* authenticator,
! 					   int timeout) {
    char* cmd = NULL;
    do {
!     if (!openConnectionFromURL(url, authenticator, timeout)) break;
  
      // Send the ANNOUNCE command:
  
***************
*** 707,716 ****
  
  Boolean RTSPClient
  ::announceWithPassword(char const* url, char const* sdpDescription,
! 		       char const* username, char const* password) {
    Authenticator authenticator;
    authenticator.setUsernameAndPassword(username, password);
!   if (announceSDPDescription(url, sdpDescription, &authenticator)) {
      // We are already authorized
      return True;
    }
--- 709,718 ----
  
  Boolean RTSPClient
  ::announceWithPassword(char const* url, char const* sdpDescription,
! 		       char const* username, char const* password, int timeout) {
    Authenticator authenticator;
    authenticator.setUsernameAndPassword(username, password);
!   if (announceSDPDescription(url, sdpDescription, &authenticator, timeout)) {
      // We are already authorized
      return True;
    }
***************
*** 723,729 ****
  
    // Try again:
    Boolean secondTrySuccess
!     = announceSDPDescription(url, sdpDescription, &authenticator);
  
    if (secondTrySuccess) {
      // The authenticator worked, so use it in future requests:
--- 725,731 ----
  
    // Try again:
    Boolean secondTrySuccess
!     = announceSDPDescription(url, sdpDescription, &authenticator, timeout);
  
    if (secondTrySuccess) {
      // The authenticator worked, so use it in future requests:
***************
*** 1791,1797 ****
  }
  
  Boolean RTSPClient
! ::openConnectionFromURL(char const* url, Authenticator* authenticator) {
    do {
      // Set this as our base URL:
      delete[] fBaseURL; fBaseURL = strDup(url); if (fBaseURL == NULL) break;
--- 1793,1799 ----
  }
  
  Boolean RTSPClient
! ::openConnectionFromURL(char const* url, Authenticator* authenticator, int timeout) {
    do {
      // Set this as our base URL:
      delete[] fBaseURL; fBaseURL = strDup(url); if (fBaseURL == NULL) break;
***************
*** 1814,1823 ****
--- 1816,1855 ----
        // Connect to the remote endpoint:
        fServerAddress = *(unsigned*)(destAddress.data());
        MAKE_SOCKADDR_IN(remoteName, fServerAddress, htons(destPortNum));
+       //Start change for timeout on connect
+ 
+ /*
        if (connect(fInputSocketNum, (struct sockaddr*)&remoteName, sizeof remoteName)
  	  != 0) {
  	envir().setResultErrMsg("connect() failed: ");
  	break;
+ */
+       fd_set set;
+       FD_ZERO(&set);
+       timeval tvout = {0,0};
+       if (timeout > 0) {
+         FD_SET(fInputSocketNum, &set);
+         tvout.tv_sec = timeout;
+         tvout.tv_usec = 0;
+         makeSocketNonBlocking(fInputSocketNum);
+       }
+       if (connect(fInputSocketNum, (struct sockaddr*) &remoteName, sizeof remoteName) != 0) {
+         if (errno != EINPROGRESS) {
+           envir().setResultErrMsg("connect() failed: ");
+           break;
+         }
+ 	if (timeout > 0 && (select(fInputSocketNum + 1, NULL, &set, NULL, &tvout) <= 0)) {
+           envir().setResultErrMsg("select/connect() failed: ");
+           break;
+         }
+ /*
+ errno = 0;
+ if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len) < 0 || errno != 0 )
+ {
+ break;
+ }
+ */
+       //End change for timeout on connect
        }
        
        if (fTunnelOverHTTPPortNum != 0 && !setupHTTPTunneling(urlSuffix, authenticator)) break;
