Skip to content

Cannot create mixed block/nonblock wxDatagramSocket (e.g. wxSOCKET_NOWAIT_READ | wxSOCKET_WAITALL_WRITE) #17114

Closed

Description

@wxtrac

Issue migrated from trac ticket # 17114

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 used
1661	    // together.
1662	    wxASSERT_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

!( (flags & wxSOCKET_NOWAIT == wxSOCKET_NOWAIT) &&
   ((flags & wxSOCKET_WAITALL == wxSOCKET_WAITALL) ||
    (flags & wxSOCKET_BLOCK == wxSOCKET_BLOCK)) )

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.

Activity

  1. wxtrac commented on Aug 19, 2015

    @wxtrac
    CollaboratorAuthor

    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 _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.

  2. jherning commented on Jul 24, 2025

    @jherning

    I am also experiencing this issue when trying to set wxSOCKET_NOWAIT_READ | wxSOCKET_WAITALL_WRITE which should be possible, right?

  3. vadz commented on Jul 25, 2025

    @vadz
    Contributor

    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.

  4. jherning commented on Jul 25, 2025

    @jherning

    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.

  5. added a commit that references this issue on Jul 28, 2025
    943e4fb
  6. vadz commented on Jul 28, 2025

    @vadz
    Contributor

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions