Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make it possible to register the xmlrpc server

  • Loading branch information...
commit 9f84974cd262493d80ba27906ab6064c1c890663 1 parent b6ae89d
Richard Carlsson authored
Showing with 28 additions and 12 deletions.
  1. +9 −3 src/xmlrpc.erl
  2. +19 −9 src/xmlrpc_tcp_serv.erl
View
12 src/xmlrpc.erl
@@ -36,7 +36,7 @@
-module(xmlrpc).
-export([call/3, call/4, call/5, call/6]).
--export([start_link/1, start_link/5, start_link/6, stop/1]).
+-export([start_link/1, start_link/5, start_link/6, start_link/7, stop/1]).
-export([ssl_call/3, ssl_call/4, ssl_call/5, ssl_call/6]).
@@ -369,6 +369,8 @@ get_payload(Socket, Timeout, ContentLength) ->
setopts(Socket, [{packet, raw}]),
recv(Socket, ContentLength, Timeout).
+-define(TIMEOUT, 6000).
+
%% Exported: start_link/{1,5,6}
-spec start_link(Handler) -> {ok, pid()} | {error, Reason::term()}
@@ -377,7 +379,7 @@ get_payload(Socket, Timeout, ContentLength) ->
%% @equiv start_link(4567, 1000, 60000, Handler, undefined)
start_link(Handler) ->
- start_link(4567, 1000, 60000, Handler, undefined).
+ start_link(4567, 1000, ?TIMEOUT, Handler, undefined).
-spec start_link(Port, MaxSessions, Timeout, Handler, State) ->
{ok, pid()} | {error, Reason::term()}
@@ -414,9 +416,13 @@ start_link(Port, MaxSessions, Timeout, Handler, State) ->
%% xmlrpc:stop/1}.
start_link(IP, Port, MaxSessions, Timeout, Handler, State) ->
+ start_link(undefined, IP, Port, MaxSessions, Timeout, Handler, State).
+
+start_link(Register, IP, Port, MaxSessions, Timeout, Handler, State) ->
OptionList = [{active, false}, {reuseaddr, true}|ip(IP)],
SessionHandler = {xmlrpc_http, handler, [Timeout, Handler, State]},
- xmlrpc_tcp_serv:start_link([Port, MaxSessions, OptionList, SessionHandler]).
+ xmlrpc_tcp_serv:start_link([Port, MaxSessions, OptionList, SessionHandler],
+ ?TIMEOUT, Register).
ip(all) -> [];
ip(IP) when is_tuple(IP) -> [{ip, IP}].
View
28 src/xmlrpc_tcp_serv.erl
@@ -30,10 +30,10 @@
-module(xmlrpc_tcp_serv).
--export([start_link/1, start_link/2,
+-export([start_link/1, start_link/2, start_link/3,
start/1, start/2,
stop/1, stop/2]).
--export([init/2, start_session/3]).
+-export([init/3, start_session/3]).
-export([system_continue/3, system_terminate/4]).
-include("log.hrl").
@@ -62,22 +62,28 @@
debug_info
}).
+-define(DEFAULT_TIMEOUT, 6000).
+
%% Exported: start_link/{1,2}
-start_link(Args) -> start_link(Args, 60000).
+start_link(Args) -> start_link(Args, ?DEFAULT_TIMEOUT).
-start_link(Args, Timeout) ->
- Pid = proc_lib:spawn_link(?MODULE, init, [self(), Args]),
+start_link(Args, Timeout) -> start_link(Args, Timeout, undefined).
+
+start_link(Args, Timeout, Register) ->
+ Pid = proc_lib:spawn_link(?MODULE, init, [self(), Register, Args]),
receive
{Pid, started} -> {ok, Pid};
{Pid, Reason} -> {error, Reason}
after Timeout -> {error, timeout}
end.
-start(Args) -> start(Args, 60000).
+start(Args) -> start(Args, ?DEFAULT_TIMEOUT).
-start(Args, Timeout) ->
- Pid = proc_lib:spawn(?MODULE, init, [self(), Args]),
+start(Args, Timeout) -> start(undefined, Args, Timeout).
+
+start(Register, Args, Timeout) ->
+ Pid = proc_lib:spawn(?MODULE, init, [self(), Register, Args]),
receive
{Pid, started} -> {ok, Pid};
{Pid, Reason} -> {error, Reason}
@@ -98,9 +104,13 @@ stop(Pid, Timeout) ->
%% Exported: init/2
-init(Parent, [Port, MaxSessions, OptionList, SessionHandler]) ->
+init(Parent, Register, [Port, MaxSessions, OptionList, SessionHandler]) ->
process_flag(trap_exit, true),
?dbg("~p init Port=~p, SessionHandler=~p~n", [self(),Port,SessionHandler]),
+ case Register of
+ undefined -> ok;
+ {local, Name} -> register(Name, self())
+ end,
case gen_tcp:listen(Port, OptionList) of
{ok, ListenSocket} ->
?dbg("~p init Port=~p got ListenSocket~n", [self(),Port]),

0 comments on commit 9f84974

Please sign in to comment.
Something went wrong with that request. Please try again.