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
This commit is contained in:
Vadim Zeitlin
2018-03-25 14:07:22 +02:00
parent 79170994fc
commit 6b859ce330
2 changed files with 3 additions and 2 deletions

View File

@@ -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:

View File

@@ -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