Patch level : 10.0
Files correlati : servers Ricompilazione Demo : [ ] Commento : Corretta gestione di più richieste contemporanee git-svn-id: svn://10.65.10.50/trunk@19850 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
		
							parent
							
								
									244eb1cf44
								
							
						
					
					
						commit
						ca04ac80b4
					
				@ -276,7 +276,6 @@ wxString TAuthorizationServer::DescribeModule(int m) const
 | 
				
			|||||||
	return line;  // Should never happen!
 | 
						return line;  // Should never happen!
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
void TAuthorizationServer::AddNumber(TXmlItem& tr, int n) const
 | 
					void TAuthorizationServer::AddNumber(TXmlItem& tr, int n) const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	TXmlItem& td = tr.AddChild("td");
 | 
						TXmlItem& td = tr.AddChild("td");
 | 
				
			||||||
 | 
				
			|||||||
@ -503,20 +503,19 @@ struct TCommand : public wxObject
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
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.
 | 
					      sock->SetNotify(wxSOCKET_LOST_FLAG);
 | 
				
			||||||
			TCommand * message = new TCommand;
 | 
								TCommand * message = new TCommand;
 | 
				
			||||||
			message->m_Sock = sock;
 | 
								message->m_Sock = sock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							  // Read the data
 | 
				
			||||||
			const size_t BUFSIZE = 1024;
 | 
								const size_t BUFSIZE = 1024;
 | 
				
			||||||
			wxChar  buf[BUFSIZE + 1];
 | 
								wxChar  buf[BUFSIZE + 16];
 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Read the data
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			memset(buf, 0, sizeof(buf));
 | 
								memset(buf, 0, sizeof(buf));
 | 
				
			||||||
			while (sock->Read(buf, BUFSIZE).LastCount() == BUFSIZE)
 | 
								while (sock->Read(buf, BUFSIZE).LastCount() == BUFSIZE)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
@ -525,6 +524,9 @@ void TBaseServerApp::OnSocketEvent(wxSocketEvent& e)
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			message->m_Command << buf;
 | 
								message->m_Command << buf;
 | 
				
			||||||
			m_Sockets.Add(message);
 | 
								m_Sockets.Add(message);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Enable input events again.
 | 
				
			||||||
 | 
					      sock->SetNotify(wxSOCKET_LOST_FLAG | wxSOCKET_INPUT_FLAG);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  case wxSOCKET_LOST:
 | 
					  case wxSOCKET_LOST:
 | 
				
			||||||
@ -535,7 +537,7 @@ void TBaseServerApp::OnSocketEvent(wxSocketEvent& e)
 | 
				
			|||||||
    break;
 | 
					    break;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
