From 14dc2fbf7e72c194d6adef5df569f1e75c70f5dc Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 1 Mar 2009 15:12:22 +0000 Subject: [PATCH] added another anti-lag strategy in pqissl.cc. This is to avoid connexion problems git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1060 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/pqissl.cc | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 7d5725eac..039342ba5 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -1409,12 +1409,30 @@ int pqissl::senddata(void *data, int len) int pqissl::readdata(void *data, int len) { int total_len = 0 ; + + // There is a do, because packets can be splitted into multiple ssl buffers + // when they are larger than 16384 bytes. Such packets have to be read in + // multiple slices. do { - int tmppktlen = SSL_read(ssl_connection, (void*)((unsigned long int)data+(unsigned long int)total_len), len-total_len); + static const int max_tries = 50 ; + int nbtries = 0 ; + int tmppktlen ; -// std::cerr <<"pqissl: read " << tmppktlen+total_len << " bytes. expected " << len << ", still " << len-(tmppktlen+total_len) << " to read"<< std::endl ; - // need to catch errors..... + // This is a loop to prevent loosing a connexion just because there is a + // lag in the network. This happens quite often actually. The total time + // to wait if nothing happens is 50*20ms = 1 sec, which is not so much. + // This current version seems to work fine. + // + while( -1 == (tmppktlen = SSL_read(ssl_connection, (void*)((unsigned long int)data+(unsigned long int)total_len), len-total_len)) && nbtries++ < max_tries) +#ifdef WIN32 + Sleep(20) ; +#else + usleep(20000) ; +#endif + + // Need to catch errors..... + // if (tmppktlen <= 0) // probably needs a reset. { std::ostringstream out;