use namespace HH\Lib\Experimental\{TCP, Network};
async function server(TCP\Server $server): Awaitable<void> {
$conn = await $server->nextConnectionNDAsync();
while (true) {
\var_dump('+');
$t = microtime(true);
$rest = '';
try {
\var_dump('reading :)');
$rest = await $conn->readAsync(1, 0.1);
} catch (\Throwable $e) {
\var_dump('timeout');
} finally {
$elapsed = microtime(true) - $t;
\var_dump('server left readAsync after '.$elapsed.' seconds');
}
\var_dump('~');
if ('' !== $rest) {
\var_dump('server read: '.$rest);
}
}
}
async function client(int $port): Awaitable<void> {
$conn = await TCP\connect_nd_async('127.0.0.1', $port);
await $conn->writeAsync("hello, world!");
\var_dump('gave the server some data, now going in a loop :)');
while (true) {
await \HH\Asio\later();
}
}
<<__EntryPoint>>
async function main(): Awaitable<void> {
require_once('vendor/autoload.hack');
\Facebook\AutoloadMap\initialize();
$server = await TCP\Server::createAsync(
Network\IPProtocolVersion::IPV4,
'127.0.0.1',
0,
);
list($_, $port) = $server->getLocalAddress();
concurrent {
await server($server);
await client($port);
}
;
\var_dump('End of program');
}
This hangs forever without this change.
I've not been able to make a smaller repro case, or one that's suitable
for a unit test: doing so requires < 0.5ms timing accuracy, which I've
not been able to achieve in anything simpler.
Fixes #100
Test Plan:
This hangs forever without this change.
I've not been able to make a smaller repro case, or one that's suitable for a unit test: doing so requires < 0.5ms timing accuracy, which I've not been able to achieve in anything simpler.