-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Properly format IPv6 addresses and return null for unknown addresses #14
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason for omitting the
$this->socket !== false
now?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several occasions where the
stream_socket_get_name()
call may emit a warning and unfortunately this is not reliable across different PHP versions and HHVM. Besides, thesocket
property can accessed from outside of this class so that thefalse
check is simply not reliable either.I've removed the check completely for consistency with the Socket component and simply discard any error messages from this call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my suggestion was not to remove
@
from thestream_socket_get_name
call again. I've been just curious if there are any consequences to potentially callstream_socket_get_name
withfalse
(or anything which isn't a resource).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all covered by the test suite and we now make sure to either return the correct address string or
null
if it's unknown. Here's how this works under the hood:This uses a client socket for simplicity, the server socket emits similar errors but has far more error situations, e.g. the server socket does not have a remote address and returns
false
without emitting an error (unless you're on HHVM).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, i'm aware that
stream_socket_get_name
would return false for non-resources, but we're relying now on PHP triggering a warning.I also noticed, that i looks like being more inconsistent as before.
stream_socket_get_name
called without@
.is_resource()
checkfalse
checkNote, that i'm reviewing without too much knowledge about the internals, so my comments are not meant to block a merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, I actually appreciate these kind of discussions :-)
This PR makes it so that we ignore any warnings (which are unreliable) and simply rely on the function returning
false
(which is documented behavior and works reliably across different PHP versions and HHVM). This is covered by both our test suite and the above gist.Once this PR is in, the behavior is consistent throughout the Datagram component.
It is currently not consistent with regards to the Socket component. As you rightfully pointed out, the Socket component does currently not implement any checks and does not suppress any errors either. This means that this does in fact error out when one tries to access to remote address after the socket has been closed. See also reactphp/socket#19, for which I've prepared a PR that I'll file once reactphp/socket#61 is in 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the reference, here's the promised follow-up PR: reactphp/socket#63 👍