0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-26 00:19:07 -05:00

Handle EOF on websocket write/ping operations

This commit is contained in:
Andrey Antukh 2022-02-10 00:02:38 +01:00 committed by Alonso Torres
parent d358185a04
commit 3fbb440436

View file

@ -15,7 +15,9 @@
[clojure.core.async :as a] [clojure.core.async :as a]
[yetti.websocket :as yws]) [yetti.websocket :as yws])
(:import (:import
java.nio.ByteBuffer)) java.nio.ByteBuffer
org.eclipse.jetty.io.EofException))
(declare decode-beat) (declare decode-beat)
(declare encode-beat) (declare encode-beat)
@ -132,17 +134,25 @@
(defn- ws-send! (defn- ws-send!
[conn s] [conn s]
(let [ch (a/chan 1)] (let [ch (a/chan 1)]
(yws/send! conn s (fn [e] (try
(when e (a/offer! ch e)) (yws/send! conn s (fn [e]
(a/close! ch))) (when e (a/offer! ch e))
(a/close! ch)))
(catch EofException cause
(a/offer! ch cause)
(a/close! ch)))
ch)) ch))
(defn- ws-ping! (defn- ws-ping!
[conn s] [conn s]
(let [ch (a/chan 1)] (let [ch (a/chan 1)]
(yws/ping! conn s (fn [e] (try
(when e (a/offer! ch e)) (yws/ping! conn s (fn [e]
(a/close! ch))) (when e (a/offer! ch e))
(a/close! ch)))
(catch EofException cause
(a/offer! ch cause)
(a/close! ch)))
ch)) ch))
(defn- encode-beat (defn- encode-beat