Skip to content

Commit be51ee3

Browse files
committed
Merge branch 'development' of https://git01.codeplex.com/casablanca into development
2 parents 15804dc + e84daed commit be51ee3

File tree

4 files changed

+88
-5
lines changed

4 files changed

+88
-5
lines changed

Release/include/cpprest/astreambuf.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,15 @@ namespace Concurrency { namespace streams
418418
closeOp = _close_read();
419419
}
420420

421+
// After the flush_internal task completed, "this" object may have been destroyed,
422+
// accessing the memebers is invalid, use shared_from_this to avoid access violation exception.
423+
auto this_ptr = std::static_pointer_cast<streambuf_state_manager>(this->shared_from_this());
424+
421425
if (mode & std::ios_base::out && can_write()) {
422426
if (closeOp.is_done())
423-
closeOp = closeOp && _close_write(); // passing down exceptions from closeOp
427+
closeOp = closeOp && _close_write().then([this_ptr]{}); // passing down exceptions from closeOp
424428
else
425-
closeOp = closeOp.then([this] { return _close_write();});
429+
closeOp = closeOp.then([this_ptr] { return this_ptr->_close_write().then([this_ptr]{}); });
426430
}
427431

428432
return closeOp;

Release/include/cpprest/filestream.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,14 @@ namespace details {
112112
typedef typename basic_streambuf<_CharType>::off_type off_type;
113113

114114
virtual ~basic_file_buffer() {
115-
if( this->can_read() || this->can_write() ) {
116-
this->close().wait();
115+
if( this->can_read() )
116+
{
117+
this->_close_read().wait();
118+
}
119+
120+
if (this->can_write())
121+
{
122+
this->_close_write().wait();
117123
}
118124
}
119125
protected:

Release/nuget/cpprestsdk.autopkg

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ nuget {
6868
symbols:${BIN_DIR}Win32\Release\cpprest110_wp8_${VER_WUNDERSCORE}.pdb;
6969
lib:${BIN_DIR}Win32\Release\cpprest110_wp8_${VER_WUNDERSCORE}.lib;
7070
}
71-
71+
7272
// XP
7373
[x64,v110_xp,debug,desktop] {
7474
lib: ${BIN_DIR}x64\Debug\cpprest110d_xp_${VER_WUNDERSCORE}.lib;
@@ -93,6 +93,31 @@ nuget {
9393
symbols: ${BIN_DIR}Win32\Release\cpprest110_xp_${VER_WUNDERSCORE}.pdb;
9494
bin: ${X86_DLLS}cpprest110_xp_${VER_WUNDERSCORE}.dll;
9595
}
96+
97+
// XP vs2013
98+
[x64,v120_xp,debug,desktop] {
99+
lib: ${BIN_DIR}x64\Debug\cpprest120d_xp_${VER_WUNDERSCORE}.lib;
100+
symbols: ${BIN_DIR}x64\Debug\cpprest120d_xp_${VER_WUNDERSCORE}.pdb;
101+
bin: ${X64_DLLS}cpprest120d_xp_${VER_WUNDERSCORE}.dll;
102+
}
103+
104+
[x86,v120_xp,debug,desktop] {
105+
lib: ${BIN_DIR}Win32\Debug\cpprest120d_xp_${VER_WUNDERSCORE}.lib;
106+
symbols: ${BIN_DIR}Win32\Debug\cpprest120d_xp_${VER_WUNDERSCORE}.pdb;
107+
bin: ${X86_DLLS}cpprest120d_xp_${VER_WUNDERSCORE}.dll;
108+
}
109+
110+
[x64,v120_xp,release,desktop] {
111+
lib: ${BIN_DIR}x64\Release\cpprest120_xp_${VER_WUNDERSCORE}.lib;
112+
symbols: ${BIN_DIR}x64\Release\cpprest120_xp_${VER_WUNDERSCORE}.pdb;
113+
bin: ${X64_DLLS}cpprest120_xp_${VER_WUNDERSCORE}.dll;
114+
}
115+
116+
[x86,v120_xp,release,desktop] {
117+
lib: ${BIN_DIR}Win32\Release\cpprest120_xp_${VER_WUNDERSCORE}.lib;
118+
symbols: ${BIN_DIR}Win32\Release\cpprest120_xp_${VER_WUNDERSCORE}.pdb;
119+
bin: ${X86_DLLS}cpprest120_xp_${VER_WUNDERSCORE}.dll;
120+
}
96121

97122
[x64,v110,debug,desktop] {
98123
lib: ${BIN_DIR}x64\Debug\cpprest110d_${VER_WUNDERSCORE}.lib;

Release/tests/Functional/streams/fstreambuf_tests.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,54 @@ TEST(alloc_acquire_not_supported)
944944
VERIFY_IS_FALSE(file_buf.acquire(temp, size));
945945
}
946946

947+
TEST(read_alloc_acquire_not_supported)
948+
{
949+
auto file_buf1 = OPEN<char>(U("read_acquire_not_supported1.txt"), std::ios::out | std::ios::in).get();
950+
auto file_buf2 = OPEN<char>(U("read_acquire_not_supported2.txt"), std::ios::out | std::ios::in).get();
951+
952+
concurrency::streams::stringstreambuf data_buf("A");
953+
file_buf1.create_ostream().write(data_buf, 1).wait();
954+
file_buf1.sync().wait();
955+
file_buf2.create_ostream().write(file_buf1, 1).wait();
956+
file_buf2.sync().wait();
957+
958+
file_buf2.create_istream().read(file_buf1, 1).wait();
959+
file_buf1.sync().wait();
960+
file_buf1.seekpos(0, std::ios::in);
961+
data_buf = concurrency::streams::stringstreambuf();
962+
file_buf1.create_istream().read(data_buf, 2).wait();
963+
const auto &data = data_buf.collection();
964+
VERIFY_ARE_EQUAL(data[0], 'A');
965+
VERIFY_ARE_EQUAL(data[1], 'A');
966+
967+
file_buf1.close().wait();
968+
file_buf2.close().wait();
969+
}
970+
971+
TEST(winrt_filestream_close)
972+
{
973+
std::string str("test data");
974+
auto t = OPEN_W<uint8_t>(U("file.txt")).then(
975+
[this, str](concurrency::streams::ostream stream)
976+
{
977+
concurrency::streams::container_buffer<std::string> rbuf(str);
978+
concurrency::streams::istream is(rbuf);
979+
size_t size = 0;
980+
is.read(stream.streambuf(), 1).wait();
981+
while (!is.is_eof())
982+
{
983+
is.read(stream.streambuf(), 1).wait();
984+
size += 1;
985+
}
986+
987+
return stream.flush().then([size, stream](){
988+
stream.close();
989+
return size;
990+
});
991+
});
992+
993+
VERIFY_ARE_EQUAL(t.get(), str.length());
994+
}
947995
} // SUITE(file_buffer_tests)
948996

949997
}}}

0 commit comments

Comments
 (0)