X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a1b806b98241ab649c169aaa1f134df85e80fb8b..1ec4e9c2b72a01a7ba7da569e0f8d04a81aaba10:/samples/sockets/baseserver.cpp diff --git a/samples/sockets/baseserver.cpp b/samples/sockets/baseserver.cpp index ac856e80a2..7e3d6d8fb1 100644 --- a/samples/sockets/baseserver.cpp +++ b/samples/sockets/baseserver.cpp @@ -142,7 +142,7 @@ private: long int m_maxConnections; - long m_port; + unsigned short m_port; wxTimer mTimer; }; @@ -258,7 +258,7 @@ Server::DumpStatistics() if ((int)(m_threadWorkersDone+m_eventWorkersDone) == m_maxConnections) { - wxLogMessage("%d connection(s) served, exiting",m_maxConnections); + wxLogMessage("%ld connection(s) served, exiting",m_maxConnections); ExitMainLoop(); } } @@ -279,12 +279,21 @@ Server::OnCmdLineParsed(wxCmdLineParser& pParser) if (pParser.Found("m",&m_maxConnections)) { - wxLogMessage("%d connection(s) to exit",m_maxConnections); + wxLogMessage("%ld connection(s) to exit",m_maxConnections); } - if (pParser.Found("p",&m_port)) + long port; + if (pParser.Found("p", &port)) { - wxLogMessage("%d connection(s) to exit",m_maxConnections); + if ( port <= 0 || port > USHRT_MAX ) + { + wxLogError("Invalid port number %ld, must be in 0..%u range.", + port, USHRT_MAX); + return false; + } + + m_port = static_cast(port); + wxLogMessage("Will listen on port %u", m_port); } if (pParser.Found("t")) @@ -331,7 +340,7 @@ bool Server::OnInit() m_eventWorkersFailed = 0; m_maxEventWorkers = 0; - wxLogMessage("Server listening at port %d, waiting for connections", m_port); + wxLogMessage("Server listening at port %u, waiting for connections", m_port); return true; } @@ -425,8 +434,8 @@ void Server::OnWorkerEvent(WorkerEvent& pEvent) { if (it->GetData() == pEvent.m_sender) { - wxLogVerbose("Deleting thread worker (%d left)", - m_threadWorkers.GetCount()); + wxLogVerbose("Deleting thread worker (%lu left)", + static_cast( m_threadWorkers.GetCount() )); it->GetData()->Wait(); delete it->GetData(); m_threadWorkers.DeleteNode(it); @@ -441,8 +450,8 @@ void Server::OnWorkerEvent(WorkerEvent& pEvent) { if (it2->GetData() == pEvent.m_sender) { - wxLogVerbose("Deleting event worker (%d left)", - m_eventWorkers.GetCount()); + wxLogVerbose("Deleting event worker (%lu left)", + static_cast( m_eventWorkers.GetCount() )); delete it2->GetData(); m_eventWorkers.DeleteNode(it2); if (!pEvent.m_workerFailed)