8000 [HttpClient] Add stream_set_option method to StreamWrapper by mcsky · Pull Request #34969 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpClient] Add stream_set_option method to StreamWrapper #34969

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

Closed

Conversation

mcsky
Copy link
@mcsky mcsky commented Dec 13, 2019
Q A
Branch? 4.4 & 5.0
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #34943
License MIT
Doc PR -

Add the structure of the method stream_set_option which is called before usage

Currently, these methods aren't implemented, but the errors & return code are handled.

Please feel free to suggest anything, I'm nooby of streams

@mcsky mcsky force-pushed the fix/stream-wrapper-add-set-option branch 2 times, most recently from 1e94e73 to 1e114d5 Compare December 13, 2019 13:37
public function stream_set_option(int $option, int $arg1, ?int $arg2): bool
{
if (null === $this->handle || 'stream' !== get_resource_type($this->handle)) {
trigger_error(sprintf('The "$handle" property of "%s" need to be a stream.', __CLASS__), E_USER_WARNING);
Copy link
Contributor

Choose a reason for hiding this comment

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

null handler cannot occur at this point (it is when the stream is not open but you cannot call that kind of function if you don't have an openned stream?!)

Copy link
Author

Choose a reason for hiding this comment

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

$handle is null when CurlHttpClient is used, as Nicolas commented :)

Copy link
Member

Choose a reason for hiding this comment

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

s/need/needs
but since the response is set in a property, I think it would be nicer to mention it
btw, how does PHP behave when we return false? does it throw another warning on its own?

return false;
}

public function stream_set_timeout($stream, int $seconds, int $microseconds = 0): bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Those 3 functions are useless and shoud be removed. stream_set_blocking stream_set_write_buffer and stream_set_timeout

Or at least they should not be public.

Copy link
Author

Choose a reason for hiding this comment

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

They are now private. IMHO it's better to have specific little functions to handle each case.

The logic of stream_set_option function is already disturbing. ^^

Copy link
Contributor
@Nek- Nek- left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this 👍 :coeuraveclesmains:

@nicolas-grekas nicolas-grekas changed the title Add stream_set_option method with required structure. But without rea… [HttpClient] Add stream_set_option method with required structure. But without real implementations Dec 13, 2019
@mcsky mcsky force-pushed the fix/stream-wrapper-add-set-option branch from 1e114d5 to 0c93bbf Compare December 13, 2019 13:46
@nicolas-grekas
Copy link
Member

But without real implementations

why don't you call the correponding PHP function?

@mcsky mcsky force-pushed the fix/stream-wrapper-add-set-option branch from 0c93bbf to f95e5ba Compare December 13, 2019 13:55
@mcsky
Copy link
Author
mcsky commented Dec 13, 2019

You're absolutely right, this is fix. 👍

case STREAM_OPTION_READ_TIMEOUT:
return \stream_set_timeout($this->handle, $arg1, $arg2);
case STREAM_OPTION_WRITE_BUFFER:
return \stream_set_write_buffer($this->handle, $arg1);
Copy link
Member

Choose a reason for hiding this comment

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

wrong CS, see fabbot

case STREAM_OPTION_WRITE_BUFFER:
return \stream_set_write_buffer($this->handle, $arg1);
default:
trigger_error(sprintf('The option "%s" is unknown for "stream_set_option" method', $option), E_ERROR);
Copy link
Member

Choose a reason for hiding this comment

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

E_ERROR is not legal
but let's return false and remove the warning, this cannot happen in practice

@nicolas-grekas
8000 Copy link
Member

Please add a test case also.

@nicolas-grekas nicolas-grekas changed the title [HttpClient] Add stream_set_option method with required structure. But without real implementations [HttpClient] Add stream_set_option method to StreamWrapper Dec 15, 2019
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Dec 15, 2019
Nek- added a commit to Nek-/symfony that referenced this pull request Jan 2, 2020
This commit is based on the job of @mcsky
symfony#34969

With this change it allows to use a stream in a select_streams function.
(which is basics in non-blocking streams in PHP)

It adds specific errors in case the user tries to change the timeout or
the write buffer because:
1. The stream is read only (so it makes not sense to update the write
   buffer)
2. By design, we need to specify the timeout at initialization of the
   stream, not after that.
Nek- added a commit to Nek-/symfony that referenced this pull request Jan 3, 2020
This commit is based on the job of @mcsky
symfony#34969

With this change it allows using a stream in a select_streams function.
(which is basics in non-blocking streams in PHP)

It adds specific errors in case the user tries to change the timeout or
the write buffer because:
1. The stream is read only (so it makes no sense to update the write
   buffer)
2. By design, we need to specify the timeout at initialization of the
   stream, not after that.
@nicolas-grekas
Copy link
Member

Closing in favor of #35187, thanks @mcsky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HttpClient] Support for non-blocking io in streams
4 participants
0