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_Sender.cpp

Go to the documentation of this file.
00001 // Sending Factory
00002 
00003 #ifndef __J2K__TFTP_Sender_CPP__
00004 #define __J2K__TFTP_Sender_CPP__
00005 
00006 #include <j2k/Net/TFTP/TFTP_Sender.hpp>
00007 
00008 // Finish the Windows size modulo crapt and also in DataFactory
00009 // This class send data packet created by the Data Factory 
00010 // until the queue is empty or that the window Size is reached
00011 // the window size shall be incremented by the ACK function
00012 // in TFTP_Parser.
00013 
00014 TFTP_Sender::TFTP_Sender() : Basic_PThread() 
00015 {
00016    timeout = (double)option.getTimeOutValue();
00017    packet  = NULL;
00018    currentDataNo = 0;
00019 
00020    // Incremented by Acknowledge packet
00021    option.windowsizeLeft = option.getWindowSizeValue();
00022 
00023    printf("Creating Sender...\n");
00024    fflush( stdout );
00025 }
00026 
00027 void TFTP_Sender::sendData() 
00028 {
00029     option.rwlock5_data_queue.read();
00030     packet = option.data_queue->dequeue();
00031     option.rwlock5_data_queue.releaseRead();
00032 
00033     packet->send();
00034 
00035     option.rwlock6_wait_queue.write();
00036     packet->setTimeStamp( option.currentTime + timeout );
00037 
00038     // First time sent.
00039     packet->resent = 0;
00040     //printf("The windowsizeLeft is %d\n",option.windowsizeLeft);
00041     option.rwlock1_global.write();
00042     option.windowsizeLeft--;
00043     option.rwlock1_global.releaseWrite();
00044 
00045     option.waitingAck_queue->enqueue( packet );
00046     option.rwlock6_wait_queue.releaseWrite();
00047 }
00048 
00049 void TFTP_Sender::run() 
00050 {
00051     printf("Starting Sender...\n");
00052     fflush( stdout );
00053     
00054 
00055   for( currentDataNo = 1;
00056        currentDataNo <= option.LastData; //  && option.Done == FALSE;
00057        currentDataNo++ )
00058   {
00059 
00060       
00061     // If there is nothing then let other folks run.
00062     while( option.data_queue->isEmpty() ) {
00063       sched_yield();
00064     }
00065 
00066     //If the there window size is 0, then wait till it get's bigger
00067     while( option.windowsizeLeft < 1  )
00068     {
00069        sched_yield();             
00070     }    
00071       
00072     sendData();    
00073     sched_yield();
00074     
00075   }
00076   
00077    printf("Ending Sender...\n");
00078    exit(1);
00079 
00080    fflush( stdout );
00081 }
00082 
00083 #endif
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 

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