Skip to content

Commit

Permalink
Merge pull request #62 from JuliaWeb/tan/misc
Browse files Browse the repository at this point in the history
allow port reuse on HTTP end
  • Loading branch information
tanmaykm authored Oct 16, 2017
2 parents c1c0355 + 83e0776 commit 41cd5c1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/http_rpc_server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@ immutable HttpRpcServer{T,F}
server::Server
end

function reusable_tcpserver()
tcp = Base.TCPServer(Base.Libc.malloc(Base._sizeof_uv_tcp), Base.StatusUninit)
err = ccall(:uv_tcp_init_ex, Cint, (Ptr{Void}, Ptr{Void}, Cuint),
Base.eventloop(), tcp.handle, 2)
Base.uv_error("failed to create tcp server", err)
tcp.status = Base.StatusInit

rc = ccall(:jl_tcp_reuseport, Int32, (Ptr{Void},), tcp.handle)
if rc == 0
Logging.info("Reusing TCP port")
else
Logging.warn("Unable to reuse TCP port, error:", rc)
end
return tcp
end

HttpRpcServer{T,F}(api::APIInvoker{T,F}, preproc::Function=default_preproc) = HttpRpcServer([api], preproc)
function HttpRpcServer{T,F}(apis::Vector{APIInvoker{T,F}}, preproc::Function=default_preproc)
api = Channel{APIInvoker{T,F}}(length(apis))
Expand All @@ -213,7 +229,7 @@ function HttpRpcServer{T,F}(apis::Vector{APIInvoker{T,F}}, preproc::Function=def
return http_handler(api, preproc, req, res)
end

handler = HttpHandler(handler)
handler = HttpHandler(handler, reusable_tcpserver())
handler.events["error"] = on_error
handler.events["listen"] = on_listen
server = Server(handler)
Expand Down
1 change: 1 addition & 0 deletions test/clnt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using Logging
using ZMQ
using Base.Test
using Requests
using JSON

Logging.configure(level=INFO)

Expand Down
1 change: 1 addition & 0 deletions test/srvr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using HttpCommon
using Logging
using Compat
using ZMQ
using JSON

include("srvrfn.jl")

Expand Down

0 comments on commit 41cd5c1

Please sign in to comment.