X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2804f77d88eb478f85a281b19d87e38cd96e0d0c..89b3361ec25cf1e6d255b14c7633d8375646e4fb:/samples/sockets/baseclient.cpp diff --git a/samples/sockets/baseclient.cpp b/samples/sockets/baseclient.cpp index f9ce6c6f9a..b7a84d492a 100644 --- a/samples/sockets/baseclient.cpp +++ b/samples/sockets/baseclient.cpp @@ -6,7 +6,7 @@ // Created: 27.06.2005 // RCS-ID: $Id$ // Copyright: (c) 2005 Lukasz Michalski -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -72,7 +72,7 @@ WX_DECLARE_LIST(ThreadWorker, TList); WX_DECLARE_LIST(EventWorker, EList); class Client : public wxApp { - DECLARE_EVENT_TABLE(); + DECLARE_EVENT_TABLE() public: void RemoveEventWorker(EventWorker* p_worker); private: @@ -141,7 +141,7 @@ private: class EventWorker : public wxEvtHandler { - DECLARE_EVENT_TABLE(); + DECLARE_EVENT_TABLE() public: EventWorker(const wxString& p_host, char* p_buf, int p_size); void Run(); @@ -254,13 +254,14 @@ Client::OnInit() int Client::OnRun() { + int i; switch(m_sendType) { case STRESS_TEST: switch(m_workMode) { case THREADS: - for (int i = 0; i < m_stressWorkers; i++) { + for (i = 0; i < m_stressWorkers; i++) { if (m_message.empty()) StartWorker(THREADS); else @@ -268,7 +269,7 @@ Client::OnRun() } break; case EVENTS: - for (int i = 0; i < m_stressWorkers; i++) { + for (i = 0; i < m_stressWorkers; i++) { if (m_message.empty()) StartWorker(EVENTS); else @@ -276,7 +277,7 @@ Client::OnRun() } break; default: - for (int i = 0; i < m_stressWorkers; i++) { + for (i = 0; i < m_stressWorkers; i++) { if (m_message.empty()) StartWorker(i % 5 == 0 ? THREADS : EVENTS); else @@ -305,9 +306,9 @@ Client::OnExit() return 0; } -// Create buffer to be sent by client. Buffer contains test indicator +// Create buffer to be sent by client. Buffer contains test indicator // message size and place for data -// msgsize parameter contains size of data in bytes and +// msgsize parameter contains size of data in bytes and // if input value does not fit into 250 bytes then // on exit is updated to new value that is multiply of 1024 bytes char* @@ -317,14 +318,14 @@ Client::CreateBuffer(int* msgsize) char* buf; //if message should have more than 256 bytes then set it as //test3 for compatibility with GUI server sample - if ((*msgsize) > 250) + if ((*msgsize) > 250) { //send at least one kb of data int size = (*msgsize)/1024 + 1; //returned buffer will contain test indicator, message size in kb and data bufsize = size*1024+2; buf = new char[bufsize]; - buf[0] = 0xDE; //second byte contains size in kilobytes + buf[0] = (unsigned char)0xDE; //second byte contains size in kilobytes buf[1] = (char)(size); *msgsize = size*1024; } @@ -333,7 +334,7 @@ Client::CreateBuffer(int* msgsize) //returned buffer will contain test indicator, message size in kb and data bufsize = (*msgsize)+2; buf = new char[bufsize]; - buf[0] = 0xBE; //second byte contains size in bytes + buf[0] = (unsigned char)0xBE; //second byte contains size in bytes buf[1] = (char)(*msgsize); } return buf; @@ -367,7 +368,7 @@ Client::StartWorker(workMode pMode) { void Client::StartWorker(workMode pMode, const wxString& pMessage) { - char* tmpbuf = strdup(pMessage.mb_str()); + char* tmpbuf = wxStrdup(pMessage.mb_str()); int msgsize = strlen(tmpbuf); char* buf = CreateBuffer(&msgsize); memset(buf+2,0x0,msgsize); @@ -450,11 +451,11 @@ Client::OnWorkerEvent(WorkerEvent& pEvent) { break; } } - for(EList::compatibility_iterator it = m_eventWorkers.GetFirst(); it ; it = it->GetNext()) + for(EList::compatibility_iterator it2 = m_eventWorkers.GetFirst(); it2 ; it2 = it2->GetNext()) { - if (it->GetData() == pEvent.m_sender) { - delete it->GetData(); - m_eventWorkers.DeleteNode(it); + if (it2->GetData() == pEvent.m_sender) { + delete it2->GetData(); + m_eventWorkers.DeleteNode(it2); break; } } @@ -613,7 +614,9 @@ EventWorker::OnSocketEvent(wxSocketEvent& pEvent) { //wxLogMessage(wxT("EventWorker: got connection")); wxLogMessage(wxT("%s: starting writing message (2 bytes for signature and %d bytes of data to write)"),CreateIdent(m_localaddr).c_str(),m_outsize-2); if (!m_clientSocket->GetLocal(m_localaddr)) + { wxLogError(_("Cannot get peer data for socket %p"),m_clientSocket); + } m_currentType = WorkerEvent::SENDING; wxLogDebug(wxT("%s: CONNECTING"),CreateIdent(m_localaddr).c_str()); SendEvent(false);