Played a little with sockets.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2539 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -130,7 +130,9 @@ class wxApp: public wxEvtHandler
|
|||||||
wxWindow *m_topWindow;
|
wxWindow *m_topWindow;
|
||||||
|
|
||||||
gint m_idleTag;
|
gint m_idleTag;
|
||||||
|
#if wxUSE_THREADS
|
||||||
gint m_wakeUpTimerTag;
|
gint m_wakeUpTimerTag;
|
||||||
|
#endif
|
||||||
unsigned char *m_colorCube;
|
unsigned char *m_colorCube;
|
||||||
|
|
||||||
int argc;
|
int argc;
|
||||||
|
@@ -130,7 +130,9 @@ class wxApp: public wxEvtHandler
|
|||||||
wxWindow *m_topWindow;
|
wxWindow *m_topWindow;
|
||||||
|
|
||||||
gint m_idleTag;
|
gint m_idleTag;
|
||||||
|
#if wxUSE_THREADS
|
||||||
gint m_wakeUpTimerTag;
|
gint m_wakeUpTimerTag;
|
||||||
|
#endif
|
||||||
unsigned char *m_colorCube;
|
unsigned char *m_colorCube;
|
||||||
|
|
||||||
int argc;
|
int argc;
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include "wx/socket.h"
|
#include "wx/socket.h"
|
||||||
#include "wx/url.h"
|
#include "wx/url.h"
|
||||||
#include "wx/protocol/http.h"
|
#include "wx/protocol/http.h"
|
||||||
|
#include "wx/thread.h"
|
||||||
|
|
||||||
#if defined(__WXMOTIF__) || defined(__WXGTK__)
|
#if defined(__WXMOTIF__) || defined(__WXGTK__)
|
||||||
#include "mondrian.xpm"
|
#include "mondrian.xpm"
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/socket.h"
|
#include "wx/socket.h"
|
||||||
|
#include "wx/thread.h"
|
||||||
|
|
||||||
#if defined(__WXMOTIF__) || defined(__WXGTK__)
|
#if defined(__WXMOTIF__) || defined(__WXGTK__)
|
||||||
#include "mondrian.xpm"
|
#include "mondrian.xpm"
|
||||||
@@ -97,6 +98,11 @@ extern wxList wxPendingDelete;
|
|||||||
|
|
||||||
void MyFrame::OnSockRequest(wxSocketEvent& evt)
|
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();
|
wxSocketBase *sock = evt.Socket();
|
||||||
|
|
||||||
printf("OnSockRequest OK\n");
|
printf("OnSockRequest OK\n");
|
||||||
@@ -111,7 +117,6 @@ void MyFrame::OnSockRequest(wxSocketEvent& evt)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case wxSocketBase::EVT_LOST:
|
case wxSocketBase::EVT_LOST:
|
||||||
UpdateStatus(-1);
|
|
||||||
printf("Destroying socket\n");
|
printf("Destroying socket\n");
|
||||||
wxPendingDelete.Append(sock);
|
wxPendingDelete.Append(sock);
|
||||||
return;
|
return;
|
||||||
@@ -123,10 +128,16 @@ void MyFrame::OnSockRequest(wxSocketEvent& evt)
|
|||||||
|
|
||||||
void MyFrame::OnSockRequestServer(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;
|
wxSocketBase *sock2;
|
||||||
wxSocketServer *server = (wxSocketServer *) evt.Socket();
|
wxSocketServer *server = (wxSocketServer *) evt.Socket();
|
||||||
|
|
||||||
printf("OnSockRequestServer OK\n");
|
printf("OnSockRequestServer OK\n");
|
||||||
|
printf("OnSockRequest (event = %d)\n",evt.SocketEvent());
|
||||||
|
|
||||||
sock2 = server->Accept();
|
sock2 = server->Accept();
|
||||||
if (sock2 == NULL)
|
if (sock2 == NULL)
|
||||||
@@ -136,7 +147,6 @@ void MyFrame::OnSockRequestServer(wxSocketEvent& evt)
|
|||||||
sock2->Notify(TRUE);
|
sock2->Notify(TRUE);
|
||||||
sock2->SetEventHandler(*this, SKDEMO_SOCKET);
|
sock2->SetEventHandler(*this, SKDEMO_SOCKET);
|
||||||
server->SetNotify(wxSocketBase::REQ_ACCEPT);
|
server->SetNotify(wxSocketBase::REQ_ACCEPT);
|
||||||
UpdateStatus(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// My frame Constructor
|
// My frame Constructor
|
||||||
|
@@ -530,7 +530,6 @@ wxEvtHandler::~wxEvtHandler()
|
|||||||
|
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
extern bool g_isIdle;
|
extern bool g_isIdle;
|
||||||
|
|
||||||
extern void wxapp_install_idle_handler();
|
extern void wxapp_install_idle_handler();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -554,7 +553,8 @@ bool wxEvtHandler::ProcessThreadEvent(wxEvent& event)
|
|||||||
wxPendingEventsLocker->Leave();
|
wxPendingEventsLocker->Leave();
|
||||||
|
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
// if (g_isIdle) wxapp_install_idle_handler();
|
if (g_isIdle)
|
||||||
|
wxapp_install_idle_handler();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@@ -215,7 +215,7 @@ void wxapp_install_idle_handler()
|
|||||||
g_isIdle = FALSE;
|
g_isIdle = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if wxUSE_THREADS
|
||||||
static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) )
|
static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) )
|
||||||
{
|
{
|
||||||
gtk_timeout_remove( wxTheApp->m_wakeUpTimerTag );
|
gtk_timeout_remove( wxTheApp->m_wakeUpTimerTag );
|
||||||
@@ -242,6 +242,7 @@ static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) )
|
|||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxApp
|
// wxApp
|
||||||
@@ -262,7 +263,9 @@ wxApp::wxApp()
|
|||||||
|
|
||||||
m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL );
|
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 );
|
m_wakeUpTimerTag = gtk_timeout_add( 10, wxapp_wakeup_timerout_callback, (gpointer) NULL );
|
||||||
|
#endif
|
||||||
|
|
||||||
m_colorCube = (unsigned char*) NULL;
|
m_colorCube = (unsigned char*) NULL;
|
||||||
}
|
}
|
||||||
@@ -271,7 +274,9 @@ wxApp::~wxApp()
|
|||||||
{
|
{
|
||||||
if (m_idleTag) gtk_idle_remove( m_idleTag );
|
if (m_idleTag) gtk_idle_remove( m_idleTag );
|
||||||
|
|
||||||
|
#if wxUSE_THREADS
|
||||||
if (m_wakeUpTimerTag) gtk_timeout_remove( m_wakeUpTimerTag );
|
if (m_wakeUpTimerTag) gtk_timeout_remove( m_wakeUpTimerTag );
|
||||||
|
#endif
|
||||||
|
|
||||||
if (m_colorCube) free(m_colorCube);
|
if (m_colorCube) free(m_colorCube);
|
||||||
}
|
}
|
||||||
|
@@ -215,7 +215,7 @@ void wxapp_install_idle_handler()
|
|||||||
g_isIdle = FALSE;
|
g_isIdle = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if wxUSE_THREADS
|
||||||
static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) )
|
static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) )
|
||||||
{
|
{
|
||||||
gtk_timeout_remove( wxTheApp->m_wakeUpTimerTag );
|
gtk_timeout_remove( wxTheApp->m_wakeUpTimerTag );
|
||||||
@@ -242,6 +242,7 @@ static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) )
|
|||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxApp
|
// wxApp
|
||||||
@@ -262,7 +263,9 @@ wxApp::wxApp()
|
|||||||
|
|
||||||
m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL );
|
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 );
|
m_wakeUpTimerTag = gtk_timeout_add( 10, wxapp_wakeup_timerout_callback, (gpointer) NULL );
|
||||||
|
#endif
|
||||||
|
|
||||||
m_colorCube = (unsigned char*) NULL;
|
m_colorCube = (unsigned char*) NULL;
|
||||||
}
|
}
|
||||||
@@ -271,7 +274,9 @@ wxApp::~wxApp()
|
|||||||
{
|
{
|
||||||
if (m_idleTag) gtk_idle_remove( m_idleTag );
|
if (m_idleTag) gtk_idle_remove( m_idleTag );
|
||||||
|
|
||||||
|
#if wxUSE_THREADS
|
||||||
if (m_wakeUpTimerTag) gtk_timeout_remove( m_wakeUpTimerTag );
|
if (m_wakeUpTimerTag) gtk_timeout_remove( m_wakeUpTimerTag );
|
||||||
|
#endif
|
||||||
|
|
||||||
if (m_colorCube) free(m_colorCube);
|
if (m_colorCube) free(m_colorCube);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user