From b4a9d9fc174c71448cc98f456d3f3b8d28d3fff1 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 30 May 2008 10:36:34 +0000 Subject: [PATCH] Patch level : 10.0 0064 Files correlati : Postman Ricompilazione Demo : [ ] Commento : Corretto l'algoritmo di lryyura mne caso che il client non aspetti la risposta git-svn-id: svn://10.65.10.50/trunk@16679 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- server/baseserv.cpp | 69 +++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/server/baseserv.cpp b/server/baseserv.cpp index b4c655e69..7ee293031 100755 --- a/server/baseserv.cpp +++ b/server/baseserv.cpp @@ -280,7 +280,8 @@ bool TBaseServerApp::CanProcessCommand(wxString& cmd, wxSocketBase& outs) if (cmd.Find("stop.cgi") > 0) { m_bRunning = false; // Disable gif on title - MessageBox("Warning!", "Server Stopped", outs); + if (outs.IsOk()) + MessageBox("Warning!", "Server Stopped", outs); ExitMainLoop(); return false; } @@ -484,23 +485,40 @@ void TBaseServerApp::OnServerEvent(wxSocketEvent& e) sock->Notify(TRUE); } +struct TCommand : public wxObject +{ + wxSocketBase * m_Sock; + wxString m_Command; +}; + void TBaseServerApp::OnSocketEvent(wxSocketEvent& e) { - wxSocketBase& sock = *e.GetSocket(); + wxSocketBase * sock = e.GetSocket(); switch(e.GetSocketEvent()) { case wxSOCKET_INPUT: { // We disable input events, so that the test doesn't trigger // wxSocketEvent again. - m_Sockets.Add(&sock); + TCommand * message = new TCommand; + message->m_Sock = sock; + const size_t BUFSIZE = 1024; + wxChar buf[BUFSIZE + 1]; + + // Read the data + + memset(buf, 0, sizeof(buf)); + while (sock->Read(buf, BUFSIZE).LastCount() == BUFSIZE) + { + message->m_Command << buf; + memset(buf, 0, sizeof(buf)); + } + message->m_Command << buf; + m_Sockets.Add(message); } break; case wxSOCKET_LOST: - WriteLog("--- Deleting socket."); - if (m_Sockets.Index(&sock) >= 0) - m_Sockets.Remove(&sock); - sock.Destroy(); + WriteLog("--- Socket lost."); break; default: break; @@ -510,36 +528,33 @@ void TBaseServerApp::OnIdle(wxIdleEvent& event) { if (m_Sockets.GetCount() > 0) { - wxSocketBase& sock = *(wxSocketBase *) m_Sockets[0]; + wxSocketBase& sock = *(((TCommand *) m_Sockets[0])->m_Sock); + const bool valid_socket = sock.IsOk(); + if (valid_socket) + sock.SetNotify(wxSOCKET_LOST_FLAG); - sock.SetNotify(wxSOCKET_LOST_FLAG); - - // Read the data - const size_t BUFSIZE = 1024; - wxString str; - wxChar buf[BUFSIZE + 1]; - - memset(buf, 0, sizeof(buf)); - while (sock.Read(buf, BUFSIZE).LastCount() == BUFSIZE) - { - str << buf; - memset(buf, 0, sizeof(buf)); - } - - str << buf; + wxString & str = ((TCommand *) m_Sockets[0])->m_Command; WriteLog(str); if (CanProcessCommand(str, sock)) { const wxSocketFlags flags = sock.GetFlags(); - sock.SetFlags(wxSOCKET_WAITALL); + if (valid_socket) + sock.SetFlags(wxSOCKET_WAITALL); ProcessCommand(str, sock); - sock.SetFlags(flags); + if (valid_socket) + sock.SetFlags(flags); } // Enable input events again. - sock.SetNotify(wxSOCKET_LOST_FLAG | wxSOCKET_INPUT_FLAG); - m_Sockets.Remove(&sock); + + if (valid_socket) + { + sock.SetNotify(wxSOCKET_LOST_FLAG | wxSOCKET_INPUT_FLAG); + sock.Notify(TRUE); + } + + m_Sockets.RemoveAt(0); } wxApp::OnIdle(event); }