Skip to content

Fixed typo, that made the blocking socket mode unconfigurable #139

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
wants to merge 3 commits into from

Conversation

alysdal
Copy link

@alysdal alysdal commented Jan 10, 2023

Related: #133

@Namoshek Namoshek added the bug Something isn't working label Jan 10, 2023
@Namoshek
Copy link
Collaborator

Mh, the fix is not as simple as it seems. The tests I've added are obviously false-positives, but now with the fix they actually show that blocking sockets do not work as expected. I'll need to look into this in more detail...

@alysdal
Copy link
Author

alysdal commented Jan 10, 2023

I was able to solve my issue by creating 2 clients:

  1. One client using blocking socket for publishing the large message and,
  2. One client using non blocking socket for subscribing to updates for the device.

I did not manage to get the blocking socket client to loop. But as I understood the settings comment it would not work anyway:

    /**
     * Whether to use a blocking socket or not. By default, the socket is non-blocking,
     * which is required when using subscriptions and/or {@see MqttClient::loop()}.
     * In rare cases, it might be required to use a blocking socket though. One such example
     * is when sending large messages (e.g. binaries) and the broker has a limited receive buffer.
     *
     * Note: When using a blocking socket, the MQTT client can get stuck if the socket is broken
     *       or when the broker does not consume the sent data fast enough. Use with caution.
     *
     * @param bool $useBlockingSocket
     * @return ConnectionSettings
     */
    public function useBlockingSocket(bool $useBlockingSocket): ConnectionSettings

@Namoshek
Copy link
Collaborator

Yes, you understood the description correctly. It is not a good idea to use blocking sockets in combination with subscriptions because it will make the client wait for data on the socket during each loop, which can cause timeouts if the broker does not send data frequently.

Using a blocking socket globally (and running the test suite successfully) seems impossible, but I'm thinking about temporarily setting a socket to blocking mode in writeToSocket($data, $length) if requested in the connection settings. I'm just not sure how good and fast changing the blocking mode really is, I couldn't find a good answer to that question.

@Namoshek
Copy link
Collaborator

@alysdal Can you please have a look at #141 and give me feedback whether that fix works for you?

@Namoshek Namoshek closed this Jan 10, 2023
@alysdal
Copy link
Author

alysdal commented Jan 10, 2023

I will check tomorrow. Thanks for already providing a fix :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants