Ticket #11107 (closed defect: fixed)

Opened 7 months ago

Last modified 7 months ago

wxSocketServer::WaitForAccept not waiting for incoming connections

Reported by: D39 Owned by: vadz
Priority: normal Milestone: 2.9.1
Component: network Version: 2.9-svn
Keywords: WaitForAccept Cc:
Blocked By: Patch: no
Blocking:

Description

i created wxSocketServer and bring him to wait for incoming connection with WaitForAccept(10).
but it returns immediately, without waiting, because there inside exist checking, which always false on my case...
as i think, this should work for wxSocketServer :)

wxSocketBase::DoWait(long timeout, wxSocketEventFlags flags)
{
    wxCHECK_MSG( m_impl, -1, "can't wait on invalid socket" );

    // we're never going to become ready if we're not connected (any more)
    '''if ( !m_connected && !m_establishing )
        return -1;'''

i using svn version with VS2008

Change History

follow-up: ↓ 2   Changed 7 months ago by vadz

  • owner set to vadz
  • status changed from new to accepted
  • milestone set to 2.9.1

Yes, this is clearly wrong, sorry, this check doesn't make sense for a server. I think it should be enough to add a check for !m_server here but it would be great to have a way to test it. Would it be possible for you to make a patch to the sockets sample exposing the problem? This would allow me to fix it much faster.

TIA!

in reply to: ↑ 1   Changed 7 months ago by D39

Replying to vadz:

Would it be possible for you to make a patch to the sockets sample exposing the problem? This would allow me to fix it much faster.

there is patch for sockets sample:

Index: server.cpp
===================================================================
--- server.cpp	(revision 61671)
+++ server.cpp	(working copy)
@@ -150,6 +150,12 @@
 
 bool MyApp::OnInit()
 {
+	wxIPV4address addr; 
+	addr.Service(1234);
+	addr.Hostname("localhost");
+	wxSocketServer server(addr, wxSOCKET_REUSEADDR);
+	server.WaitForAccept(10, 0); // there should be freeze for 10 sec
+
   if ( !wxApp::OnInit() )
       return false;

  Changed 7 months ago by D39

i found way to live without this function, just:

SetTimeout(10);
Accept(true);

producing same result :)

  Changed 7 months ago by VZ

  • status changed from accepted to closed
  • resolution set to fixed

(In [61726]) Do wait for connection in the server socket.

The code returned immediately from wxSocketBase::DoWait() if it wasn't
connected but it only made sense for the client sockets, not server ones which
could be calling this function precisely in order to wait until a connection
is made.

Also added a test for this bug in the sockets/server sample.

Closes #11107.

  Changed 7 months ago by VZ

(In [61734]) Back port of wxSocket-related fixes from trunk.

This patch combines the changes from the following trunk revisions:

It refactors wxSocketImpl creation to use a Mac-specific version of it in GUI
Mac applications which fixes generation of socket events under Mac (see #11030)
and also fixes bug in wxSocketServer::WaitForAccept() (see #11107).

Note: See TracTickets for help on using tickets.