Skip to content

Commit

Permalink
use new ZMQ api (#729)
Browse files Browse the repository at this point in the history
* use new ZMQ api

* require ZMQ 1.0
  • Loading branch information
stevengj authored Sep 4, 2018
1 parent e946901 commit 9e4b6d9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
julia 0.7
MbedTLS 0.4.3
JSON 0.17
ZMQ 0.6.0
ZMQ 1.0.0
Compat 0.69.0
Conda 0.1.5
SoftGlobalScope
2 changes: 1 addition & 1 deletion src/heartbeat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ end
function start_heartbeat(sock)
heartbeat_c = @cfunction(heartbeat_thread, Cvoid, (Ptr{Cvoid},))
ccall(:uv_thread_create, Cint, (Ptr{Int}, Ptr{Cvoid}, Ptr{Cvoid}),
threadid, heartbeat_c, sock.data)
threadid, heartbeat_c, sock)
end
12 changes: 5 additions & 7 deletions src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function __init__()
end

# the following constants need to be initialized in init().
const ctx = Ref{Context}()
const publish = Ref{Socket}()
const raw_input = Ref{Socket}()
const requests = Ref{Socket}()
Expand Down Expand Up @@ -91,12 +90,11 @@ function init(args)
profile["key"])
end

ctx[] = Context()
publish[] = Socket(ctx[], PUB)
raw_input[] = Socket(ctx[], ROUTER)
requests[] = Socket(ctx[], ROUTER)
control[] = Socket(ctx[], ROUTER)
heartbeat[] = Socket(ctx[], ROUTER)
publish[] = Socket(PUB)
raw_input[] = Socket(ROUTER)
requests[] = Socket(ROUTER)
control[] = Socket(ROUTER)
heartbeat[] = Socket(ROUTER)
bind(publish[], "$(profile["transport"])://$(profile["ip"]):$(profile["iopub_port"])")
bind(requests[], "$(profile["transport"])://$(profile["ip"]):$(profile["shell_port"])")
bind(control[], "$(profile["transport"])://$(profile["ip"]):$(profile["control_port"])")
Expand Down
28 changes: 13 additions & 15 deletions src/msg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ function send_ipython(socket, m::Msg)
try
@vprintln("SENDING ", m)
for i in m.idents
send(socket, i, SNDMORE)
send(socket, i, more=true)
end
send(socket, "<IDS|MSG>", SNDMORE)
send(socket, "<IDS|MSG>", more=true)
header = json(m.header)
parent_header = json(m.parent_header)
metadata = json(m.metadata)
content = json(m.content)
send(socket, hmac(header, parent_header, metadata, content), SNDMORE)
send(socket, header, SNDMORE)
send(socket, parent_header, SNDMORE)
send(socket, metadata, SNDMORE)
send(socket, hmac(header, parent_header, metadata, content), more=true)
send(socket, header, more=true)
send(socket, parent_header, more=true)
send(socket, metadata, more=true)
send(socket, content)
finally
unlock(socket_locks[socket])
Expand All @@ -65,22 +65,20 @@ end
function recv_ipython(socket)
lock(socket_locks[socket])
try
msg = recv(socket)
idents = String[]
s = unsafe_string(msg)
s = recv(socket, String)
@vprintln("got msg part $s")
while s != "<IDS|MSG>"
push!(idents, s)
msg = recv(socket)
s = unsafe_string(msg)
s = recv(socket, String)
@vprintln("got msg part $s")
end
signature = unsafe_string(recv(socket))
signature = recv(socket, String)
request = Dict{String,Any}()
header = unsafe_string(recv(socket))
parent_header = unsafe_string(recv(socket))
metadata = unsafe_string(recv(socket))
content = unsafe_string(recv(socket))
header = recv(socket, String)
parent_header = recv(socket, String)
metadata = recv(socket, String)
content = recv(socket, String)
if signature != hmac(header, parent_header, metadata, content)
error("Invalid HMAC signature") # What should we do here?
end
Expand Down

0 comments on commit 9e4b6d9

Please sign in to comment.