Skip to content

Commit 0fc7329

Browse files
committed
Added error when an ostream runs out of space
1 parent 2e8e215 commit 0fc7329

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

Release/include/cpprest/interopstream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ namespace Concurrency { namespace streams {
104104
virtual size_t buffer_size(std::ios_base::openmode direction = std::ios_base::in) const { return 0; }
105105
virtual void set_buffer_size(size_t size, std::ios_base::openmode direction = std::ios_base::in) { return; }
106106

107-
virtual pplx::task<bool> _sync() { return pplx::task_from_result(m_buffer->pubsync() != std::char_traits<_CharType>::eof()); }
107+
virtual pplx::task<bool> _sync() { return pplx::task_from_result(m_buffer->pubsync() == 0); }
108108

109109
virtual pplx::task<int_type> _putc(_CharType ch) { return pplx::task_from_result(m_buffer->sputc(ch)); }
110110
virtual pplx::task<size_t> _putn(const _CharType *ptr, size_t size) { return pplx::task_from_result((size_t)m_buffer->sputn(ptr, size)); }

Release/include/cpprest/streams.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,21 +1123,20 @@ namespace Concurrency { namespace streams
11231123
auto locs = _locals;
11241124
auto trg = _target;
11251125

1126-
auto after_putn =
1127-
[=](size_t wr) mutable -> bool
1126+
return _buffer.getn(locs->outbuf, buf_size).then([=](size_t rd) mutable -> pplx::task<bool>
11281127
{
1129-
locs->total += wr;
1130-
trg.sync().wait();
1131-
return true;
1132-
};
1133-
1134-
return _buffer.getn(locs->outbuf, buf_size).then(
1135-
[=] (size_t rd) mutable -> pplx::task<bool>
1136-
{
1137-
if ( rd == 0 )
1138-
return pplx::task_from_result(false);
1139-
return trg.putn(locs->outbuf, rd).then(after_putn);
1140-
});
1128+
if ( rd == 0 )
1129+
return pplx::task_from_result(false);
1130+
return trg.putn(locs->outbuf, rd).then([=](size_t wr) mutable -> bool
1131+
{
1132+
locs->total += wr;
1133+
trg.sync().wait();
1134+
if (rd != wr)
1135+
// Number of bytes written is less than number of bytes received.
1136+
throw std::runtime_error("failed to write all bytes");
1137+
return true;
1138+
});
1139+
});
11411140
}
11421141
private:
11431142
size_t _buf_size;

0 commit comments

Comments
 (0)