mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-06 05:14:21 -04:00
Merge pull request #212 from csoler/v0.6-TrafficOptim
V0.6 traffic optim
This commit is contained in:
commit
d50875b9bb
2 changed files with 120 additions and 82 deletions
|
@ -54,7 +54,7 @@ const int PQISTREAM_ABS_MAX = 100000000; /* 100 MB/sec (actually per loop) */
|
|||
pqistreamer::pqistreamer(RsSerialiser *rss, const RsPeerId& id, BinInterface *bio_in, int bio_flags_in)
|
||||
:PQInterface(id), mStreamerMtx("pqistreamer"),
|
||||
mBio(bio_in), mBio_flags(bio_flags_in), mRsSerialiser(rss),
|
||||
mPkt_wpending(NULL),
|
||||
mPkt_wpending(NULL), mPkt_wpending_size(0),
|
||||
mTotalRead(0), mTotalSent(0),
|
||||
mCurrRead(0), mCurrSent(0),
|
||||
mAvgReadCount(0), mAvgSentCount(0)
|
||||
|
@ -117,6 +117,7 @@ pqistreamer::~pqistreamer()
|
|||
{
|
||||
free(mPkt_wpending);
|
||||
mPkt_wpending = NULL;
|
||||
mPkt_wpending_size = 0 ;
|
||||
}
|
||||
|
||||
free_rpend_locked();
|
||||
|
@ -421,8 +422,7 @@ int pqistreamer::handleoutgoing_locked()
|
|||
|
||||
int maxbytes = outAllowedBytes_locked();
|
||||
int sentbytes = 0;
|
||||
int len;
|
||||
int ss;
|
||||
|
||||
// std::cerr << "pqistreamer: maxbytes=" << maxbytes<< std::endl ;
|
||||
|
||||
std::list<void *>::iterator it;
|
||||
|
@ -438,6 +438,7 @@ int pqistreamer::handleoutgoing_locked()
|
|||
{
|
||||
free(mPkt_wpending);
|
||||
mPkt_wpending = NULL;
|
||||
mPkt_wpending_size = 0 ;
|
||||
}
|
||||
|
||||
outSentBytes_locked(sentbytes);
|
||||
|
@ -447,6 +448,7 @@ int pqistreamer::handleoutgoing_locked()
|
|||
// a very simple round robin
|
||||
|
||||
bool sent = true;
|
||||
int nsent = 0 ;
|
||||
while(sent) // catch if all items sent.
|
||||
{
|
||||
sent = false;
|
||||
|
@ -470,26 +472,54 @@ int pqistreamer::handleoutgoing_locked()
|
|||
outSentBytes_locked(sentbytes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define GROUP_OUTGOING_PACKETS 1
|
||||
// send a out_pkt., else send out_data. unless
|
||||
// there is a pending packet.
|
||||
if (!mPkt_wpending)
|
||||
mPkt_wpending = locked_pop_out_data() ;
|
||||
#ifdef GROUP_OUTGOING_PACKETS
|
||||
{
|
||||
void *dta;
|
||||
mPkt_wpending_size = 0 ;
|
||||
int k=0;
|
||||
|
||||
while(mPkt_wpending_size < maxbytes && (dta = locked_pop_out_data())!=NULL )
|
||||
{
|
||||
uint32_t s = getRsItemSize(dta);
|
||||
mPkt_wpending = realloc(mPkt_wpending,s+mPkt_wpending_size) ;
|
||||
memcpy(mPkt_wpending+mPkt_wpending_size,dta,s) ;
|
||||
free(dta);
|
||||
mPkt_wpending_size += s ;
|
||||
++k ;
|
||||
}
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
if(k > 1)
|
||||
std::cerr << "Packed " << k << " packets into " << mPkt_wpending_size << " bytes." << std::endl;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
{
|
||||
void *dta = locked_pop_out_data() ;
|
||||
|
||||
if(dta != NULL)
|
||||
{
|
||||
mPkt_wpending = dta ;
|
||||
mPkt_wpending_size = getRsItemSize(dta);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (mPkt_wpending)
|
||||
{
|
||||
// write packet.
|
||||
len = getRsItemSize(mPkt_wpending);
|
||||
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
std::cout << "Sending Out Pkt of size " << len << " !" << std::endl;
|
||||
std::cout << "Sending Out Pkt of size " << mPkt_wpending_size << " !" << std::endl;
|
||||
#endif
|
||||
int ss=0;
|
||||
|
||||
if (len != (ss = mBio->senddata(mPkt_wpending, len)))
|
||||
if (mPkt_wpending_size != (ss = mBio->senddata(mPkt_wpending, mPkt_wpending_size)))
|
||||
{
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
std::string out;
|
||||
rs_sprintf(out, "Problems with Send Data! (only %d bytes sent, total pkt size=%d)", ss, len);
|
||||
rs_sprintf(out, "Problems with Send Data! (only %d bytes sent, total pkt size=%d)", ss, mPkt_wpending_size);
|
||||
// std::cerr << out << std::endl ;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqistreamerzone, out);
|
||||
#endif
|
||||
|
@ -499,19 +529,26 @@ int pqistreamer::handleoutgoing_locked()
|
|||
// ensuring exactly the same data is written (openSSL requirement).
|
||||
return -1;
|
||||
}
|
||||
++nsent;
|
||||
|
||||
#ifdef DEBUG_TRANSFERS
|
||||
std::cerr << "pqistreamer::handleoutgoing_locked() Sent Packet len: " << len << " @ " << RsUtil::AccurateTimeString();
|
||||
std::cerr << "pqistreamer::handleoutgoing_locked() Sent Packet len: " << mPkt_wpending_size << " @ " << RsUtil::AccurateTimeString();
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
sentbytes += mPkt_wpending_size;
|
||||
|
||||
free(mPkt_wpending);
|
||||
mPkt_wpending = NULL;
|
||||
mPkt_wpending_size = 0 ;
|
||||
|
||||
sentbytes += len;
|
||||
sent = true;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
if(nsent > 0)
|
||||
std::cerr << "nsent = " << nsent << ", total bytes=" << sentbytes << std::endl;
|
||||
#endif
|
||||
outSentBytes_locked(sentbytes);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -113,6 +113,7 @@ class pqistreamer: public PQInterface
|
|||
RsSerialiser *mRsSerialiser;
|
||||
|
||||
void *mPkt_wpending; // storage for pending packet to write.
|
||||
uint32_t mPkt_wpending_size; // ... and its size.
|
||||
|
||||
void allocate_rpend_locked(); // use these two functions to allocate/free the buffer below
|
||||
void free_rpend_locked();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue