-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 WebSocket and SSE options #1272
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fb6a756
Add WebSocket and SSE options
ohler55 42d535a
Don't use extend for push handler
ohler55 cb84901
Add client to on_message
ohler55 975acaa
client on all upgrade handler callbacks
ohler55 a742739
slight wording change
ohler55 0f047d3
Cleanup formatting
ohler55 7d15187
Add client env method
ohler55 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
After reading through @ioquatix and @matthewd 's comments, I wonder:
Perhaps
close()
should "schedule the connection to close once all pendingwrite
calls have been performed"?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.
If you want to have that, implement it as
close_write
which is what Ruby callsshutdown(SHUT_WR)
.close
should guarantee after returning that the underlying socket is closed. Otherwise, you are in for a world of pain.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.
Agoo treats a cal to close as a request just like a write and places the close on the queue.
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.
@ohler55, so does iodine. I place a "close" marker on the packet queue, so
close
is always performed after all scheduled data is sent.@ioquatix , I think your missing the point of abstracting away the network and the protocol.
My suggestion was about clarifying this little bit, not changing what both iodine and agoo already implement.
We aren't authoring a network layer. We are authoring an abstracted application side API.
The reasonable exception is that
write
is performed beforeclose
. i.e., if my code is:The reasonable expectation is that "hello" is actually written.
There's no
force_close
orclose_write
in the specification because the application shouldn't be concerned with these things. If the application doesn't want data written, it can avoid writing it.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.
You can make close call
flush
, or you can flush after every write. But you make close call flush, you better be careful aboutEPIPE
.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.
For a high level protocol like this, calling flush after each write would make sense to me.
It provides the user with a strong expectation, that after calling write, the data has been sent, and pending a network failure, would arrive, or else the write fails right then, with, say,
EPIPE
. Otherwise you'll just end up with a spaghetti state machine trying to handle all these conditions.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.
@ioquatix ,
I hope I don't seem too blunt or crude. I very much appreciate the interest and willingness to polish the specification and make it both as clear and as practical as can be.
However, please consider the model to be totally separate from the network - there is no network. There's only this API.
We can change the API if we need features, but we don't expose network bits or logic because part of our job is to abstract these things away - so there is no network, there is no protocol (as much as possible).
In this sense,
flush
doesn't exist. It's a network / server detail that the application never sees, abstracted away by the server.The closest an application can come to ask about these things is to ask about all the
pending
outgoingwrite
events that haven't yet completed. This allows an application to know if theon_drain
callback is somewhere in their future.The
pending
query doesn't to expose the network, it exposes the progress of existing API calls. This provides important information about the possibility of a slow client (or a slow clearing "queue") allowing an application to stop serving a resource hungry "client".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.
If I understand your response you are answering yes to the question of whether or not a
flush
method should be added. Then in any application you wrote you would block until the write completes instead of making use of theon_drained
callback. That is your choice of course.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.
Fair enough.
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.
I really find the inverted flow control of callback style programming horrible. So, I prefer
#flush
over an#on_drained
callback. Callbacks = state machine spaghetti = hard to maintain/buggy code. It's just my personal opinion, FYI.