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
This commit is contained in:
alex 2008-05-30 10:36:34 +00:00
parent d02ab18b42
commit b4a9d9fc17

View File

@ -280,7 +280,8 @@ bool TBaseServerApp::CanProcessCommand(wxString& cmd, wxSocketBase& outs)
if (cmd.Find("stop.cgi") > 0) if (cmd.Find("stop.cgi") > 0)
{ {
m_bRunning = false; // Disable gif on title m_bRunning = false; // Disable gif on title
MessageBox("Warning!", "Server Stopped", outs); if (outs.IsOk())
MessageBox("Warning!", "Server Stopped", outs);
ExitMainLoop(); ExitMainLoop();
return false; return false;
} }
@ -484,23 +485,40 @@ void TBaseServerApp::OnServerEvent(wxSocketEvent& e)
sock->Notify(TRUE); sock->Notify(TRUE);
} }
struct TCommand : public wxObject
{
wxSocketBase * m_Sock;
wxString m_Command;
};
void TBaseServerApp::OnSocketEvent(wxSocketEvent& e) void TBaseServerApp::OnSocketEvent(wxSocketEvent& e)
{ {
wxSocketBase& sock = *e.GetSocket(); wxSocketBase * sock = e.GetSocket();
switch(e.GetSocketEvent()) switch(e.GetSocketEvent())
{ {
case wxSOCKET_INPUT: case wxSOCKET_INPUT:
{ {
// We disable input events, so that the test doesn't trigger // We disable input events, so that the test doesn't trigger
// wxSocketEvent again. // 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; break;
case wxSOCKET_LOST: case wxSOCKET_LOST:
WriteLog("--- Deleting socket."); WriteLog("--- Socket lost.");
if (m_Sockets.Index(&sock) >= 0)
m_Sockets.Remove(&sock);
sock.Destroy();
break; break;
default: default:
break; break;
@ -510,36 +528,33 @@ void TBaseServerApp::OnIdle(wxIdleEvent& event)
{ {
if (m_Sockets.GetCount() > 0) 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); wxString & str = ((TCommand *) m_Sockets[0])->m_Command;
// 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;
WriteLog(str); WriteLog(str);
if (CanProcessCommand(str, sock)) if (CanProcessCommand(str, sock))
{ {
const wxSocketFlags flags = sock.GetFlags(); const wxSocketFlags flags = sock.GetFlags();
sock.SetFlags(wxSOCKET_WAITALL); if (valid_socket)
sock.SetFlags(wxSOCKET_WAITALL);
ProcessCommand(str, sock); ProcessCommand(str, sock);
sock.SetFlags(flags); if (valid_socket)
sock.SetFlags(flags);
} }
// Enable input events again. // 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); wxApp::OnIdle(event);
} }