From 23a617dca4d64344f18d482f2031a27a18908301 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 26 Feb 2009 14:04:48 +0000 Subject: [PATCH] Added a workarround for the packet sending problem. This is not optimal, but seems to work fairly well. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1054 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/pqissl.cc | 19 ++++++++++++++++++- libretroshare/src/pqi/pqistreamer.cc | 11 +++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index a76bab894..7d5725eac 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -33,6 +33,7 @@ #include "util/rsnet.h" #include "util/rsdebug.h" +#include #include #include @@ -1341,7 +1342,14 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat int pqissl::senddata(void *data, int len) { - int tmppktlen = SSL_write(ssl_connection, data, len); + int tmppktlen ; + int nbtries = 0 ; +#ifdef WIN32 + while( (tmppktlen = SSL_write(ssl_connection, data, len)) == -1 && nbtries++ < 50) Sleep(300); +#else + while( (tmppktlen = SSL_write(ssl_connection, data, len)) == -1 && nbtries++ < 50) usleep(300000); +#endif + if (len != tmppktlen) { std::ostringstream out; @@ -1359,6 +1367,7 @@ int pqissl::senddata(void *data, int len) out << std::endl; out << "Socket Closed Abruptly.... Resetting PQIssl"; out << std::endl; + std::cerr << out.str() ; rslog(RSL_ALERT, pqisslzone, out.str()); reset(); return -1; @@ -1368,6 +1377,7 @@ int pqissl::senddata(void *data, int len) out << "SSL_write() SSL_ERROR_WANT_WRITE"; out << std::endl; rslog(RSL_ALERT, pqisslzone, out.str()); + std::cerr << out.str() ; return -1; } else if (err == SSL_ERROR_WANT_READ) @@ -1375,6 +1385,7 @@ int pqissl::senddata(void *data, int len) out << "SSL_write() SSL_ERROR_WANT_READ"; out << std::endl; rslog(RSL_ALERT, pqisslzone, out.str()); + std::cerr << out.str() ; return -1; } else @@ -1385,6 +1396,7 @@ int pqissl::senddata(void *data, int len) out << std::endl; out << "\tResetting!"; out << std::endl; + std::cerr << out.str() ; rslog(RSL_ALERT, pqisslzone, out.str()); reset(); @@ -1442,6 +1454,7 @@ int pqissl::readdata(void *data, int len) } rslog(RSL_ALERT, pqisslzone, out.str()); + std::cerr << out.str() << std::endl ; return 0; } @@ -1454,6 +1467,7 @@ int pqissl::readdata(void *data, int len) out << std::endl; rslog(RSL_ALERT, pqisslzone, out.str()); reset(); + std::cerr << out.str() << std::endl ; return -1; } else if (error == SSL_ERROR_WANT_WRITE) @@ -1461,6 +1475,7 @@ int pqissl::readdata(void *data, int len) out << "SSL_read() SSL_ERROR_WANT_WRITE"; out << std::endl; rslog(RSL_ALERT, pqisslzone, out.str()); + std::cerr << out.str() << std::endl ; return -1; } else if (error == SSL_ERROR_WANT_READ) @@ -1468,6 +1483,7 @@ int pqissl::readdata(void *data, int len) out << "SSL_read() SSL_ERROR_WANT_READ"; out << std::endl; rslog(RSL_ALERT, pqisslzone, out.str()); + std::cerr << out.str() << std::endl ; return -1; } else @@ -1476,6 +1492,7 @@ int pqissl::readdata(void *data, int len) out << std::endl; out << "\tResetting!"; rslog(RSL_ALERT, pqisslzone, out.str()); + std::cerr << out.str() << std::endl ; reset(); return -1; } diff --git a/libretroshare/src/pqi/pqistreamer.cc b/libretroshare/src/pqi/pqistreamer.cc index 0905d5371..f19162a5e 100644 --- a/libretroshare/src/pqi/pqistreamer.cc +++ b/libretroshare/src/pqi/pqistreamer.cc @@ -436,12 +436,14 @@ int pqistreamer::handleoutgoing() if (pkt_wpending) { std::ostringstream out; - out << "Sending Out Pkt!"; // write packet. len = getRsItemSize(pkt_wpending); + + out << "Sending Out Pkt of size " << len << " !"; + if (len != (ss = bio->senddata(pkt_wpending, len))) { - out << "Problems with Send Data!"; + out << "Problems with Send Data! (only " << ss << " bytes sent" << ", total pkt size=" << len ; out << std::endl; std::cerr << out.str() ; pqioutput(PQL_DEBUG_BASIC, pqistreamerzone, out.str()); @@ -586,7 +588,7 @@ int pqistreamer::handleincoming() std::ostringstream out; out << "Error Completing Read (read "; out << tmplen << "/" << extralen << ")" << std::endl; -// std::cerr << out.str() ; + std::cerr << out.str() ; pqioutput(PQL_ALERT, pqistreamerzone, out.str()); pqiNotify *notify = getPqiNotify(); @@ -606,7 +608,8 @@ int pqistreamer::handleincoming() msgout << "\n"; std::string msg = msgout.str(); - notify->AddSysMessage(0, RS_SYS_WARNING, title, msg); + std::cout << msg << std::endl ; +// notify->AddSysMessage(0, RS_SYS_WARNING, title, msg); } bio->close(); return -1;