Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Net/TFTP/TFTP_Timeout.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__TFTP_Timeout_CPP__
00002 #define __J2K__TFTP_Timeout_CPP__
00003 
00004 #include <j2k/Net/TFTP/TFTP_Timeout.hpp>
00005 #define  DEAD   4
00006 
00007 // Must be straight forward in binary:
00008 // 1/2, 1/4, 1/8, 1/16, else we got arithmetic problems !
00009 // 250 ms
00010 TFTP_Timeout::TFTP_Timeout() : Timer( 0000000, 10 ) 
00011 {
00012   dataEmpty = 0;
00013   waitEmpty = 0;
00014   elapsed = 10.000;  // 1/4 sec
00015   packet  = NULL;
00016   timeout = option.getTimeOutValue();
00017 
00018   // This is logic time 0
00019   option.currentTime = 0;
00020 
00021   // Start the timer NOW !
00022   // Timer::start();
00023 }
00024 
00025 void TFTP_Timeout::timedRun( int signalNo ) 
00026 {
00027   option.currentTime += elapsed;
00028 
00029   //  printf("Timer[%0.001f]\n", option.currentTime );
00030 
00031   option.rwlock6_wait_queue.write();
00032   option.waitingAck_queue->setFirst();
00033   long rc = 0;
00034   while ( rc >= 0 ) {
00035     //  printf("timedRun:  rc is equal to %d\n",rc);
00036 
00037     // Not Found = -1, Empty = -50, Invalid = -100 - position
00038       rc = option.waitingAck_queue->findTimeStamp( option.currentTime );
00039 
00040     // printf("timedRun: rc is returning %d after findTimeStamp\n", rc);
00041 
00042     if ( rc < 0 ) 
00043     {
00044         
00045         //option.waitingAck_queue->display();
00046     }
00047     
00048     if ( rc >= 0 ) {
00049       // TIMEOUT for packet on waitingAck_queue->curr
00050       packet = option.waitingAck_queue->remove();
00051 
00052       // Resend it, anything else to do ?!?!!?
00053       // Do we resent the hole thing ?!
00054       packet->resent++;
00055 
00056       // After 10 timeout on the same data packet
00057       if ( packet->resent > 10 ) 
00058       {
00059         SendNotDefinedError( "ERROR: 10 Timeouts. Connection closed.\n" );
00060         exit( 1 );
00061       }
00062       
00063       printf( "Resending Data, packet Timed out! \n" );
00064       fflush(stdout);
00065       packet->send();
00066       packet->setTimeStamp( option.currentTime + timeout );
00067       option.waitingAck_queue->enqueue( packet );
00068       fflush(stdout);
00069     }
00070   }
00071 
00072   if (  option.waitingAck_queue->isEmpty() ) 
00073   {
00074      waitEmpty++; 
00075   } else {
00076      waitEmpty = 0; 
00077   }
00078   
00079   option.rwlock6_wait_queue.releaseWrite();
00080 
00081   option.rwlock5_data_queue.read();
00082   if (  option.data_queue->isEmpty() ) 
00083   { 
00084     dataEmpty++;
00085   } else {
00086     dataEmpty = 0;
00087   }
00088 
00089   option.rwlock5_data_queue.releaseRead();
00090  
00091   if ( ( dataEmpty > DEAD || waitEmpty > DEAD ) && ( option.isReading() || option.isWriting() ) ) 
00092   {
00093     exit( 0 );
00094   } 
00095 }
00096 
00097 #endif

Generated on Sun Oct 14 18:46:35 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001