Skip to content

Clean up temporal dependence #19

@clue

Description

@clue

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();

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy