Thread fork() & Variablen mitübernehmen (32 answers)
Opened by Sascha2018 at 2017-08-09 07:50

Sascha2018
 2017-08-13 13:18
#187234 #187234
User since
2017-08-05
51 Artikel
BenutzerIn
[default_avatar]
Was könnte an diesem Code falsch sein ? Wie gesagt es klappt nicht mit start_SSL da bekomme ich nur folgende Meldung:

Code: (dl )
1
2
3
DEBUG: .../IO/Socket/SSL.pm:1492: new ctx 32253824
DEBUG: .../IO/Socket/SSL.pm:938: start handshake
DEBUG: .../IO/Socket/SSL.pm:505: starting sslifying


Und ich bekomme einfach keinen Handshake zustande :-(

Code: (dl )
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
use strict;
use warnings;
use feature 'state';

no strict 'refs';


my %lkup;
our %config;
our %language;
our $dbh;

our %srv_modes;
our $HOST = $config{server};
our $PORT = $config{port};
our $last_RnR = time;
our $last_UPDATE = time;
our( %srvban, %loggedin, %rooms) = ((),(),(),());
my $uid;
my $die = 0;


require "config.cfg";
require 5.002;
use IO::Socket::SSL 'inet4';
use IO::Select;
$IO::Socket::SSL::DEBUG = 3;
use Time::HiRes;
use HTML::Template;
use Text::Wrap;
use Fcntl ':flock';
use strict;
no strict 'refs';
$SIG{INT} = sub{ exit; };

use Parallel::ForkManager;

$|=1;

sub _uid {
state $uid = 0;
$uid = 1 if ++$uid > 2e9;
$uid;
}


my %clients = ();
my $select = IO::Select->new;

my $server = IO::Socket::INET->new(
LocalHost => 'host',
LocalPort => 63027,
Proto => 'tcp',
Listen => 10000,
Reuse => 1,
) or die "Sock Error: $!\n";

my $pm = Parallel::ForkManager->new(500);
$pm->set_waitpid_blocking_sleep(0);

$pm->run_on_finish( sub {
my ($pid,$exitcode,$ident,$exitsignal,$coredump,$get) = @_;
$clients{$ident}->{ident} = $ident;
$clients{$ident}->{ip} = $get->{ip};
$clients{$ident}->{socket} = delete $lkup{$ident};
my $killsock = $get->{killing} || 0;
my $sock = $clients{$ident}->{socket};
if($killsock){
delete $clients{$ident};
$select->remove($sock);
}
});

$server->autoflush(1);
$select->add($server);

while (1) {
foreach my $key ($select->can_read()) { # foreach
if ($key eq $server) { # if $bay eq $server
next if $key eq "";

our $bay = $server->accept or next;
my $ip = $bay->peerhost();
our $ident = _uid();

$lkup{$ident} = $bay;
$select->add($bay);
my $buffer = <$bay>;
$pm->start($ident) and next;
IO::Socket::SSL->start_SSL($bay,
PeerAddr => $config{server},
SSL_verify_mode => SSL_VERIFY_PEER,
verify_hostname => 1,
SSL_hostname => $config{server},
SSL_port => $PORT,
SSL_server => 1,
SSL_ca_file => $config{ca_file},
SSL_ca_path => $config{ca_path},
SSL_verifycn_name => 'host',
SSL_verifycn_scheme => 'http',
SSL_cert_file => $config{cert_file},
SSL_key_file => $config{key_file},
) or die "SSL accept failed: $SSL_ERROR";
my $killing = 0;

if( defined $buffer && $buffer =~ m/^GET\s\/\?sid=12\sHTTP\/1\.1\s/ ){
print "$buffer";
sendHeader($bay);
print "OK";
for( 1 .. 30 ){ # Firefox and other browsers
$bay->syswrite("<!-- //--><!-- //--><!-- //--><!-- //--><!-- //-->\n\n");
}
my $html=<<"EOT";
<html>
<head>
<title>hallo</title>
</head>
<body style='background-color: darkblue; color: #FFFFFF'>
hello world
</body>
</html>
EOT

$bay->syswrite($html);
}elsif( defined $buffer && $buffer =~ m/^GET\s\/\?printoall=1\sHTTP\/1\.1\s/ ){
foreach my $client( keys %clients ){
print "$buffer";
my $socket = $clients{$client}->{socket};
$socket->syswrite("The sun is shining\n");
print "Conntected: \n" . keys %clients;

}
$killing = 1;
}

$pm->finish(0, { ip => $ip, killing => $killing });
}
}

$pm->wait_all_children;
}

sub sendHeader {
my $client = shift;
if( defined $client ) {
my $header =<<"EOT";
HTTP/1.1 200 OK
Content-type: text/html\n\n
EOT
$client->syswrite($header);
}
}

View full thread fork() & Variablen mitübernehmen