mirror of https://github.com/BOINC/boinc.git
added counter/timeout loop
svn path=/trunk/boinc/; revision=4102
This commit is contained in:
parent
9a336ede22
commit
803e4ed168
108
sched/main.C
108
sched/main.C
|
@ -50,6 +50,7 @@ using namespace std;
|
|||
#endif
|
||||
|
||||
#define DEBUG_LEVEL 999
|
||||
#define MAX_FCGI_COUNT 20
|
||||
|
||||
void get_log_path(char* p) {
|
||||
char buf[256];
|
||||
|
@ -69,8 +70,7 @@ key_t sema_key;
|
|||
int g_pid;
|
||||
|
||||
void send_message(char* msg, int delay) {
|
||||
fprintf(
|
||||
stdout,
|
||||
printf(
|
||||
"Content-type: text/plain\n\n"
|
||||
"<scheduler_reply>\n"
|
||||
" <message priority=\"low\">%s</message>\n"
|
||||
|
@ -173,59 +173,69 @@ int main() {
|
|||
|
||||
g_pid = getpid();
|
||||
#ifdef _USING_FCGI_
|
||||
while(FCGI_Accept() >= 0) {
|
||||
counter++;
|
||||
while(FCGI_Accept() >= 0 && counter < MAX_FCGI_COUNT) {
|
||||
counter++;
|
||||
#endif
|
||||
if (project_stopped) {
|
||||
send_message("Project is temporarily shut down for maintenance", 3600);
|
||||
goto done;
|
||||
if (project_stopped) {
|
||||
send_message("Project is temporarily shut down for maintenance", 3600);
|
||||
goto done;
|
||||
}
|
||||
fprintf(stdout,"Content-type: text/plain\n\n");
|
||||
if (use_files) {
|
||||
// the code below is convoluted because,
|
||||
// instead of going from stdin to stdout directly,
|
||||
// we go via a pair of disk files
|
||||
// (this makes it easy to save the input,
|
||||
// and to know the length of the output).
|
||||
//
|
||||
sprintf(req_path, "%s%d_%u", REQ_FILE_PREFIX, g_pid, counter);
|
||||
sprintf(reply_path, "%s%d_%u", REPLY_FILE_PREFIX, g_pid, counter);
|
||||
fout = fopen(req_path, "w");
|
||||
if (!fout) {
|
||||
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't write request file\n");
|
||||
exit(1);
|
||||
}
|
||||
fprintf(stdout,"Content-type: text/plain\n\n");
|
||||
if (use_files) {
|
||||
// the code below is convoluted because,
|
||||
// instead of going from stdin to stdout directly,
|
||||
// we go via a pair of disk files
|
||||
// (this makes it easy to save the input,
|
||||
// and to know the length of the output).
|
||||
//
|
||||
sprintf(req_path, "%s%d_%u", REQ_FILE_PREFIX, g_pid, counter);
|
||||
sprintf(reply_path, "%s%d_%u", REPLY_FILE_PREFIX, g_pid, counter);
|
||||
fout = fopen(req_path, "w");
|
||||
if (!fout) {
|
||||
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't write request file\n");
|
||||
exit(1);
|
||||
}
|
||||
copy_stream(stdin, fout);
|
||||
fclose(fout);
|
||||
fin = fopen(req_path, "r");
|
||||
if (!fin) {
|
||||
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't read request file\n");
|
||||
exit(1);
|
||||
}
|
||||
fout = fopen(reply_path, "w");
|
||||
if (!fout) {
|
||||
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't write reply file\n");
|
||||
exit(1);
|
||||
}
|
||||
handle_request(fin, fout, *ssp, code_sign_key);
|
||||
fclose(fin);
|
||||
fclose(fout);
|
||||
fin = fopen(reply_path, "r");
|
||||
if (!fin) {
|
||||
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't read reply file\n");
|
||||
exit(1);
|
||||
}
|
||||
copy_stream(fin, stdout);
|
||||
fclose(fin);
|
||||
//unlink(req_path);
|
||||
//unlink(reply_path);
|
||||
} else {
|
||||
handle_request(stdin, stdout, *ssp, code_sign_key);
|
||||
copy_stream(stdin, fout);
|
||||
fclose(fout);
|
||||
fin = fopen(req_path, "r");
|
||||
if (!fin) {
|
||||
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't read request file\n");
|
||||
exit(1);
|
||||
}
|
||||
fout = fopen(reply_path, "w");
|
||||
if (!fout) {
|
||||
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't write reply file\n");
|
||||
exit(1);
|
||||
}
|
||||
handle_request(fin, fout, *ssp, code_sign_key);
|
||||
fclose(fin);
|
||||
fclose(fout);
|
||||
fin = fopen(reply_path, "r");
|
||||
if (!fin) {
|
||||
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't read reply file\n");
|
||||
exit(1);
|
||||
}
|
||||
copy_stream(fin, stdout);
|
||||
fclose(fin);
|
||||
//unlink(req_path);
|
||||
//unlink(reply_path);
|
||||
} else {
|
||||
handle_request(stdin, stdout, *ssp, code_sign_key);
|
||||
}
|
||||
done:
|
||||
#ifdef _USING_FCGI_
|
||||
continue;
|
||||
fprintf(stderr, "FCGI: counter: %d\n", counter);
|
||||
continue;
|
||||
}
|
||||
if (counter == MAX_FCGI_COUNT) {
|
||||
fprintf(stderr, "FCGI: counter passed MAX_FCGI_COUNT - exiting..\n");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "FCGI: FCGI_Accept failed - exiting..\n");
|
||||
}
|
||||
// when exiting, write headers back to apache so it won't complain
|
||||
// about "incomplete headers"
|
||||
fprintf(stdout,"Content-type: text/plain\n\n");
|
||||
#endif
|
||||
if (db_opened) {
|
||||
boinc_db.close();
|
||||
|
|
Loading…
Reference in New Issue