JuliaInterop / ZMQ.jl

Julia interface to ZMQ

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

zmq_proxy and optional parameter

albestro opened this issue · comments

I'm not an expert both in Julia and zeromq and I was playing with this wrapper. My example uses the zmq_proxy, which is missing in the wrapper currently, and I managed to make it work.

I would have open a PR with a minimal proposal, but I faced an issue that I'd like to know from you Julia and ZMQ.jl experts about how to address it.

The wrapper function would be something similar to

function proxy(frontend::Socket, backend::Socket, context::Socket)
  ccall((:zmq_proxy, libzmq),
    Cint, (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
    frontend, backend, context)
end

I have a few concerns about this function per se, but the main problem keeping me away from opening a PR is the fact that context may be NULL or a Socket, and I was not able to figure out a way in the ZMQ.jl design to create a "null" Socket (e.g. I may evaluate to add an additional Socket constructor that sets data = C_NULL, but then the problem is the Socket.pollfd, which in turn I don't know anything about).

If you want to be able to pass C_NULL for context, you could just declare a separate two-argument method:

function proxy(frontend::Socket, backend::Socket)
  ccall((:zmq_proxy, libzmq),
    Cint, (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
    frontend, backend, C_NULL)
end

If you want to be able to pass C_NULL for context, you could just declare a separate two-argument method:

function proxy(frontend::Socket, backend::Socket)
  ccall((:zmq_proxy, libzmq),
    Cint, (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
    frontend, backend, C_NULL)
end

Aha! Thanks for the reply! I discarded that option because it does not follow DRY principle, but maybe it is the right way in Julia for a simple thing like this.

I will eventually open a PR with this simple proposal.
Thanks again!