From bbb97806475a97548aebeb626a0a87eb7b0b3200 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Thu, 22 Apr 2010 08:29:59 +0000 Subject: [PATCH] server accepting connection modified in MySocketTCP.cxx git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@16 951219d9-93cf-4727-9268-0efd64621fa3 --- .../MySocketTCP/MySocketTCP.cxx | 80 +++++++++++++++++-- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/slsDetectorSoftware/MySocketTCP/MySocketTCP.cxx b/slsDetectorSoftware/MySocketTCP/MySocketTCP.cxx index 7bc213418..88d2df313 100644 --- a/slsDetectorSoftware/MySocketTCP/MySocketTCP.cxx +++ b/slsDetectorSoftware/MySocketTCP/MySocketTCP.cxx @@ -6,6 +6,7 @@ #include #include #include +#include using namespace std; @@ -20,7 +21,6 @@ MySocketTCP::~MySocketTCP(){ MySocketTCP::MySocketTCP(unsigned short int const port_number): last_keep_connection_open_action_was_a_send(0), file_des(-1), send_rec_max_size(SEND_REC_MAX_SIZE), is_a_server(1), portno(DEFAULT_PORTNO), socketDescriptor(-1) { // receiver (server) local no need for ip - //is_a_server = 1; portno=port_number; strcpy(hostname,"localhost"); @@ -51,7 +51,6 @@ MySocketTCP::MySocketTCP(unsigned short int const port_number): last_keep_connec MySocketTCP::MySocketTCP(const char* const host_ip_or_name, unsigned short int const port_number): last_keep_connection_open_action_was_a_send(0), file_des(-1), send_rec_max_size(SEND_REC_MAX_SIZE), is_a_server(0), portno(DEFAULT_PORTNO), socketDescriptor(-1) { // sender (client): where to? ip - //is_a_server = 0; // SetupParameters(); strcpy(hostname,host_ip_or_name); portno=port_number; @@ -93,10 +92,67 @@ int MySocketTCP::Connect(){ cerr << "Error: with server accept, connection refused"<0){ int nreceiving = (length>send_rec_max_size) ? send_rec_max_size:length; - int nreceived = read(file_des,(char*)buf+total_received,nreceiving); - if(!nreceived) break; +#ifdef VERY_VERBOSE + cout << "start to receive "<< nreceiving << " Bytes" << endl; +#endif + int 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: "<