Skip to content
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

Add server:connections() #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sparked435
Copy link

Adds :connections() method to http.server objects, so that external code can see how many client connections are actively being handled.

A project needed this for statistics and load balancing.

@coveralls
Copy link

coveralls commented Sep 29, 2020

Coverage Status

Coverage increased (+0.004%) to 87.785% when pulling aaae464 on sparked435:master into 47225d0 on daurnimator:master.

@daurnimator
Copy link
Owner

The method name :connections() to me suggests an iterator over connections, rather than something that returns a count.

Maybe the existing field .n_connections could just be documented as part of public API?

@sparked435
Copy link
Author

That works fine for me.

I assumed that it was a private field that shouldn't be utilized out of fear breaking encapsulation. If that's not a concern, and n_connections can be assumed to be part of the public API going forward, I've already got everything I need in the existing release. I can amend this to just a documentation change.

I'm also okay with renaming it to something like :connection_count(), or just about anything else, if encapsulation is something to worry about.

Copy link
Owner

@daurnimator daurnimator left a comment

Choose a reason for hiding this comment

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

Upon reflection, I think its a bad idea to make the field public and there should be a getter method.

However, I don't like the function :connections() as it suggests an iterator to me.
Can you think of a different name?

@sparked435
Copy link
Author

I'm not particularly concerned about the name. I probably would call it active_connections() but, to your point, that still sounds somewhat like an iterator.

Any of these work for you?
number_connections()
connection_count()
total_connections()

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

Successfully merging this pull request may close these issues.

3 participants