Creating Socket in secondary thread confusion Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Creating Socket in secondary thread confusion

Post by evstevemd »

I'm creating wxSocketClient instance and I use block mode as advised

Code: Select all

    m_socket = new wxSocketClient(wxSOCKET_BLOCK|wxSOCKET_WAITALL);
    m_socket->Notify(false); //disables socket events

    wxIPV4address addr;
    addr.AnyAddress();
    addr.Service(port);

    if(m_socket->Connect(addr, true))
    {
        wxPuts(wxString::Format("Connected to port %d", port));
    }
But I get error:
../src/common/socket.cpp(1984): assert "(flags & wxSOCKET_BLOCK) || wxIsMainThread()" failed in wxSocketClient(): Non-blocking sockets may only be created in the main thread [in thread 70000611d000]
Since thread is already in blocked mode I wonder what is going on. Can someone help me understand why is it complaining that?

Here is a relevant callstack

Call stack:
[01] wxSocketClient::wxSocketClient(int) socket.cpp:1982
[02] wxSocketClient::wxSocketClient(int) socket.cpp:1988
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: Creating Socket in secondary thread confusion

Post by Kvaz1r »

Code looks ok for me. Can you provide MCVE for reproducing the behaviour?

Edit:

The documentation said one must call Initialize/0 when use wxSocket from multiple threads:
Can it be problem?
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Creating Socket in secondary thread confusion

Post by evstevemd »

Hi,
Kvaz1r wrote: Thu Jul 18, 2019 7:41 am Code looks ok for me. Can you provide MCVE for reproducing the behaviour?
I have been puzzled for quiet long time only to find I was modifying a copy of source files not the one in project so I was actually changing nothing on actual code I was compiling. Stupid error indeed! :oops:
It is initialized already in app's OnInit

Thanks for the comment. I have fixed it
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Post Reply