<?php
}
}
}
$write = $except = $clients = $readBuffer = $writeBuffer = array();
while (true) {
throw new Exception('socket_accept() failed: '
}
$clients[intval($conn)] = $conn; $readBuffer[intval($conn)] = ""; $writeBuffer[intval($conn)] = 0; }
foreach ($read as $r) {
if ($r == $server) continue;
/*throw new Exception( 'socket_read failed: '
. socket_strerror(socket_last_error()) );*/
/* То ли клиент отсоединился, то ли ошибка */
);
foreach ($clients as $client) {
if ($client === $r) continue;
$writeBuffer[intval($client)] += $written; }
} else {
$readBuffer[intval($r)] .= $data; }
}
$read = $clients;
$write = $clients;
$read[] = $server;
}
PD9waHAKCmlmICggISRzZXJ2ZXIgPSBzb2NrZXRfY3JlYXRlKEFGX0lORVQsIFNPQ0tfU1RSRUFNLCBTT0xfVENQKSApIHsKICAgIHRocm93IG5ldyBFeGNlcHRpb24oJ3NvY2tldF9jcmVhdGUgZmFpbGVkOiAnIC4gc29ja2V0X3N0cmVycm9yKHNvY2tldF9sYXN0X2Vycm9yKCkpICk7Cn0KaWYgKCEkc2IgPSBzb2NrZXRfYmluZCgkc2VydmVyLCAnMC4wLjAuMCcsIDgwODEpICkgewogICAgdGhyb3cgbmV3IEV4Y2VwdGlvbignc29ja2V0X2JpbmQgZmFpbGVkOiAnIC4gc29ja2V0X3N0cmVycm9yKHNvY2tldF9sYXN0X2Vycm9yKCkpICk7Cn0KaWYgKCEkc2wgPSBzb2NrZXRfbGlzdGVuKCRzZXJ2ZXIsIDEyOCkpIHsKICAgIHRocm93IG5ldyBFeGNlcHRpb24oJ3NvY2tldF9saXN0ZW4gZmFpbGVkOiAnIC4gc29ja2V0X3N0cmVycm9yKHNvY2tldF9sYXN0X2Vycm9yKCkpKTsKfQoKJHJlYWQgPSBhcnJheSgkc2VydmVyKTsKJHdyaXRlID0gJGV4Y2VwdCA9ICRjbGllbnRzID0gJHJlYWRCdWZmZXIgPSAkd3JpdGVCdWZmZXIgPSBhcnJheSgpOwoKd2hpbGUgKHRydWUpIHsKICAgIHNvY2tldF9zZWxlY3QoJHJlYWQsICR3cml0ZSwgJGV4Y2VwdCwgbnVsbCk7CiAgICBpZiAoaW5fYXJyYXkoJHNlcnZlciwgJHJlYWQpKSB7CiAgICAgICAgaWYgKCAoJGNvbm4gPSBzb2NrZXRfYWNjZXB0KCRzZXJ2ZXIpKSA8IDAgKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFeGNlcHRpb24oJ3NvY2tldF9hY2NlcHQoKSBmYWlsZWQ6ICcKICAgICAgICAgICAgICAgIC4gc29ja2V0X3N0cmVycm9yKHNvY2tldF9sYXN0X2Vycm9yKCkpICk7CiAgICAgICAgfQogICAgICAgIHNvY2tldF9zZXRfbm9uYmxvY2soJGNvbm4pOwogICAgICAgICRjbGllbnRzW2ludHZhbCgkY29ubildID0gJGNvbm47CiAgICAgICAgJHJlYWRCdWZmZXJbaW50dmFsKCRjb25uKV0gPSAiIjsKICAgICAgICAkd3JpdGVCdWZmZXJbaW50dmFsKCRjb25uKV0gPSAwOwogICAgfQogICAgZm9yZWFjaCAoJHJlYWQgYXMgJHIpIHsKICAgICAgICBpZiAoJHIgPT0gJHNlcnZlcikgY29udGludWU7CiAgICAgICAgaWYgKGZhbHNlID09PSAoJGRhdGEgPSBzb2NrZXRfcmVhZCgkciwgMTAyNCkpICkgewogICAgICAgICAgICAvKnRocm93IG5ldyBFeGNlcHRpb24oICdzb2NrZXRfcmVhZCBmYWlsZWQ6ICcKICAgICAgICAgICAgICAgIC4gc29ja2V0X3N0cmVycm9yKHNvY2tldF9sYXN0X2Vycm9yKCkpICk7Ki8KICAgICAgICAgICAgLyog0KLQviDQu9C4INC60LvQuNC10L3RgiDQvtGC0YHQvtC10LTQuNC90LjQu9GB0Y8sINGC0L4g0LvQuCDQvtGI0LjQsdC60LAgKi8KICAgICAgICAgICAgdW5zZXQoCiAgICAgICAgICAgICAgICAkcmVhZEJ1ZmZlcltpbnR2YWwoJHIpXSwKICAgICAgICAgICAgICAgICR3cml0ZUJ1ZmZlcltpbnR2YWwoJHIpXSwKICAgICAgICAgICAgICAgICRjbGllbnRzW2ludHZhbCgkcildCiAgICAgICAgICAgICk7CiAgICAgICAgfSBlbHNlaWYgKGZlb2YoJHIpKSB7CiAgICAgICAgICAgIGZvcmVhY2ggKCRjbGllbnRzIGFzICRjbGllbnQpIHsKICAgICAgICAgICAgICAgIGlmICgkY2xpZW50ID09PSAkcikgY29udGludWU7CiAgICAgICAgICAgICAgICAkd3JpdHRlbiA9IHNvY2tldF93cml0ZSgkY2xpZW50LCAidXNlciAiIC4gaW50dmFsKCRyKSAuICI6ICIKICAgICAgICAgICAgICAgICAgICAuIHN1YnN0cigkcmVhZEJ1ZmZlcltpbnR2YWwoJHIpXSwgJHdyaXRlQnVmZmVyW2ludHZhbCgkY2xpZW50KV0pICk7CiAgICAgICAgICAgICAgICAkd3JpdGVCdWZmZXJbaW50dmFsKCRjbGllbnQpXSArPSAkd3JpdHRlbjsKICAgICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICRyZWFkQnVmZmVyW2ludHZhbCgkcildIC49ICRkYXRhOwogICAgICAgIH0KICAgIH0KICAgICRyZWFkID0gJGNsaWVudHM7CiAgICAkd3JpdGUgPSAkY2xpZW50czsKICAgICRyZWFkW10gPSAkc2VydmVyOwp9