Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/rev/5484e7f83505
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 00:05:48 2012
Кодировка:
allpy: 5484e7f83505

allpy

changeset 75:5484e7f83505

wt: anti-DDOS counter of active tasks
author boris <bnagaev@gmail.com>
date Sat, 25 Sep 2010 21:56:44 +0400
parents df4d9ab9569b
children e4b269ba4f5f
files blocks3d/wt/TODO blocks3d/wt/blocks3d-wt-widget.C blocks3d/wt/blocks3d-wt-widget.h blocks3d/wt/blocks3d-wt.pro blocks3d/wt/config.h
diffstat 5 files changed, 39 insertions(+), 8 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/blocks3d/wt/TODO	Sat Sep 25 21:56:44 2010 +0400
     1.3 @@ -0,0 +1,2 @@
     1.4 +mktemp -> mkstemp 
     1.5 +count number of running tasks (limit is N)
     2.1 --- a/blocks3d/wt/blocks3d-wt-widget.C	Sat Sep 18 11:57:21 2010 +0400
     2.2 +++ b/blocks3d/wt/blocks3d-wt-widget.C	Sat Sep 25 21:56:44 2010 +0400
     2.3 @@ -17,6 +17,10 @@
     2.4  #include <iostream>
     2.5  #include <boost/format.hpp>
     2.6  #include <cstdlib>
     2.7 +#include <list>
     2.8 +#include <string>
     2.9 +
    2.10 +std::list<std::string> current_taks;
    2.11  
    2.12  Blocks3DWidget::Blocks3DWidget(Wt::WContainerWidget *parent) :
    2.13  	Wt::WContainerWidget(parent)
    2.14 @@ -150,8 +154,29 @@
    2.15  		conformity_upload->spoolFileName().c_str());
    2.16  }
    2.17  
    2.18 +bool Blocks3DWidget::is_completed(std::string tempfile_check)
    2.19 +{
    2.20 +	std::ifstream check_file;
    2.21 +	check_file.open(tempfile_check.c_str());
    2.22 +	if (!check_file) 
    2.23 +	{
    2.24 +		return false;
    2.25 +	}
    2.26 +	check_file.close();
    2.27 +	return true;
    2.28 +}
    2.29 +
    2.30  void Blocks3DWidget::try_to_run()
    2.31  {
    2.32 +	current_taks.remove_if(&Blocks3DWidget::is_completed);
    2.33 +	if (current_taks.size() >= Malakite::max_simultaneous_tasks)
    2.34 +	{
    2.35 +		new Wt::WBreak(results_panel);
    2.36 +		new Wt::WText("Service is overloaded. "
    2.37 +		"Please wait until other tasks are completed", results_panel); 
    2.38 +		return;
    2.39 +	}
    2.40 +	
    2.41  	std::string alignment = alignment_textarea->text().toUTF8();
    2.42  	std::string conformity = conformity_textarea->text().toUTF8();
    2.43  	if (alignment.empty())
    2.44 @@ -242,19 +267,17 @@
    2.45  	
    2.46  	timer->start();
    2.47  	
    2.48 +	current_taks.push_back(tempfile_check);
    2.49  }
    2.50  
    2.51  void Blocks3DWidget::timeout()
    2.52  {
    2.53  	worktime->render();
    2.54  	// FIXME: check status of task
    2.55 -	std::ifstream check_file;
    2.56 -	check_file.open(tempfile_check.c_str());
    2.57 -	if (!check_file) 
    2.58 +	if (!is_completed(tempfile_check))
    2.59  	{
    2.60  		return;
    2.61  	}
    2.62 -	check_file.close();
    2.63  	
    2.64  	timer->stop();
    2.65  	worktime->stop();
    2.66 @@ -282,8 +305,6 @@
    2.67  	Wt::WFileResource* html_download = 
    2.68  	new Wt::WFileResource("application/html", tempfile_html, this);	
    2.69  	new Wt::WAnchor(html_download, "Download", results_panel);
    2.70 -	
    2.71 -	
    2.72  }
    2.73  
    2.74  
     3.1 --- a/blocks3d/wt/blocks3d-wt-widget.h	Sat Sep 18 11:57:21 2010 +0400
     3.2 +++ b/blocks3d/wt/blocks3d-wt-widget.h	Sat Sep 25 21:56:44 2010 +0400
     3.3 @@ -4,6 +4,8 @@
     3.4  #include "config.h"
     3.5  #include "work-time.h"
     3.6  
     3.7 +#include <string>
     3.8 +
     3.9  #include <Wt/WPanel>
    3.10  #include <Wt/WString>
    3.11  #include <Wt/WHBoxLayout>
    3.12 @@ -47,6 +49,8 @@
    3.13    std::string tempfile_check;
    3.14    std::string tempfile_sh;
    3.15    
    3.16 +  static bool is_completed(std::string tempfile_check);
    3.17 +  
    3.18    void textarea_from_file(Wt::WTextArea* ta, const char* file);
    3.19    void go_button_click();
    3.20    void alignment_uploaded();
     4.1 --- a/blocks3d/wt/blocks3d-wt.pro	Sat Sep 18 11:57:21 2010 +0400
     4.2 +++ b/blocks3d/wt/blocks3d-wt.pro	Sat Sep 25 21:56:44 2010 +0400
     4.3 @@ -6,9 +6,12 @@
     4.4  SOURCES += blocks3d-wt-widget.C
     4.5  SOURCES += work-time.C
     4.6  
     4.7 -CONFIG += debug
     4.8 -CONFIG += precompile_header
     4.9 +#CONFIG += debug
    4.10 +#CONFIG += precompile_header
    4.11 +CONFIG += console
    4.12  
    4.13 +QMAKE_LFLAGS += -flto
    4.14 +QMAKE_CXXFLAGS += -flto
    4.15  
    4.16  INCLUDEPATH = /usr/local/include/Wt/
    4.17  
     5.1 --- a/blocks3d/wt/config.h	Sat Sep 18 11:57:21 2010 +0400
     5.2 +++ b/blocks3d/wt/config.h	Sat Sep 25 21:56:44 2010 +0400
     5.3 @@ -6,6 +6,7 @@
     5.4  
     5.5  const int refresh_period = 5*1000;
     5.6  
     5.7 +const unsigned int max_simultaneous_tasks = 1;
     5.8  
     5.9  extern const char* python_path;
    5.10  extern const char* blocks3d_path;