Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Group: Allow connections to be added or removed on-the-fly #39

Open
Savageman opened this issue Mar 18, 2016 · 6 comments
Open

Group: Allow connections to be added or removed on-the-fly #39

Savageman opened this issue Mar 18, 2016 · 6 comments

Comments

@Savageman
Copy link
Member

Currently if we merge connections after the run, they don't seem to be listened.

@Hywan Hywan changed the title [Feature] Allow connections to be added / removed on the fly in Connection\Group Group: Allow connections to be added or removed on-the-fly Mar 19, 2016
@Hywan
Copy link
Member

Hywan commented Mar 19, 2016

Please, explain how do you do that :-). I reckon this is not possible but I woud like to know how do you run and add at the same time.

@Savageman
Copy link
Member Author

Currently it's not possible with Hoa, it's a feature request: I'd like to be able to do it :)

@Hywan
Copy link
Member

Hywan commented Mar 23, 2016

Removing is hard because connections are “merged”, but this is still possible to undo this

/**
* Merge a connection into this one.
* If we have two connections that must run at the same time, the
* Hoa\Socket\Connection::consider() and Hoa\Socket\Connection::is() methods
* are helpful but this whole class eases the merge of “high-level”
* connections.
*
* @param \Hoa\Socket\Connection\Handler $other Connection to merge.
* @return \Hoa\Socket\Connection\Handler
*/
public function merge(self $other)
{
$thisConnection = $this->getConnection();
$otherConnection = $other->getConnection();
$thisConnection->consider($otherConnection);
if ($otherConnection instanceof Socket\Server) {
$other->setConnection($thisConnection);
}
$this->_connections[] = $other;
return $this;
}
and this https://github.com/hoaproject/Socket/blob/master/Server.php#L364-L392 (this one is difficult) and https://github.com/hoaproject/Socket/blob/master/Client.php#L246-L272.

Adding should already work I think.

Why would you like to remove a connection? If you close it, it's OK, isn't it? I understand your needs, I am just looking for a workaround.

@Savageman
Copy link
Member Author

Maybe the Connection\Group is designed weirdly. It looks like Connection classes (both Client and Server) have code to manage multiple connections with consider(). Maybe this is too much responsibility and it would be easier to isolate this part into the Connection\Handler class only?

@Hywan
Copy link
Member

Hywan commented Apr 1, 2016

Nop. Actually, the design seems weird because of the select API. We have to merge connections into a single one, this is why a connection must consider/be aware of another one. Adding a connection at runtime is easy I think, but removing one would require several tests and could cause many data races (a lot of null value). This is a long time development. I will modify my planning to find a period to work on this feature. Not sure I could provide it in the next months. Is it urgent?

@Savageman
Copy link
Member Author

No, don't bother it's not urgent. We already developed our system with another library, but we were evaluating other libraries to migrate (the one we use it's not working with PHP 7).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants