Commit e4549f7b authored by Davis King's avatar Davis King

Added an option for a sockstreambuf to automatically flush its output

buffers before performing any network reads.
parent 10cf3028
......@@ -109,6 +109,15 @@ namespace dlib
// copy the putback characters into the putback end of the in_buffer
std::memmove(in_buffer+(max_putback-num_put_back), gptr()-num_put_back, num_put_back);
if (flushes_output_on_read())
{
if (flush_out_buffer() == EOF)
{
// an error occurred
return EOF;
}
}
int num = con.read(in_buffer+max_putback, in_buffer_size-max_putback);
if (num <= 0)
{
......
......@@ -40,7 +40,8 @@ namespace dlib
) :
con(*con_),
out_buffer(0),
in_buffer(0)
in_buffer(0),
autoflush(false)
{
init();
}
......@@ -50,7 +51,8 @@ namespace dlib
) :
con(*con_),
out_buffer(0),
in_buffer(0)
in_buffer(0),
autoflush(false)
{
init();
}
......@@ -66,6 +68,20 @@ namespace dlib
connection* get_connection (
) { return &con; }
void flush_output_on_read()
{
autoflush = true;
}
bool flushes_output_on_read() const
{
return autoflush;
}
void do_not_flush_output_on_read()
{
autoflush = false;
}
protected:
......@@ -140,6 +156,7 @@ namespace dlib
static const std::streamsize in_buffer_size = 10000;
char* out_buffer;
char* in_buffer;
bool autoflush;
};
......
......@@ -53,6 +53,7 @@ namespace dlib
- con == a valid connection object
ensures
- *this will read from and write to con
- #flushes_output_on_read() == false
throws
- std::bad_alloc
!*/
......@@ -65,6 +66,7 @@ namespace dlib
- con == a valid connection object
ensures
- *this will read from and write to con
- #flushes_output_on_read() == false
throws
- std::bad_alloc
!*/
......@@ -88,6 +90,28 @@ namespace dlib
reads from and writes to
!*/
void flush_output_on_read (
);
/*!
ensures
- #flushes_output_on_read() == true
!*/
bool flushes_output_on_read (
) const;
/*!
ensures
- This function returns true if this object will flush its output buffer
to the network socket before performing any network read.
!*/
void do_not_flush_output_on_read (
);
/*!
ensures
- #flushes_output_on_read() == false
!*/
};
// ----------------------------------------------------------------------------------------
......
......@@ -17,9 +17,14 @@ namespace dlib
{
/*!
WHAT THIS OBJECT REPRESENTS
This is an implementation of the interface defined in sockstreambuf_abstract.h
except that it doesn't do any kind of buffering at all. It just writes
data directly to a connection.
This is an implementation of the interface defined in
sockstreambuf_abstract.h except that it doesn't do any kind of buffering at
all. It just writes data directly to a connection. However, note that we
don't implement the flushes_output_on_read() routine as this object always
flushes immediately (since it isn't buffers. Moreover, it should be
pointed out that this object is deprecated and only present for backwards
compatibility with previous versions of dlib. So you really should use the
sockstreambuf object instead.
INITIAL VALUE
con == a connection
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment