//version 1.0, base development, Ian 19/01/09 #include "MySocketTCP.h" #include #include #include using namespace std; int MySocketTCP::SendDataOnly(void* buf,int length){//length in characters #ifdef VERY_VERBOSE cout << "want to send "<< length << " Bytes" << endl; #endif int nsending; int nsent; if (file_des<0) return -1; int total_sent=0; while(length>0){ nsending = (length>send_rec_max_size) ? send_rec_max_size:length; nsent = write(file_des,(char*)buf+total_sent,nsending); if(!nsent) break; length-=nsent; total_sent+=nsent; // cout<<"nsent: "<0){ nreceiving = (length>send_rec_max_size) ? send_rec_max_size:length; #ifdef VERY_VERBOSE cout << "start to receive "<< nreceiving << " Bytes" << endl; #endif nreceived = read(file_des,(char*)buf+total_received,nreceiving); #ifdef VERY_VERBOSE cout << "received "<< nreceived << " Bytes on fd " << file_des << endl; #endif if(nreceived<0) break; length-=nreceived; #ifdef VERY_VERBOSE cout << "length left "<< length << " Bytes" << endl; #endif total_received+=nreceived; #ifdef VERY_VERBOSE cout << "total "<< total_received << " Bytes" << endl; #endif // cout<<"nrec: "<