From 6b3eb77aece0708b6c9dd0c58bd2b4408e4fac9d Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 22 May 1999 10:11:03 +0000 Subject: [PATCH] Played a little with sockets. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2539 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/app.h | 2 ++ include/wx/gtk1/app.h | 2 ++ samples/wxsocket/client.cpp | 1 + samples/wxsocket/server.cpp | 14 ++++++++++++-- src/common/event.cpp | 4 ++-- src/gtk/app.cpp | 7 ++++++- src/gtk1/app.cpp | 7 ++++++- 7 files changed, 31 insertions(+), 6 deletions(-) diff --git a/include/wx/gtk/app.h b/include/wx/gtk/app.h index 958c8a39ae..03b53e2440 100644 --- a/include/wx/gtk/app.h +++ b/include/wx/gtk/app.h @@ -130,7 +130,9 @@ class wxApp: public wxEvtHandler wxWindow *m_topWindow; gint m_idleTag; +#if wxUSE_THREADS gint m_wakeUpTimerTag; +#endif unsigned char *m_colorCube; int argc; diff --git a/include/wx/gtk1/app.h b/include/wx/gtk1/app.h index 958c8a39ae..03b53e2440 100644 --- a/include/wx/gtk1/app.h +++ b/include/wx/gtk1/app.h @@ -130,7 +130,9 @@ class wxApp: public wxEvtHandler wxWindow *m_topWindow; gint m_idleTag; +#if wxUSE_THREADS gint m_wakeUpTimerTag; +#endif unsigned char *m_colorCube; int argc; diff --git a/samples/wxsocket/client.cpp b/samples/wxsocket/client.cpp index ffb17c4de8..6a163e47f7 100644 --- a/samples/wxsocket/client.cpp +++ b/samples/wxsocket/client.cpp @@ -27,6 +27,7 @@ #include "wx/socket.h" #include "wx/url.h" #include "wx/protocol/http.h" +#include "wx/thread.h" #if defined(__WXMOTIF__) || defined(__WXGTK__) #include "mondrian.xpm" diff --git a/samples/wxsocket/server.cpp b/samples/wxsocket/server.cpp index 727c8e63a8..5a380483ac 100644 --- a/samples/wxsocket/server.cpp +++ b/samples/wxsocket/server.cpp @@ -24,6 +24,7 @@ #endif #include "wx/socket.h" +#include "wx/thread.h" #if defined(__WXMOTIF__) || defined(__WXGTK__) #include "mondrian.xpm" @@ -97,6 +98,11 @@ 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. */ + wxSocketBase *sock = evt.Socket(); printf("OnSockRequest OK\n"); @@ -111,7 +117,6 @@ void MyFrame::OnSockRequest(wxSocketEvent& evt) break; case wxSocketBase::EVT_LOST: - UpdateStatus(-1); printf("Destroying socket\n"); wxPendingDelete.Append(sock); return; @@ -123,10 +128,16 @@ 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. */ + wxSocketBase *sock2; wxSocketServer *server = (wxSocketServer *) evt.Socket(); printf("OnSockRequestServer OK\n"); + printf("OnSockRequest (event = %d)\n",evt.SocketEvent()); sock2 = server->Accept(); if (sock2 == NULL) @@ -136,7 +147,6 @@ void MyFrame::OnSockRequestServer(wxSocketEvent& evt) sock2->Notify(TRUE); sock2->SetEventHandler(*this, SKDEMO_SOCKET); server->SetNotify(wxSocketBase::REQ_ACCEPT); - UpdateStatus(1); } // My frame Constructor diff --git a/src/common/event.cpp b/src/common/event.cpp index 0c2e5f813c..5dcfadf76c 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -530,7 +530,6 @@ wxEvtHandler::~wxEvtHandler() #ifdef __WXGTK__ extern bool g_isIdle; - extern void wxapp_install_idle_handler(); #endif @@ -554,7 +553,8 @@ bool wxEvtHandler::ProcessThreadEvent(wxEvent& event) wxPendingEventsLocker->Leave(); #ifdef __WXGTK__ -// if (g_isIdle) wxapp_install_idle_handler(); + if (g_isIdle) + wxapp_install_idle_handler(); #endif return TRUE; diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index bf7a03b90e..a456ed86aa 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -215,7 +215,7 @@ void wxapp_install_idle_handler() g_isIdle = FALSE; } - +#if wxUSE_THREADS static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) ) { gtk_timeout_remove( wxTheApp->m_wakeUpTimerTag ); @@ -242,6 +242,7 @@ static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) ) return TRUE; } +#endif //----------------------------------------------------------------------------- // wxApp @@ -262,7 +263,9 @@ wxApp::wxApp() m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL ); +#if wxUSE_THREADS m_wakeUpTimerTag = gtk_timeout_add( 10, wxapp_wakeup_timerout_callback, (gpointer) NULL ); +#endif m_colorCube = (unsigned char*) NULL; } @@ -271,7 +274,9 @@ wxApp::~wxApp() { if (m_idleTag) gtk_idle_remove( m_idleTag ); +#if wxUSE_THREADS if (m_wakeUpTimerTag) gtk_timeout_remove( m_wakeUpTimerTag ); +#endif if (m_colorCube) free(m_colorCube); } diff --git a/src/gtk1/app.cpp b/src/gtk1/app.cpp index bf7a03b90e..a456ed86aa 100644 --- a/src/gtk1/app.cpp +++ b/src/gtk1/app.cpp @@ -215,7 +215,7 @@ void wxapp_install_idle_handler() g_isIdle = FALSE; } - +#if wxUSE_THREADS static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) ) { gtk_timeout_remove( wxTheApp->m_wakeUpTimerTag ); @@ -242,6 +242,7 @@ static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) ) return TRUE; } +#endif //----------------------------------------------------------------------------- // wxApp @@ -262,7 +263,9 @@ wxApp::wxApp() m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL ); +#if wxUSE_THREADS m_wakeUpTimerTag = gtk_timeout_add( 10, wxapp_wakeup_timerout_callback, (gpointer) NULL ); +#endif m_colorCube = (unsigned char*) NULL; } @@ -271,7 +274,9 @@ wxApp::~wxApp() { if (m_idleTag) gtk_idle_remove( m_idleTag ); +#if wxUSE_THREADS if (m_wakeUpTimerTag) gtk_timeout_remove( m_wakeUpTimerTag ); +#endif if (m_colorCube) free(m_colorCube); } -- 2.45.2