void TBaseServerApp::OnIdle(wxIdleEvent& event)
 | 
					void TBaseServerApp::OnIdle(wxIdleEvent& evt)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (m_Sockets.GetCount() > 0)
 | 
						if (m_Sockets.GetCount() > 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@ -568,8 +570,9 @@ void TBaseServerApp::OnIdle(wxIdleEvent& event)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		m_Sockets.RemoveAt(0);
 | 
							m_Sockets.RemoveAt(0);
 | 
				
			||||||
 | 
					    evt.RequestMore(); // FONDAMENTALE per gestire richieste multiple!
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	wxApp::OnIdle(event);
 | 
						wxApp::OnIdle(evt);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const wxString& TBaseServerApp::GetConfigName() const
 | 
					const wxString& TBaseServerApp::GetConfigName() const
 | 
				
			||||||
@ -729,8 +732,8 @@ int TBaseServerApp::OnExit()
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
    Deinitialization();
 | 
					    Deinitialization();
 | 
				
			||||||
		delete m_SingleInstance;
 | 
							delete m_SingleInstance;
 | 
				
			||||||
  	delete m_server;
 | 
					 | 
				
			||||||
    m_SingleInstance = NULL;
 | 
					    m_SingleInstance = NULL;
 | 
				
			||||||
 | 
					  	delete m_server;
 | 
				
			||||||
    m_server = NULL;
 | 
					    m_server = NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (m_log != NULL)
 | 
						if (m_log != NULL)
 | 
				
			||||||
 | 
				
			|||||||
@ -47,6 +47,7 @@ protected:
 | 
				
			|||||||
	virtual const wxChar* GetAppName() const;
 | 
						virtual const wxChar* GetAppName() const;
 | 
				
			||||||
  virtual bool Initialization();
 | 
					  virtual bool Initialization();
 | 
				
			||||||
  void OnTimer(wxTimerEvent& evt);
 | 
					  void OnTimer(wxTimerEvent& evt);
 | 
				
			||||||
 | 
					  bool RestartTimer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void AddMiniForm(TXmlItem& tr, const wxChar* action, const wxChar* app, const wxChar* prompt) const;
 | 
						void AddMiniForm(TXmlItem& tr, const wxChar* action, const wxChar* app, const wxChar* prompt) const;
 | 
				
			||||||
  void EnumerateVariables(const wxString& strApp, wxArrayString& arr) const;
 | 
					  void EnumerateVariables(const wxString& strApp, wxArrayString& arr) const;
 | 
				
			||||||
@ -142,7 +143,7 @@ void TLurchServer::OnTimer(wxTimerEvent& WXUNUSED(evt))
 | 
				
			|||||||
    wxSleep(2);
 | 
					    wxSleep(2);
 | 
				
			||||||
    StartProcess(strApp);
 | 
					    StartProcess(strApp);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  m_Timer.Start(m_nFreq);
 | 
					  RestartTimer();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const wxChar* TLurchServer::GetAppName() const
 | 
					const wxChar* TLurchServer::GetAppName() const
 | 
				
			||||||
@ -212,7 +213,7 @@ void TLurchServer::GenerateFile(wxString& strFilename)
 | 
				
			|||||||
			ini.SetPath(str);
 | 
								ini.SetPath(str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      wxString strHost; 
 | 
					      wxString strHost; 
 | 
				
			||||||
			ini.Read("Host", &strHost, wxGetFullHostName());
 | 
								ini.Read("Host", &strHost, "127.0.0.1");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			int nPort;
 | 
								int nPort;
 | 
				
			||||||
			ini.Read("Port", &nPort, 3883);
 | 
								ini.Read("Port", &nPort, 3883);
 | 
				
			||||||
@ -247,6 +248,25 @@ void TLurchServer::GenerateFile(wxString& strFilename)
 | 
				
			|||||||
     	a3 << arr[i] << " Server";
 | 
					     	a3 << arr[i] << " Server";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    body.AddChild("hr");
 | 
				
			||||||
 | 
					    TXmlItem& panel = body.AddChild("table");
 | 
				
			||||||
 | 
					    panel.SetAttr("border", "1"); panel.SetAttr("width", "100%");
 | 
				
			||||||
 | 
					    panel.AddChild("caption").AddEnclosedText("Options");
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    TXmlItem& tr0 = panel.AddChild("tr");
 | 
				
			||||||
 | 
					    tr0.AddChild("td").AddEnclosedText("Working directory");
 | 
				
			||||||
 | 
					    tr0.AddChild("td").AddEnclosedText(wxGetCwd());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TXmlItem& tr1 = panel.AddChild("tr");
 | 
				
			||||||
 | 
					    tr1.AddChild("td").AddEnclosedText("Host Name");
 | 
				
			||||||
 | 
					    wxString strHost; strHost << wxGetHostName() << wxT(":") << GetDefaultPort();
 | 
				
			||||||
 | 
					    tr1.AddChild("td").AddEnclosedText(strHost);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    TXmlItem& tr2 = panel.AddChild("tr");
 | 
				
			||||||
 | 
					    tr2.AddChild("td").AddEnclosedText("Ping Frequency");
 | 
				
			||||||
 | 
					    wxString strFreq; strFreq << m_nFreq/1000;
 | 
				
			||||||
 | 
					    tr2.AddChild("td").AddEnclosedText(strFreq);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		html.Save(strFilename);
 | 
							html.Save(strFilename);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -281,6 +301,21 @@ bool TLurchServer::IsCgiName(wxString strFilename) const
 | 
				
			|||||||
	return strExt == "cgi" || strExt == "exe";
 | 
						return strExt == "cgi" || strExt == "exe";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool TLurchServer::RestartTimer()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  bool ok = true;
 | 
				
			||||||
 | 
					  if (m_nFreq > 0)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    ok = m_Timer.Start(m_nFreq) && m_Timer.IsRunning();
 | 
				
			||||||
 | 
					    if (!ok)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      wxString strMsg;
 | 
				
			||||||
 | 
					      strMsg << "Error starting timer with " << m_nFreq << " ms frequency";
 | 
				
			||||||
 | 
					      WriteLog(strMsg);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return ok;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wxString TLurchServer::StartProcess(const wxString& strApp)
 | 
					wxString TLurchServer::StartProcess(const wxString& strApp)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -314,8 +349,6 @@ wxString TLurchServer::StartProcess(const wxString& strApp)
 | 
				
			|||||||
        pProcess->ForcePid(nProc);
 | 
					        pProcess->ForcePid(nProc);
 | 
				
			||||||
        m_ProcMap[strApp] = pProcess;   //memorizza il numero del processo che ha lanciato per poterlo usare in fase di controllo
 | 
					        m_ProcMap[strApp] = pProcess;   //memorizza il numero del processo che ha lanciato per poterlo usare in fase di controllo
 | 
				
			||||||
			  strMessage = wxEmptyString;
 | 
								  strMessage = wxEmptyString;
 | 
				
			||||||
        if (m_nFreq > 0)
 | 
					 | 
				
			||||||
          m_Timer.Start(m_nFreq);
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
@ -560,6 +593,8 @@ void TLurchServer::ProcessHttpPost(wxString cmd, wxSocketBase& outs)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bool TLurchServer::Initialization()
 | 
					bool TLurchServer::Initialization()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					  m_nFreq = GetConfigInt("PingFreq") * 1000;  // sec to msec
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  wxArrayString arr; CreateServersList(arr);
 | 
					  wxArrayString arr; CreateServersList(arr);
 | 
				
			||||||
	for (size_t i = 0; i < arr.GetCount(); i++)
 | 
						for (size_t i = 0; i < arr.GetCount(); i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@ -568,8 +603,9 @@ bool TLurchServer::Initialization()
 | 
				
			|||||||
		if (bAutorun)
 | 
							if (bAutorun)
 | 
				
			||||||
      StartProcess(strApp);
 | 
					      StartProcess(strApp);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  RestartTimer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  m_nFreq = GetConfigInt("PingFreq") * 1000;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user