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

# HG changeset patch
# User boris
# Date 1285437404 -14400
# Node ID 5484e7f83505fd489e7d58354737c9a44e773529
# Parent df4d9ab9569bb2f541a9ad3943904505d37c43c8
wt: anti-DDOS counter of active tasks

diff -r df4d9ab9569b -r 5484e7f83505 blocks3d/wt/TODO
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/blocks3d/wt/TODO Sat Sep 25 21:56:44 2010 +0400
@@ -0,0 +1,2 @@
+mktemp -> mkstemp
+count number of running tasks (limit is N)
diff -r df4d9ab9569b -r 5484e7f83505 blocks3d/wt/blocks3d-wt-widget.C
--- a/blocks3d/wt/blocks3d-wt-widget.C Sat Sep 18 11:57:21 2010 +0400
+++ b/blocks3d/wt/blocks3d-wt-widget.C Sat Sep 25 21:56:44 2010 +0400
@@ -17,6 +17,10 @@
#include
#include
#include
+#include
+#include
+
+std::list current_taks;

Blocks3DWidget::Blocks3DWidget(Wt::WContainerWidget *parent) :
Wt::WContainerWidget(parent)
@@ -150,8 +154,29 @@
conformity_upload->spoolFileName().c_str());
}

+bool Blocks3DWidget::is_completed(std::string tempfile_check)
+{
+ std::ifstream check_file;
+ check_file.open(tempfile_check.c_str());
+ if (!check_file)
+ {
+ return false;
+ }
+ check_file.close();
+ return true;
+}
+
void Blocks3DWidget::try_to_run()
{
+ current_taks.remove_if(&Blocks3DWidget::is_completed);
+ if (current_taks.size() >= Malakite::max_simultaneous_tasks)
+ {
+ new Wt::WBreak(results_panel);
+ new Wt::WText("Service is overloaded. "
+ "Please wait until other tasks are completed", results_panel);
+ return;
+ }
+
std::string alignment = alignment_textarea->text().toUTF8();
std::string conformity = conformity_textarea->text().toUTF8();
if (alignment.empty())
@@ -242,19 +267,17 @@

timer->start();

+ current_taks.push_back(tempfile_check);
}

void Blocks3DWidget::timeout()
{
worktime->render();
// FIXME: check status of task
- std::ifstream check_file;
- check_file.open(tempfile_check.c_str());
- if (!check_file)
+ if (!is_completed(tempfile_check))
{
return;
}
- check_file.close();

timer->stop();
worktime->stop();
@@ -282,8 +305,6 @@
Wt::WFileResource* html_download =
new Wt::WFileResource("application/html", tempfile_html, this);
new Wt::WAnchor(html_download, "Download", results_panel);
-
-
}


diff -r df4d9ab9569b -r 5484e7f83505 blocks3d/wt/blocks3d-wt-widget.h
--- a/blocks3d/wt/blocks3d-wt-widget.h Sat Sep 18 11:57:21 2010 +0400
+++ b/blocks3d/wt/blocks3d-wt-widget.h Sat Sep 25 21:56:44 2010 +0400
@@ -4,6 +4,8 @@
#include "config.h"
#include "work-time.h"

+#include
+
#include
#include
#include
@@ -47,6 +49,8 @@
std::string tempfile_check;
std::string tempfile_sh;

+ static bool is_completed(std::string tempfile_check);
+
void textarea_from_file(Wt::WTextArea* ta, const char* file);
void go_button_click();
void alignment_uploaded();
diff -r df4d9ab9569b -r 5484e7f83505 blocks3d/wt/blocks3d-wt.pro
--- a/blocks3d/wt/blocks3d-wt.pro Sat Sep 18 11:57:21 2010 +0400
+++ b/blocks3d/wt/blocks3d-wt.pro Sat Sep 25 21:56:44 2010 +0400
@@ -6,9 +6,12 @@
SOURCES += blocks3d-wt-widget.C
SOURCES += work-time.C

-CONFIG += debug
-CONFIG += precompile_header
+#CONFIG += debug
+#CONFIG += precompile_header
+CONFIG += console

+QMAKE_LFLAGS += -flto
+QMAKE_CXXFLAGS += -flto

INCLUDEPATH = /usr/local/include/Wt/

diff -r df4d9ab9569b -r 5484e7f83505 blocks3d/wt/config.h
--- a/blocks3d/wt/config.h Sat Sep 18 11:57:21 2010 +0400
+++ b/blocks3d/wt/config.h Sat Sep 25 21:56:44 2010 +0400
@@ -6,6 +6,7 @@

const int refresh_period = 5*1000;

+const unsigned int max_simultaneous_tasks = 1;

extern const char* python_path;
extern const char* blocks3d_path;