Skip to content

Commit c2c2e80

Browse files
committed
Fix up a cast and remove an unnecessary void * in win32 file streams.
1 parent 989d05c commit c2c2e80

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

Release/include/cpprest/filestream.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,10 @@ namespace details {
217217
return pplx::create_task(result_tce);
218218
}
219219

220-
// Use a separated function for working around Dev10's ICE
221-
pplx::task<void> _close_read_impl()
220+
pplx::task<void> _close_read()
222221
{
222+
return m_readOps.enqueue_operation([this]
223+
{
223224
streambuf_state_manager<_CharType>::_close_read();
224225

225226
if (this->can_write())
@@ -234,11 +235,7 @@ namespace details {
234235

235236
return _close_file(fileInfo);
236237
}
237-
}
238-
239-
pplx::task<void> _close_read()
240-
{
241-
return m_readOps.enqueue_operation([this] { return _close_read_impl(); });
238+
});
242239
}
243240

244241
pplx::task<void> _close_write()

Release/include/cpprest/producerconsumerstream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ namespace Concurrency { namespace streams {
391391
if ( m_blocks.empty() || m_blocks.back()->wr_chars_left() < count )
392392
{
393393
msl::safeint3::SafeInt<size_t> alloc = m_alloc_size.Max(count);
394-
m_blocks.push_back(std::make_shared<_block>((size_t)alloc));
394+
m_blocks.push_back(std::make_shared<_block>(alloc));
395395
}
396396

397397
// The block at the back is always the write head

Release/src/streams/fileio_win32.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ using namespace streams::details;
8484
/// </remarks>
8585
struct EXTENDED_OVERLAPPED : OVERLAPPED
8686
{
87-
EXTENDED_OVERLAPPED(LPOVERLAPPED_COMPLETION_ROUTINE func) : data(nullptr), func(func)
87+
EXTENDED_OVERLAPPED(LPOVERLAPPED_COMPLETION_ROUTINE func, streams::details::_filestream_callback *cb) : callback(cb), func(func)
8888
{
8989
ZeroMemory(this, sizeof(OVERLAPPED));
9090
}
9191

92-
void *data;
92+
streams::details::_filestream_callback *callback;
9393
LPOVERLAPPED_COMPLETION_ROUTINE func;
9494
};
9595

@@ -99,7 +99,7 @@ void CALLBACK IoCompletionCallback(
9999
DWORD dwNumberOfBytesTransfered,
100100
LPOVERLAPPED pOverlapped)
101101
{
102-
EXTENDED_OVERLAPPED *pExtOverlapped = (EXTENDED_OVERLAPPED *) pOverlapped;
102+
EXTENDED_OVERLAPPED *pExtOverlapped = static_cast<EXTENDED_OVERLAPPED *>(pOverlapped);
103103

104104
////If dwErrorCode is 0xc0000011, it means STATUS_END_OF_FILE.
105105
////Map this error code to system error code:ERROR_HANDLE_EOF
@@ -331,14 +331,13 @@ VOID CALLBACK _WriteFileCompletionRoutine(DWORD dwErrorCode, DWORD dwNumberOfByt
331331
{
332332
EXTENDED_OVERLAPPED* pOverlapped = static_cast<EXTENDED_OVERLAPPED *>(lpOverlapped);
333333

334-
auto callback = static_cast<streams::details::_filestream_callback *>(pOverlapped->data);
335334
if (dwErrorCode != ERROR_SUCCESS && dwErrorCode != ERROR_HANDLE_EOF)
336335
{
337-
callback->on_error(std::make_exception_ptr(utility::details::create_system_error(dwErrorCode)));
336+
pOverlapped->callback->on_error(std::make_exception_ptr(utility::details::create_system_error(dwErrorCode)));
338337
}
339338
else
340339
{
341-
callback->on_completed(static_cast<size_t>(dwNumberOfBytesTransfered));
340+
pOverlapped->callback->on_completed(static_cast<size_t>(dwNumberOfBytesTransfered));
342341
}
343342
}
344343

@@ -353,15 +352,13 @@ VOID CALLBACK _ReadFileCompletionRoutine(DWORD dwErrorCode, DWORD dwNumberOfByte
353352
{
354353
EXTENDED_OVERLAPPED* pOverlapped = static_cast<EXTENDED_OVERLAPPED *>(lpOverlapped);
355354

356-
auto callback = reinterpret_cast<streams::details::_filestream_callback *>(pOverlapped->data);
357-
358355
if (dwErrorCode != ERROR_SUCCESS && dwErrorCode != ERROR_HANDLE_EOF)
359356
{
360-
callback->on_error(std::make_exception_ptr(utility::details::create_system_error(dwErrorCode)));
357+
pOverlapped->callback->on_error(std::make_exception_ptr(utility::details::create_system_error(dwErrorCode)));
361358
}
362359
else
363360
{
364-
callback->on_completed(static_cast<size_t>(dwNumberOfBytesTransfered));
361+
pOverlapped->callback->on_completed(static_cast<size_t>(dwNumberOfBytesTransfered));
365362
}
366363
}
367364

@@ -375,7 +372,7 @@ VOID CALLBACK _ReadFileCompletionRoutine(DWORD dwErrorCode, DWORD dwNumberOfByte
375372
/// <returns>0 if the write request is still outstanding, -1 if the request failed, otherwise the size of the data written</returns>
376373
size_t _write_file_async(_In_ streams::details::_file_info_impl *fInfo, _In_ streams::details::_filestream_callback *callback, const void *ptr, size_t count, size_t position)
377374
{
378-
auto pOverlapped = new EXTENDED_OVERLAPPED(_WriteFileCompletionRoutine<streams::details::_file_info_impl>);
375+
auto pOverlapped = new EXTENDED_OVERLAPPED(_WriteFileCompletionRoutine<streams::details::_file_info_impl>, callback);
379376

380377
if (position == static_cast<size_t>(-1))
381378
{
@@ -392,8 +389,6 @@ size_t _write_file_async(_In_ streams::details::_file_info_impl *fInfo, _In_ str
392389
#endif
393390
}
394391

395-
pOverlapped->data = callback;
396-
397392
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
398393
StartThreadpoolIo(static_cast<PTP_IO>(fInfo->m_io_context));
399394

@@ -463,14 +458,13 @@ size_t _write_file_async(_In_ streams::details::_file_info_impl *fInfo, _In_ str
463458
/// <returns>0 if the read request is still outstanding, -1 if the request failed, otherwise the size of the data read into the buffer</returns>
464459
size_t _read_file_async(_In_ streams::details::_file_info_impl *fInfo, _In_ streams::details::_filestream_callback *callback, _Out_writes_ (count) void *ptr, _In_ size_t count, size_t offset)
465460
{
466-
auto pOverlapped = new EXTENDED_OVERLAPPED(_ReadFileCompletionRoutine<streams::details::_file_info_impl>);
461+
auto pOverlapped = new EXTENDED_OVERLAPPED(_ReadFileCompletionRoutine<streams::details::_file_info_impl>, callback);
467462
pOverlapped->Offset = static_cast<DWORD>(offset);
468463
#ifdef _WIN64
469464
pOverlapped->OffsetHigh = static_cast<DWORD>(offset >> 32);
470465
#else
471466
pOverlapped->OffsetHigh = 0;
472467
#endif
473-
pOverlapped->data = callback;
474468

475469
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
476470
StartThreadpoolIo((PTP_IO)fInfo->m_io_context);

0 commit comments

Comments
 (0)