mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-26 07:59:35 -05:00
pqistreamer: only allocate incoming buffer when needed, free incoming buffer when not needed anymore
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8115 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e9b722a732
commit
ee68d00376
@ -65,13 +65,10 @@ pqistreamer::pqistreamer(RsSerialiser *rss, const RsPeerId& id, BinInterface *bi
|
|||||||
mIncomingSize = 0 ;
|
mIncomingSize = 0 ;
|
||||||
|
|
||||||
/* allocated once */
|
/* allocated once */
|
||||||
mPkt_rpend_size = getRsPktMaxSize();
|
mPkt_rpend_size = 0;
|
||||||
mPkt_rpending = malloc(mPkt_rpend_size);
|
mPkt_rpending = 0;
|
||||||
mReading_state = reading_state_initial ;
|
mReading_state = reading_state_initial ;
|
||||||
|
|
||||||
// avoid uninitialized (and random) memory read.
|
|
||||||
memset(mPkt_rpending,0,mPkt_rpend_size) ;
|
|
||||||
|
|
||||||
// 100 B/s (minimal)
|
// 100 B/s (minimal)
|
||||||
setMaxRate(true, 0.1);
|
setMaxRate(true, 0.1);
|
||||||
setMaxRate(false, 0.1);
|
setMaxRate(false, 0.1);
|
||||||
@ -121,7 +118,7 @@ pqistreamer::~pqistreamer()
|
|||||||
mPkt_wpending = NULL;
|
mPkt_wpending = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(mPkt_rpending);
|
free_rpend_locked();
|
||||||
|
|
||||||
// clean up incoming.
|
// clean up incoming.
|
||||||
while(!mIncoming.empty())
|
while(!mIncoming.empty())
|
||||||
@ -254,6 +251,10 @@ int pqistreamer::tick_recv(uint32_t timeout)
|
|||||||
{
|
{
|
||||||
handleincoming_locked();
|
handleincoming_locked();
|
||||||
}
|
}
|
||||||
|
if(!(mBio->isactive()))
|
||||||
|
{
|
||||||
|
free_rpend_locked();
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,8 +487,11 @@ int pqistreamer::handleincoming_locked()
|
|||||||
{
|
{
|
||||||
mReading_state = reading_state_initial ;
|
mReading_state = reading_state_initial ;
|
||||||
inReadBytes_locked(readbytes);
|
inReadBytes_locked(readbytes);
|
||||||
|
free_rpend_locked();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
allocate_rpend_locked();
|
||||||
|
|
||||||
// enough space to read any packet.
|
// enough space to read any packet.
|
||||||
int maxlen = mPkt_rpend_size;
|
int maxlen = mPkt_rpend_size;
|
||||||
@ -960,6 +964,28 @@ void pqistreamer::inReadBytes_locked(int inb)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pqistreamer::allocate_rpend_locked()
|
||||||
|
{
|
||||||
|
if(mPkt_rpending)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mPkt_rpend_size = getRsPktMaxSize();
|
||||||
|
mPkt_rpending = malloc(mPkt_rpend_size);
|
||||||
|
|
||||||
|
// avoid uninitialized (and random) memory read.
|
||||||
|
memset(mPkt_rpending,0,mPkt_rpend_size) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pqistreamer::free_rpend_locked()
|
||||||
|
{
|
||||||
|
if(!mPkt_rpending)
|
||||||
|
return;
|
||||||
|
|
||||||
|
free(mPkt_rpending);
|
||||||
|
mPkt_rpending = 0;
|
||||||
|
mPkt_rpend_size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int pqistreamer::gatherOutQueueStatistics(std::vector<uint32_t>& per_service_count,std::vector<uint32_t>& per_priority_count)
|
int pqistreamer::gatherOutQueueStatistics(std::vector<uint32_t>& per_service_count,std::vector<uint32_t>& per_priority_count)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
||||||
|
@ -112,6 +112,9 @@ class pqistreamer: public PQInterface
|
|||||||
RsSerialiser *mRsSerialiser;
|
RsSerialiser *mRsSerialiser;
|
||||||
|
|
||||||
void *mPkt_wpending; // storage for pending packet to write.
|
void *mPkt_wpending; // storage for pending packet to write.
|
||||||
|
|
||||||
|
void allocate_rpend_locked(); // use these two functions to allocate/free the buffer below
|
||||||
|
void free_rpend_locked();
|
||||||
int mPkt_rpend_size; // size of pkt_rpending.
|
int mPkt_rpend_size; // size of pkt_rpending.
|
||||||
void *mPkt_rpending; // storage for read in pending packets.
|
void *mPkt_rpending; // storage for read in pending packets.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user