Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Improve connection handling #80

Merged
merged 3 commits into from
Nov 23, 2018
Merged

Improve connection handling #80

merged 3 commits into from
Nov 23, 2018

Conversation

wiegandm
Copy link
Member

This commit improves the way connections are handled by the
handle_client_stream() method.

Previously, data from the client socket was read until a timeout was
reached after two seconds, i.e. when there was no activity from the open
client socket for two seconds. Beyond reaching this timeout or
encountering an error, there was no way to exit the while True: loop
containing the recv and read calls.

This lead to problems when a client sent data and waited less than two
seconds before closing the connection. Since the timeout was never
reached, the data.append() method continued to append bytes to the
data array indefinitely.

This commit introduces a conditional to check if any additional data was
read and to break the loop if not, i.e. all data sent by the client
was consumed.

This has the added benefit of reducing the time the client has to wait
after it is done sending by the two seconds the server previously waited
before starting to process the data.

This commit improves the way connections are handled by the
`handle_client_stream()` method.

Previously, data from the client socket was read until a timeout was
reached after two seconds, i.e. when there was no activity from the open
client socket for two seconds. Beyond reaching this timeout or
encountering an error, there was no way to exit the `while True:` loop
containing the `recv` and `read` calls.

This lead to problems when a client sent data and waited less than two
seconds before closing the connection. Since the timeout was never
reached, the `data.append()` method continued to append `bytes` to the
`data` array indefinitely.

This commit introduces a conditional to check if any additional data was
read and to `break` the loop if not, i.e. all data sent by the client
was consumed.

This has the added benefit of reducing the time the client has to wait
after it is done sending by the two seconds the server previously waited
before starting to process the data.
@wiegandm wiegandm requested a review from a team November 23, 2018 11:54
ospd/ospd.py Outdated Show resolved Hide resolved
This commit further simplifies the check for received data by inverting
the conditional and taking into account that an empty array is `False`.

It also removes the useless conditional checking the length of the
`data` array. The `data` array cannot be zero-length at this point
because at least an empty `bytes` object will have been appended to it,
resulting in a non-zero length.
@bjoernricks bjoernricks merged commit e52b6b1 into greenbone:master Nov 23, 2018
@wiegandm wiegandm deleted the connection_handling branch November 26, 2018 10:48
jjnicola added a commit that referenced this pull request Nov 28, 2018
jjnicola referenced this pull request in jjnicola/ospd Nov 28, 2018
Improve connection handling

This commit improves the way connections are handled by the
handle_client_stream() method.
jjnicola referenced this pull request in jjnicola/ospd Nov 28, 2018
Improve connection handling

This commit improves the way connections are handled by the
handle_client_stream() method.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants