-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserver.pl
More file actions
executable file
·77 lines (63 loc) · 1.95 KB
/
userver.pl
File metadata and controls
executable file
·77 lines (63 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl
use 5.010;
BEGIN
{ my $q;
my $path = $ENV{'PWD'};
until ( -d $path.'/'.'lib' )
{
$path .= '/../';
++$q > 10 and die 'Ошибка, возможно неверная структура каталогов приложения!';
}
chdir($path);
use lib qw|lib|;
}
package USERVER;
use Getopt::Long;
use Data::Dumper;
use SERVER;
use CONFIG;
use POSIX;
my $result = GetOptions ( 'debug|d+' => \$d, 'check|c:i' => \$cc, ) or die;
&SERVER::init_log();
&SERVER::get_logs();
&SERVER::locked_open($CONFIG::path->{'lock'});
&SERVER::init_server();
&SERVER::init_sig_handler(['CHLD','INT','USR1','USR2']);
&SERVER::check_hand_type() and &SERVER::init_application();
$USERVER::q = 0;
$USERVER::children = 0;
while ( 1 )
{
sleep 1;
&SERVER::check_childs;
for (my $i = $USERVER::children; $i < $CONFIG::prefork; $i++ )
{
&make_new_child();
}
}
sub make_new_child
{
my $sigset = POSIX::SigSet->new(SIGINT);
sigprocmask(SIG_BLOCK, $sigset) or die "Не удалось заблокировать 'SIGINT' для форка: $!\n";
die "Форк: $!" unless defined ( my $pid = fork );
if ($pid)
{
sigprocmask(SIG_UNBLOCK, $sigset) or die "Не удалось разблокировать 'SIGINT' для форка: $!\n";
$logger->info('Порождён потомок, процесс сервер!'.'|'.$pid.'|');
$USERVER::childrens->{$pid} = 1;
$USERVER::children++;
return;
}
else
{
&SERVER::reset_sig_handler(['CHLD','INT','USR1','USR2']);
sigprocmask(SIG_UNBLOCK, $sigset) or die "Не удалось разблокировать 'SIGINT' для форка: $!\n";
&SERVER::check_hand_type() or &SERVER::init_application();
while ( &SERVER::accept_request() )
{
my $request = &SERVER::fetch_request();
$logger->info('Принят запрос, процесс '.'|'.$$.'|'.', запрос '.'|'.++$USERVER::q.'|');
&SERVER::call_application($request);
}
}
}