8000 Setting enable disable ipv6 by drSychev · Pull Request #1187 · php-amqplib/php-amqplib · GitHub
[go: up one dir, main page]

Skip to content

Setting enable disable ipv6 #1187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

drSychev
Copy link
@drSychev drSychev commented Jul 25, 2024

No description provided.

@ramunasd
Copy link
Member

Thanks for Your contribution. This not neccessary solves issue 1169, please remove that tag. Also, we'd like to ask for some improvement.

* Const AF_INET6 IPv6 Internet based protocols.<br>
* null Auto select
*/
private $socketProtocolMode = null;
Copy link
Member
8000

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's probably simply socketProtocol? word mode is redundant here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the mode because if you do not install the protocol, automatic will be selected

*/
public function setSocketProtocolMode(?int $socketProtocolMode): void
{
$this->socketProtocolMode = $socketProtocolMode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows to set any integer, while valid values are only 2?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->sock = socket_create(!$this->isIpv6() ? AF_INET : AF_INET6, SOCK_STREAM, SOL_TCP);

Yes, function socket_create will give an error "socket_create(): Argument #1 ($domain) must be one of AF_UNIX, AF_INET6, or AF_INET"

@@ -60,7 +60,7 @@ public function __construct(
*/
public function connect()
{
$this->sock = socket_create(!$this->isIpv6() ? AF_INET : AF_INET6, SOCK_STREAM, SOL_TCP);
$this->sock = socket_create($this->selectProtocol(), SOCK_STREAM, SOL_TCP);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe getProtocol() ?

@@ -314,6 +314,15 @@ protected function setErrorHandler(): void
socket_clear_error($this->sock);
}

private function selectProtocol() :int
{
if (is_null($this->config) || is_null($this->config->getSocketProtocolMode())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we improve readability here?

if ($this->config && $this->config->getSocketProtocol()){
return $this->config->getSocketProtocol();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using a simple flag forcing the AF_INET instead of selecting the version by hand ?

It will probably be easier to understand. What do you think ?

public function force_connect_ipv4()
{
$config = new AMQPConnectionConfig();
$config->setSocketProtocolMode(AF_INET);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we remove this line, tests won't fail. Seems test case is not testing this feature.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm new to test. Can your help my in wraiting tests?

Copy link
@jworreth jworreth Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add that:

To be run, your two added functions must have the below headers:

    /**
     * @test
     */

In fact the test will also succeed if you put HOST6 with AF_INET configuration. Or even HOST with AF_INET6.
I am not sure this is a "testable" feature by the way it is done in the code.

@drSychev drSychev requested a review from ramunasd July 31, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0