Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SimpleBufferStream = "777ac1f9-54b0-4bf8-805c-2214025038e7"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
TaskLocalValues = "ed4db957-447d-4319-bfb6-7fa9ae7ecf34"
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

Expand All @@ -30,6 +31,7 @@ MbedTLS = "0.6.8, 0.7, 1"
OpenSSL = "1.3"
PrecompileTools = "1.2.1"
SimpleBufferStream = "1.1"
TaskLocalValues = "0.1.2"
URIs = "1.3"
julia = "1.6"

Expand Down
8 changes: 6 additions & 2 deletions src/WebSockets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ module WebSockets

using Base64, UUIDs, Sockets, Random
using MbedTLS: digest, MD_SHA1, SSLContext
using TaskLocalValues
using ..IOExtras, ..Streams, ..Connections, ..Messages, ..Conditions, ..Servers
using ..Exceptions: current_exceptions_to_string
import ..open
import ..HTTP # for doc references

export WebSocket, send, receive, ping, pong

write_lock = ReentrantLock()

# 1st 2 bytes of a frame
primitive type FrameFlags 16 end
uint16(x::FrameFlags) = Base.bitcast(UInt16, x)
Expand Down Expand Up @@ -180,7 +183,6 @@ function readframe(io::IO, ::Type{Frame}, buffer::Vector{UInt8}=UInt8[], first_f
return Frame(flags, extlen, mask, payload)
end

# writing a single frame
function writeframe(io::IO, x::Frame)
buff = IOBuffer()
n = write(buff, hton(uint16(x.flags)))
Expand All @@ -199,7 +201,9 @@ function writeframe(io::IO, x::Frame)
else
n += write(buff, pl)
end
write(io.io, take!(buff))
lock(write_lock) do
write(io.io, take!(buff))
end
return n
end

Expand Down
Loading