#include #include #include #include class SocketTestApp : public wxAppConsole { public: virtual int OnRun(); }; DECLARE_APP( SocketTestApp ) IMPLEMENT_APP( SocketTestApp ) class SocketThread : public wxThread { public: SocketThread( wxSocketBase* socket ); virtual void* Entry(); private: wxSocketBase* m_socket; }; SocketThread::SocketThread( wxSocketBase* socket ) { m_socket = socket; m_socket->SetFlags( wxSOCKET_WAITALL ); m_socket->SetTimeout( 15 ); } void* SocketThread::Entry() { while( m_socket->IsConnected()) { std::cout << "Thread - Calling WaitForRead()...\n" << std::flush; if( m_socket->WaitForRead()) { std::cout << "Thread - WaitForRead() returned true\n"; }else { std::cout << "Thread - WaitForRead() returned false\n"; } } } int SocketTestApp::OnRun() { wxSocketBase::Initialize(); wxIPV4address addy; addy.AnyAddress(); addy.Service( 3000 ); wxSocketServer* ss = new wxSocketServer( addy, wxSOCKET_WAITALL ); std::cout << "Main - Waiting for connection...\n" << std::flush; wxSocketBase* test_socket = ss->Accept( true ); std::cout << "Main - Connection made. Creating thread...\n" << std::flush; SocketThread* st = new SocketThread( test_socket ); st->Create(); st->Run(); wxSleep( 1 ); std::cout << "Main - Thread is running, should timeout in 15 seconds. Calling InterruptWait()...\n" << std::flush; test_socket->InterruptWait(); std::cout << "Main - Call to InterruptWait() has returned. Spinning...\n" << std::flush; while(1) { wxSleep( 1 ); } }