mirror of https://github.com/davisking/dlib.git
Changed the code a little bit so that it should be more portable and
robust to variations in how std::streamsize is defined. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403009
This commit is contained in:
parent
3fc4e6153f
commit
ab0e617ef1
|
@ -3,6 +3,7 @@
|
|||
#ifndef DLIB_SOCKSTREAMBUF_KERNEL_2_CPp_
|
||||
#define DLIB_SOCKSTREAMBUF_KERNEL_2_CPp_
|
||||
#include "sockstreambuf_kernel_2.h"
|
||||
#include "../assert.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
|
@ -39,7 +40,15 @@ namespace dlib
|
|||
std::streamsize num
|
||||
)
|
||||
{
|
||||
int space_left = static_cast<int>(epptr()-pptr());
|
||||
// Add a sanity check here
|
||||
DLIB_ASSERT(num >= 0,
|
||||
"\tstd::streamsize sockstreambuf::xsputn"
|
||||
<< "\n\tThe number of bytes to write can't be negative"
|
||||
<< "\n\tnum: " << num
|
||||
<< "\n\tthis: " << this
|
||||
);
|
||||
|
||||
std::streamsize space_left = static_cast<std::streamsize>(epptr()-pptr());
|
||||
if (num <= space_left)
|
||||
{
|
||||
std::memcpy(pptr(),s,static_cast<size_t>(num));
|
||||
|
@ -48,10 +57,10 @@ namespace dlib
|
|||
}
|
||||
else
|
||||
{
|
||||
std::memcpy(pptr(),s,space_left);
|
||||
std::memcpy(pptr(),s,static_cast<size_t>(space_left));
|
||||
s += space_left;
|
||||
pbump(space_left);
|
||||
int num_left = static_cast<int>(num) - space_left;
|
||||
std::streamsize num_left = num - space_left;
|
||||
|
||||
if (flush_out_buffer() == EOF)
|
||||
{
|
||||
|
@ -61,7 +70,7 @@ namespace dlib
|
|||
|
||||
if (num_left < out_buffer_size)
|
||||
{
|
||||
std::memcpy(pptr(),s,num_left);
|
||||
std::memcpy(pptr(),s,static_cast<size_t>(num_left));
|
||||
pbump(num_left);
|
||||
return num;
|
||||
}
|
||||
|
|
|
@ -128,9 +128,9 @@ namespace dlib
|
|||
|
||||
// member data
|
||||
connection& con;
|
||||
static const int max_putback = 4;
|
||||
static const int out_buffer_size = 10000;
|
||||
static const int in_buffer_size = 10000;
|
||||
static const std::streamsize max_putback = 4;
|
||||
static const std::streamsize out_buffer_size = 10000;
|
||||
static const std::streamsize in_buffer_size = 10000;
|
||||
char* out_buffer;
|
||||
char* in_buffer;
|
||||
|
||||
|
|
Loading…
Reference in New Issue