From 6b859ce330180d373c7c3f2197fdc3e2c60f4dd4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 25 Mar 2018 14:07:22 +0200 Subject: [PATCH] Use Last[Read/Write]Count() in socket stream operations Using LastRead() was MT-unsafe when the same socket was used for both writing and reading from different threads. It's not clear if this change is sufficient to make wxSocket fully MT-safe in this scenario, but it does help and there should be no negative effects from doing this. Closes #17787. Closes https://github.com/wxWidgets/wxWidgets/pull/761 --- docs/changes.txt | 1 + src/common/sckstrm.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index d2b8473fc8..f69b03c2d3 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -70,6 +70,7 @@ Changes in behaviour which may result in build errors All: - Make wxList and wxVector iterators conform to input iterator requirements. +- Fix MT-safety problem when reading and writing from wxSocket (jkubalik). wxGTK: diff --git a/src/common/sckstrm.cpp b/src/common/sckstrm.cpp index 8f64727d78..6146be5214 100644 --- a/src/common/sckstrm.cpp +++ b/src/common/sckstrm.cpp @@ -40,7 +40,7 @@ wxSocketOutputStream::~wxSocketOutputStream() size_t wxSocketOutputStream::OnSysWrite(const void *buffer, size_t size) { - const size_t ret = m_o_socket->Write(buffer, size).LastCount(); + const size_t ret = m_o_socket->Write(buffer, size).LastWriteCount(); m_lasterror = m_o_socket->Error() ? m_o_socket->IsClosed() ? wxSTREAM_EOF : wxSTREAM_WRITE_ERROR @@ -63,7 +63,7 @@ wxSocketInputStream::~wxSocketInputStream() size_t wxSocketInputStream::OnSysRead(void *buffer, size_t size) { - const size_t ret = m_i_socket->Read(buffer, size).LastCount(); + const size_t ret = m_i_socket->Read(buffer, size).LastReadCount(); m_lasterror = m_i_socket->Error() ? m_i_socket->IsClosed() ? wxSTREAM_EOF : wxSTREAM_READ_ERROR