X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a737331db68b754c8bf31fa0a15f6d1f207b40bf..4438caf41af49f00f3c8137ac801871f59cce386:/samples/wxsocket/server.cpp?ds=sidebyside diff --git a/samples/wxsocket/server.cpp b/samples/wxsocket/server.cpp index 45825d88fb..56f2dfc303 100644 --- a/samples/wxsocket/server.cpp +++ b/samples/wxsocket/server.cpp @@ -3,7 +3,7 @@ * Purpose: wxSocket: server demo * Author: LAVAUX Guilhem * Created: June 1997 - * Updated: + * CVS Id: $Id$ * Copyright: (C) 1997, LAVAUX Guilhem */ @@ -24,6 +24,7 @@ #endif #include "wx/socket.h" +#include "wx/thread.h" #if defined(__WXMOTIF__) || defined(__WXGTK__) #include "mondrian.xpm" @@ -97,6 +98,14 @@ extern wxList wxPendingDelete; void MyFrame::OnSockRequest(wxSocketEvent& evt) { + /* this routine gets called from within the + waiting socket thread, i.e. here we are + not in the main GUI thread and thus we + must not call any GUI function here. */ + /* Wrong ! This routine is called by the main GUI thread + because the main GUI thread received a signal from the other + thread using wxEvent::ProcessThreadEvent */ + wxSocketBase *sock = evt.Socket(); printf("OnSockRequest OK\n"); @@ -111,9 +120,9 @@ void MyFrame::OnSockRequest(wxSocketEvent& evt) break; case wxSocketBase::EVT_LOST: - UpdateStatus(-1); printf("Destroying socket\n"); wxPendingDelete.Append(sock); + UpdateStatus(-1); return; break; } @@ -123,20 +132,29 @@ void MyFrame::OnSockRequest(wxSocketEvent& evt) void MyFrame::OnSockRequestServer(wxSocketEvent& evt) { + /* this routine gets called from within the + waiting socket thread, i.e. here we are + not in the main GUI thread and thus we + must not call any GUI function here. */ + /* Wrong ! This routine is called by the main GUI thread + because the main GUI thread received a signal from the other + thread using wxEvent::ProcessThreadEvent */ + wxSocketBase *sock2; wxSocketServer *server = (wxSocketServer *) evt.Socket(); printf("OnSockRequestServer OK\n"); + printf("OnSockRequest (Main = %d) (event = %d)\n",wxThread::IsMain(), evt.SocketEvent()); sock2 = server->Accept(); if (sock2 == NULL) return; - sock2->SetFlags(wxSocketBase::NONE); + UpdateStatus(1); + sock2->SetFlags(wxSocketBase::SPEED); sock2->Notify(TRUE); sock2->SetEventHandler(*this, SKDEMO_SOCKET); server->SetNotify(wxSocketBase::REQ_ACCEPT); - UpdateStatus(1); } // My frame Constructor @@ -154,6 +172,7 @@ MyFrame::MyFrame(wxFrame *frame): wxSocketHandler::Master().Register(sock); sock->SetNotify(wxSocketBase::REQ_ACCEPT); sock->SetEventHandler(*this, SKDEMO_SOCKET_SERV); + sock->SetFlags(wxSocketBase::SPEED); sock->Notify(TRUE); nb_clients = 0;