E
Ebenezer
Shalom
How to improve this function?
bool
SendBuffer::Flush ()
{
uint32_t const all = buf_.size();
uint32_t numWritten = 0;
if (partialFlush_) {
::neolib::segmented_array<unsigned char, chunk_size>::segment&
segment =
segmented_iterator<unsigned char,
chunk_size>(buf_.begin()).segment();
numWritten = Write(sock_, &buf_[0], segment.size());
if (numWritten < segment.size()) goto ending;
partialFlush_ = false;
}
{
int32_t const chunks = (all - numWritten) / chunk_size;
for (int32_t ii = 0; ii < chunks; ++ii) {
uint32_t bytes = Write(sock_, &buf_[numWritten], chunk_size);
numWritten += bytes;
if (bytes < chunk_size) goto ending;
}
}
if (numWritten < all) {
numWritten += Write(sock_, &buf_[numWritten], all - numWritten);
}
ending:
buf_.erase(buf_.begin(), buf_.begin() + numWritten);
if (numWritten == all) return true;
partialFlush_ = true;
return false;
}
Tia.
Brian Wood
Ebenezer Enterprises
http://webEbenezer.net
How to improve this function?
bool
SendBuffer::Flush ()
{
uint32_t const all = buf_.size();
uint32_t numWritten = 0;
if (partialFlush_) {
::neolib::segmented_array<unsigned char, chunk_size>::segment&
segment =
segmented_iterator<unsigned char,
chunk_size>(buf_.begin()).segment();
numWritten = Write(sock_, &buf_[0], segment.size());
if (numWritten < segment.size()) goto ending;
partialFlush_ = false;
}
{
int32_t const chunks = (all - numWritten) / chunk_size;
for (int32_t ii = 0; ii < chunks; ++ii) {
uint32_t bytes = Write(sock_, &buf_[numWritten], chunk_size);
numWritten += bytes;
if (bytes < chunk_size) goto ending;
}
}
if (numWritten < all) {
numWritten += Write(sock_, &buf_[numWritten], all - numWritten);
}
ending:
buf_.erase(buf_.begin(), buf_.begin() + numWritten);
if (numWritten == all) return true;
partialFlush_ = true;
return false;
}
Tia.
Brian Wood
Ebenezer Enterprises
http://webEbenezer.net