Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Sockets dependency/namespace insertion #190

Closed
wants to merge 2 commits into from
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
7 changes: 2 additions & 5 deletions src/ZMQ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Libdl
using Base.Libc: EAGAIN
using FileWatching: UV_READABLE, uv_pollcb, _FDWatcher
import Sockets
using Sockets: connect, bind, send, recv
import Base.GC: @preserve

const depsjl_path = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
Expand All @@ -19,11 +18,9 @@ export
#Types
StateError,Context,Socket,Message,
#functions
set, subscribe, unsubscribe,
set, subscribe, unsubscribe, connect, bind, send, recv,
#Constants
IO_THREADS,MAX_SOCKETS,PAIR,PUB,SUB,REQ,REP,ROUTER,DEALER,PULL,PUSH,XPUB,XSUB,XREQ,XREP,UPSTREAM,DOWNSTREAM,MORE,POLLIN,POLLOUT,POLLERR,STREAMER,FORWARDER,QUEUE,SNDMORE,
#Sockets
connect, bind, send, recv
IO_THREADS,MAX_SOCKETS,PAIR,PUB,SUB,REQ,REP,ROUTER,DEALER,PULL,PUSH,XPUB,XSUB,XREQ,XREP,UPSTREAM,DOWNSTREAM,MORE,POLLIN,POLLOUT,POLLERR,STREAMER,FORWARDER,QUEUE,SNDMORE


include("constants.jl")
Expand Down
29 changes: 23 additions & 6 deletions src/comm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ to indicate that `data` is a portion of a larger multipart message.
`String`, or a [`Message`](@ref) object to perform zero-copy sends
of large arrays.
"""
function Sockets.send(socket::Socket, data; more::Bool=false)
function send(socket::Socket, data; more::Bool=false)
zmsg = _MessageRef(data)
try
_send(socket, zmsg, more)
Expand All @@ -48,13 +48,20 @@ function Sockets.send(socket::Socket, data; more::Bool=false)
end
end

function Sockets.send(socket::Socket, data; more::Bool=false)
depwarn("Sockets.send(socket::Socket, data; more::Bool) is deprecated, use send(socket::Socket, data; more::Bool=false) instead.", nothing)
send(socket, data, more=more)
end

# zero-copy version using user-allocated Message
Sockets.send(socket::Socket, zmsg::Message; more::Bool=false) = _send(socket, zmsg, more)
send(socket::Socket, zmsg::Message; more::Bool=false) = _send(socket, zmsg, more)
function Sockets.send(socket::Socket, zmsg::Message; more::Bool=false)
depwarn("Sockets.send(socket::Socket, zmsg::Message; more::Bool=false) is deprecated, use send(socket::Socket, zmsg::Message; more::Bool=false) instead.", nothing)
end

import Sockets: send
@deprecate send(socket::Socket, data, more::Bool) send(socket, data; more=more)

function Sockets.send(f::Function, socket::Socket; more::Bool=false)
function send(f::Function, socket::Socket; more::Bool=false)
io = IOBuffer()
f(io)
send(socket, take!(io); more=more)
Expand Down Expand Up @@ -91,7 +98,11 @@ end
Return a `Message` object representing a message received from a ZMQ `Socket`
(without making a copy of the message data).
"""
Sockets.recv(socket::Socket) = _recv!(socket, Message())
recv(socket::Socket) = _recv!(socket, Message())
function Sockets.recv(socket::Socket)
depwarn("Sockets.recv(socket::Socket) is deprecated, use recv(socket::Socket) instead.", nothing)
recv(socket::Socket)
end

"""
recv(socket::Socket, ::Type{T})
Expand All @@ -100,7 +111,7 @@ Receive a message of type `T` (typically a `String`, `Vector{UInt8}`, or [`isbit
from a ZMQ `Socket`. (Makes a copy of the message data; you can alternatively use
`recv(socket)` to work with zero-copy bytearray-like representation for large messages.)
"""
function Sockets.recv(socket::Socket, ::Type{T}) where {T}
function recv(socket::Socket, ::Type{T}) where {T}
zmsg = msg_init()
try
_recv!(socket, zmsg)
Expand All @@ -109,3 +120,9 @@ function Sockets.recv(socket::Socket, ::Type{T}) where {T}
close(zmsg)
end
end

function Sockets.recv(socket::Socket, t::Type{T}) where {T}
depwarn("Sockets.recv(socket::Socket, ::Type{T}) where {T} is deprecated, use recv(socket::Socket, ::Type{T}) where {T}
instead.", nothing)
recv(socket, t)
end
15 changes: 12 additions & 3 deletions src/socket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,25 @@ end
Base.wait(socket::Socket) = wait(getfield(socket, :pollfd), readable=true, writable=false)
Base.notify(socket::Socket) = @preserve socket uv_pollcb(getfield(socket, :pollfd).handle, Int32(0), Int32(UV_READABLE))

function Sockets.bind(socket::Socket, endpoint::AbstractString)
function bind(socket::Socket, endpoint::AbstractString)
rc = ccall((:zmq_bind, libzmq), Cint, (Ptr{Cvoid}, Ptr{UInt8}), socket, endpoint)
if rc != 0
throw(StateError(jl_zmq_error_str()))
end
end
function Sockets.bind(socket::Socket, endpoint::AbstractString)
depwarn("Sockets.bind(socket::Socket, endpoint::AbstractString) is deprecated, use bind(socket::Socket, endpoint::AbstractString) insead.", nothing)
bind(socket, endpoint)
end

function Sockets.connect(socket::Socket, endpoint::AbstractString)
function connect(socket::Socket, endpoint::AbstractString)
rc=ccall((:zmq_connect, libzmq), Cint, (Ptr{Cvoid}, Ptr{UInt8}), socket, endpoint)
if rc != 0
throw(StateError(jl_zmq_error_str()))
end
end
end

function Sockets.connect(socket::Socket, endpoint::AbstractString)
depwarn("Sockets.connect(socket::Socket, endpoint::AbstractString) is deprecated, use connect(socket::Socket, endpoint::AbstractString) insead.", nothing)
connect(socket, endpoint)
end