File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -48,13 +48,16 @@ class HTTP::WebSocket::Protocol
4848 end
4949
5050 class StreamIO < IO
51+ getter closed? = false
52+
5153 def initialize (@websocket : Protocol , binary, frame_size)
5254 @opcode = binary ? Opcode ::BINARY : Opcode ::TEXT
5355 @buffer = Bytes .new(frame_size)
5456 @pos = 0
5557 end
5658
5759 def write (slice : Bytes ) : Nil
60+ check_open
5861 return if slice.empty?
5962
6063 count = Math .min(@buffer .size - @pos , slice.size)
@@ -74,11 +77,6 @@ class HTTP::WebSocket::Protocol
7477 raise " This IO is write-only"
7578 end
7679
77- def flush : Nil
78- # StreamIO is used to split one message into the necessary frames. There
79- # should be no need for the caller to try to control this by flushing.
80- end
81-
8280 private def send_frame (final = false ) : Nil
8381 @websocket .send(
8482 @buffer [0 ...@pos ],
@@ -90,7 +88,10 @@ class HTTP::WebSocket::Protocol
9088 @pos = 0
9189 end
9290
91+
9392 def close
93+ return if closed?
94+ @closed = true
9495 send_frame(final: true )
9596 end
9697 end
You can’t perform that action at this time.
0 commit comments