-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
1e94e73
to
1e114d5
Compare
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); |
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.
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?!)
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.
$handle
is null when CurlHttpClient
is used, as Nicolas commented :)
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.
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 |
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.
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.
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.
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. ^^
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.
Thanks for fixing this 👍 :coeuraveclesmains:
1e114d5
to
0c93bbf
Compare
why don't you call the correponding PHP function? |
…l implementations
0c93bbf
to
f95e5ba
Compare
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); |
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.
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); |
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.
E_ERROR is not legal
but let's return false and remove the warning, this cannot happen in practice
Please add a test case also. |
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.
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.
4.4
&5.0
Add the structure of the method
stream_set_option
which is called before usageCurrently, these methods aren't implemented, but the errors &
return code
are handled.Please feel free to suggest anything, I'm nooby of streams