The current socket API exhibits a temporal dependence:
$server = new Server($loop);
$server->listen(1234);
$server->getPort();
$server->on('connection', function () { });
$server->shutdown();
- What happens if you call
listen() twice?
It's tempting to think that this will allow you to listen on two addresses – it does not.
- What happens if you call
shutdown() twice or before calling listen()?
Errors out – should probably be ignored
- What happens if you call
getPort() before calling listen() or after calling shutdown()?
Errors out – should probably be ignored
- What happens if you call
listen() after calling shutdown()?
Should work, but makes for an awkward API.
Afaict most of this boils down to this:
- What does a
Server instance actually represent?
Honestly, I'm not sure how to answer this. Once listen() has been called, it represents a "server socket", but until then?
Afaict most of these issues can be avoided if a Server instance always were to represent a "server socket" (which is possibly in a closed state). This means that the listen call would have to be part of the construction.
One possible API could look like this:
$server = $api->createServer(1234);
$server->getPort();
$server->on('connection', function() { });
$server->shutdown();