@@ -202,6 +202,22 @@ immutable HttpRpcServer{T,F}
202
202
server:: Server
203
203
end
204
204
205
+ function reusable_tcpserver ()
206
+ tcp = Base. TCPServer (Base. Libc. malloc (Base. _sizeof_uv_tcp), Base. StatusUninit)
207
+ err = ccall (:uv_tcp_init_ex , Cint, (Ptr{Void}, Ptr{Void}, Cuint),
208
+ Base. eventloop (), tcp. handle, 2 )
209
+ Base. uv_error (" failed to create tcp server" , err)
210
+ tcp. status = Base. StatusInit
211
+
212
+ rc = ccall (:jl_tcp_reuseport , Int32, (Ptr{Void},), tcp. handle)
213
+ if rc == 0
214
+ Logging. info (" Reusing TCP port" )
215
+ else
216
+ Logging. warn (" Unable to reuse TCP port, error:" , rc)
217
+ end
218
+ return tcp
219
+ end
220
+
205
221
HttpRpcServer {T,F} (api:: APIInvoker{T,F} , preproc:: Function = default_preproc) = HttpRpcServer ([api], preproc)
206
222
function HttpRpcServer {T,F} (apis:: Vector{APIInvoker{T,F}} , preproc:: Function = default_preproc)
207
223
api = Channel {APIInvoker{T,F}} (length (apis))
@@ -213,7 +229,7 @@ function HttpRpcServer{T,F}(apis::Vector{APIInvoker{T,F}}, preproc::Function=def
213
229
return http_handler (api, preproc, req, res)
214
230
end
215
231
216
- handler = HttpHandler (handler)
232
+ handler = HttpHandler (handler, reusable_tcpserver () )
217
233
handler. events[" error" ] = on_error
218
234
handler. events[" listen" ] = on_listen
219
235
server = Server (handler)
0 commit comments