Commit d2b9f8f0 authored by Davis King's avatar Davis King

To work around a bug in visual studio 2012, I changed the iosockstream from using

iostream::tie() to implement its "auto flush on read" feature to use the sockstreambuf's
own auto flushing mode instead.
parent e4549f7b
......@@ -10,11 +10,12 @@
#include "../smart_pointers_thread_safe.h"
#include "../timeout.h"
#ifdef _MSC_VER
// Disable the warning about inheriting from std::iostream 'via dominance' since this warning is a warning about
// visual studio conforming to the standard and is ignorable. See http://connect.microsoft.com/VisualStudio/feedback/details/733720/inheriting-from-std-fstream-produces-c4250-warning
// for further details if interested.
#pragma warning(disable : 4250)
#ifdef _MSC_VER
// Disable the warning about inheriting from std::iostream 'via dominance' since this warning is a warning about
// visual studio conforming to the standard and is ignorable.
// See http://connect.microsoft.com/VisualStudio/feedback/details/733720/inheriting-from-std-fstream-produces-c4250-warning
// for further details if interested.
#pragma warning(disable : 4250)
#endif // _MSC_VER
namespace dlib
......@@ -30,7 +31,6 @@ namespace dlib
) :
std::iostream(0)
{
tie(this);
}
iosockstream(
......@@ -38,7 +38,6 @@ namespace dlib
) :
std::iostream(0)
{
tie(this);
open(addr);
}
......@@ -48,7 +47,6 @@ namespace dlib
) :
std::iostream(0)
{
tie(this);
open(addr, timeout);
}
......@@ -64,6 +62,14 @@ namespace dlib
close();
con.reset(connect(addr));
buf.reset(new sockstreambuf(con.get()));
// Note that we use the sockstreambuf's ability to autoflush instead of
// telling the iostream::tie() function to tie the stream to itself even though
// that should work fine. The reason we do it this way is because there is a
// bug in visual studio 2012 that causes a program to crash when a stream is
// tied to itself and then used. See
// http://connect.microsoft.com/VisualStudio/feedback/details/772293/tying-a-c-iostream-object-to-itself-causes-a-stack-overflow-in-visual-studio-2012
// for further details.
buf->flush_output_on_read();
rdbuf(buf.get());
clear();
}
......@@ -76,6 +82,7 @@ namespace dlib
close(timeout);
con.reset(connect(addr.host_address, addr.port, timeout));
buf.reset(new sockstreambuf(con.get()));
buf->flush_output_on_read();
rdbuf(buf.get());
clear();
}
......
......@@ -18,6 +18,9 @@ namespace dlib
WHAT THIS OBJECT REPRESENTS
This is an iostream object that reads/writes from a TCP network connection.
Note that any attempt to read from this stream will automatically flush the
stream's output buffers.
THREAD SAFETY
It is not safe to touch this object from more than one thread at a time.
Therefore, you should mutex lock it if you need to do so.
......@@ -30,9 +33,6 @@ namespace dlib
/*!
ensures
- #good() == false
- #tie() == this
(i.e. Any attempt to read from this stream will automatically flush the
stream's output buffers)
!*/
iosockstream(
......@@ -40,9 +40,6 @@ namespace dlib
);
/*!
ensures
- #tie() == this
(i.e. Any attempt to read from this stream will automatically flush the
stream's output buffers)
- Attempts to connect to the given network address.
- Calling this constructor is equivalent to calling the default constructor
and then invoking open(addr).
......@@ -59,9 +56,6 @@ namespace dlib
);
/*!
ensures
- #tie() == this
(i.e. Any attempt to read from this stream will automatically flush the
stream's output buffers)
- Attempts to connect to the given network address.
- Calling this constructor is equivalent to calling the default constructor
and then invoking open(addr, timeout).
......
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