00001
00002
00003 #ifndef __J2K__TFTP_Sender_CPP__
00004 #define __J2K__TFTP_Sender_CPP__
00005
00006 #include <j2k/Net/TFTP/TFTP_Sender.hpp>
00007
00008
00009
00010
00011
00012
00013
00014 TFTP_Sender::TFTP_Sender() : Basic_PThread()
00015 {
00016 timeout = (double)option.getTimeOutValue();
00017 packet = NULL;
00018 currentDataNo = 0;
00019
00020
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
00039 packet->resent = 0;
00040
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;
00057 currentDataNo++ )
00058 {
00059
00060
00061
00062 while( option.data_queue->isEmpty() ) {
00063 sched_yield();
00064 }
00065
00066
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