You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
component: base | priority: normal | keywords: socket mixed nowait waitall blocking non-blocking
2015-08-19 22:18:15: mojomojomojo created the issue
I'm attempting to make a UDP socket that blocks on writes (send), but not on reads (recv). The documentation makes it sound like I should be able to do this.
Note that wxSOCKET_NOWAIT_READ impacts only Read operations and does not impact Write operations, allowing Read and Write operations to be set differently.
When I attempt to create the socket, the assert fails.
Socket = new wxDatagramSocket(LocalAddress, wxSOCKET_NOWAIT_READ | wxSOCKET_WAITALL_WRITE);
src/common/socket.cpp
1660// Do some sanity checking on the flags used: not all values can be used1661// together.1662wxASSERT_MSG( !(flags & wxSOCKET_NOWAIT) ||
1663 !(flags & (wxSOCKET_WAITALL | wxSOCKET_BLOCK)),
1664 "Using wxSOCKET_WAITALL or wxSOCKET_BLOCK with "
1665 "wxSOCKET_NOWAIT doesn't make sense" );
1666
It appears that these checks are not exactly correct. If we're supposed to be able to mix nowait/waitall between send/recv, then the checks should be something more like
Because the unidirectional nowait/waitall flags come up non-zero in the bitwise AND, mixing things like WAITALL_WRITE and NOWAIT_READ will cause the (current) assertion will fail. If this check is designed to keep users from mixing the bidirectional wait/nowait flags (wxSOCKET_NOWAIT and wxSOCKET_WAITALL, wxSOCKET_BLOCK), then the current assertion condition is not adequately checking for that exact condition.
flags & wxSOCKET_NOWAIT is non-zero if wxSOCKET_NOWAIT_READ is set, but flags & wxSOCKET_NOWAIT == wxSOCKET_NOWAIT is false, and it seems like this is the behavior described in the documentation.
The assert does seem to be wrong, thanks for noticing this (well, actually it used to be correct, but was broken by the patch adding _READ and _WRITE versions of the flags). We should rewrite it to check that wxSOCKET_NOWAIT_READ and wxSOCKET_WAITALL_READ are not specified together -- and the same thing for _WRITE versions, of course. If you could please make a test [HowToSubmitPatches patch] doing this, it would be gratefully applied.
It should be possible, I think, but wxSocket code is basically unmaintained and so I just don't know why it doesn't work. It looks like I had identified problem 10 years ago, but nobody bothered to make/test/submit a patch for fixing it — if you can do it, please do, I'd be glad to merge any PRs even if I have no plans of working on it myself as I don't use it.
Barring the assert, the code seems to be working for me. Since we agree it's not checking things right, can we just remove it for now? Separate issues could be created for actual problems with wxSockets. I created pull request #25662 to remove the assert (I think). Sorry if something is not right; not a pro here.
If the assert is really the only problem, it's simple to fix, of course, I didn't even realize it, sorry.
But removing it entirely doesn't seem like a good idea, because some flags are genuinely incompatible, so I'd rather apply #25665 -- could you please check that it fixes the problem for you too? TIA!
Activity
wxtrac commentedon Aug 19, 2015
2015-08-19 22:25:56: @vadz changed status from new to confirmed
2015-08-19 22:25:56: @vadz commented
The assert does seem to be wrong, thanks for noticing this (well, actually it used to be correct, but was broken by the patch adding
_READand_WRITEversions of the flags). We should rewrite it to check thatwxSOCKET_NOWAIT_READandwxSOCKET_WAITALL_READare not specified together -- and the same thing for_WRITEversions, of course. If you could please make a test [HowToSubmitPatches patch] doing this, it would be gratefully applied.jherning commentedon Jul 24, 2025
I am also experiencing this issue when trying to set wxSOCKET_NOWAIT_READ | wxSOCKET_WAITALL_WRITE which should be possible, right?
vadz commentedon Jul 25, 2025
It should be possible, I think, but wxSocket code is basically unmaintained and so I just don't know why it doesn't work. It looks like I had identified problem 10 years ago, but nobody bothered to make/test/submit a patch for fixing it — if you can do it, please do, I'd be glad to merge any PRs even if I have no plans of working on it myself as I don't use it.
jherning commentedon Jul 25, 2025
Barring the assert, the code seems to be working for me. Since we agree it's not checking things right, can we just remove it for now? Separate issues could be created for actual problems with wxSockets. I created pull request #25662 to remove the assert (I think). Sorry if something is not right; not a pro here.
Fix assert checking for wxSocket flags compatibility
vadz commentedon Jul 28, 2025
If the assert is really the only problem, it's simple to fix, of course, I didn't even realize it, sorry.
But removing it entirely doesn't seem like a good idea, because some flags are genuinely incompatible, so I'd rather apply #25665 -- could you please check that it fixes the problem for you too? TIA!
Fix assert checking for wxSocket flags compatibility