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

ensure handshake is performed #53

Merged
merged 3 commits into from
Apr 22, 2018
Merged

Conversation

yuya373
Copy link
Contributor

@yuya373 yuya373 commented Apr 19, 2018

emacs26 pass :nowait to open-gnutls-stream but emacs25 doesn't.
emacs-26 branch on github:
https://github.com/emacs-mirror/emacs/blob/emacs-26/lisp/net/network-stream.el#L381
emacs-25 branch on github:
https://github.com/emacs-mirror/emacs/blob/emacs-25/lisp/net/network-stream.el#L354

And other open stream functions which is used when gnutls is not available
seems don't support :nowait arguments, so we should check
process-status is open or not instead of passed argument nowait.

emacs26 pass :nowait to `open-gnutls-stream` but emacs25 doesn't.
emacs-26 branch on github:
https://github.com/emacs-mirror/emacs/blob/emacs-26/lisp/net/network-stream.el#L381
emacs-25 branch on github:
https://github.com/emacs-mirror/emacs/blob/emacs-25/lisp/net/network-stream.el#L354

other open stream functions which is used when gnutls is not available
seems don't support :nowait arguments, so we should check
process-status is open or not instead of passed argument `nowait`.
yuya373 added a commit to yuya373/emacs-slack that referenced this pull request Apr 19, 2018
@ahyatt
Copy link
Owner

ahyatt commented Apr 20, 2018

Thanks for the change! Your reasoning is valid, I think. But I'm a little worried that this will mean that sometimes when clients are not setting nowait, then connection won't be guaranteed to be usable. I think we should either wait (perhaps in a retry loop?) or error out if the connection isn't open. What do you think?

@ahyatt
Copy link
Owner

ahyatt commented Apr 21, 2018

Thanks for the reply. I looked up the possible process statuses, and it would either have to be open, or closed. Either way should work here.

However, another thought occurred to me: how do we know that if nowait is true we don't try to handshake twice? The process may be open by the time we reach your change, and the sentinel should also get the change notification.

after handshake successed, websocket's ready-state is open
prevent handshake is executed when process status is connect
@yuya373
Copy link
Contributor Author

yuya373 commented Apr 21, 2018

The process may be open by the time we reach your change, and the sentinel should also get the change notification.

Thanks! I confirmed called twice.

    (set-process-sentinel
     conn
     (websocket-sentinel url conn key protocols extensions custom-header-alist nowait))
    (set-process-query-on-exit-flag conn nil)
    (sleep-for 1)
    (when (eq 'open (process-status conn))
      (websocket-handshake url conn key protocols extensions custom-header-alist))

I add (sleep-for 1) like above, websocket-handshake is called twice.

I fixed to call websocket-handshake once in 38c1f20

@ahyatt
Copy link
Owner

ahyatt commented Apr 22, 2018

Thanks! One additional suggestion: can you rename websocket-handshake to websocket-ensure-handshake, which I think is now a more accurate function name?

@yuya373
Copy link
Contributor Author

yuya373 commented Apr 22, 2018

It is more accurate name. I renamed in 607355d. Thanks!

@ahyatt ahyatt merged commit de26889 into ahyatt:master Apr 22, 2018
@yuya373 yuya373 deleted the fix-for-emacs-25 branch April 23, 2018 02:54
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.

2 participants