Skip to content

Commit

Permalink
throw error if client disconnects while reading
Browse files Browse the repository at this point in the history
  • Loading branch information
jebej authored Dec 18, 2016
1 parent 872977e commit 9bd583b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/WebSockets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ else
init_socket(sock) = Base.buffer_writes(sock) # Buffer writes to socket till flush(sock)
end

type WebSocketClosedError <: Exception end
Base.showerror(io::IO, e::WebSocketClosedError) = print(io, "Error: client disconnected")

# A WebSocket is a wrapper over a TcpSocket. It takes care of wrapping outgoing
# data in a frame and unwrapping (and concatenating) incoming data.
type WebSocket
Expand Down Expand Up @@ -247,7 +250,8 @@ function handle_control_frame(ws::WebSocket,wsf::WebSocketFragment)
# Reply with an empty CLOSE frame
locked_write(ws.socket, true, "", OPCODE_CLOSE)
ws.is_closed = true
wait(ws.socket.closenotify)
close(ws.socket)
throw(WebSocketClosedError())
elseif wsf.opcode == OPCODE_PING
write_pong(ws.socket,wsf.data)
elseif wsf.opcode == OPCODE_PONG
Expand Down

0 comments on commit 9bd583b

Please sign in to comment.