wxSocketBase.LastCount() and thread-safety
|Reported by:||mar||Owned by:|
|Keywords:||wxSocketBase wxDatagramSocket LastCount thread-safety||Cc:|
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
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.
Change History (9)
comment:2 in reply to: ↑ 1 Changed 21 months ago by mar
- Resolution set to wontfix
- Status changed from new to closed
comment:3 Changed 19 months ago by rowbearto
- Resolution wontfix deleted
- Status changed from closed to reopened
- Type changed from defect to enhancement
Changed 19 months ago by rowbearto
comment:7 Changed 19 months ago by VZ
- Resolution set to fixed
- Status changed from reopened to closed