Ticket #14506 (closed enhancement: fixed)
wxSocketBase.LastCount() and thread-safety
| Reported by: | mar | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | network | Version: | |
| Keywords: | wxSocketBase wxDatagramSocket LastCount thread-safety | Cc: | |
| Blocked By: | Patch: | no | |
| Blocking: |
Description
Assume the following scenario:
A blocking socket keeps reading in a background thread,
while it's possible to send from another thread on the same socket.
The only way (AFAIK) to get received count is by calling LastCount()
on a socket. The problem is that m_lcount is also set by Write.
It can happen that another thread modifies m_lcount before the read thread
calls LastCount().
I encountered crashes when using wxDataGramSocket in such scenario.
The workround is to use a nonblocking socket,
sleep in the read thread and encapsulate all SendTo/RecvFrom calls with a mutex,
which is certainly a bad solution.
I believe this is a design problem and Recv/Read should return read count instead of ref to socket. The same for Send/Write.

