You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2008/06/11 02:56:25 UTC

svn commit: r666405 - /incubator/thrift/trunk/lib/alterl/src/thrift_server.erl

Author: dreiss
Date: Tue Jun 10 17:56:25 2008
New Revision: 666405

URL: http://svn.apache.org/viewvc?rev=666405&view=rev
Log:
Add thrift_server:stop/1 to stop a running server

Modified:
    incubator/thrift/trunk/lib/alterl/src/thrift_server.erl

Modified: incubator/thrift/trunk/lib/alterl/src/thrift_server.erl
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/alterl/src/thrift_server.erl?rev=666405&r1=666404&r2=666405&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/alterl/src/thrift_server.erl (original)
+++ incubator/thrift/trunk/lib/alterl/src/thrift_server.erl Tue Jun 10 17:56:25 2008
@@ -10,7 +10,7 @@
 -behaviour(gen_server).
 
 %% API
--export([start_link/3]).
+-export([start_link/3, stop/1]).
 
 %% gen_server callbacks
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
@@ -30,6 +30,15 @@
 start_link(Port, Service, HandlerModule) when is_integer(Port), is_atom(HandlerModule) ->
     gen_server:start_link({local, ?SERVER}, ?MODULE, {Port, Service, HandlerModule}, []).
 
+
+%%--------------------------------------------------------------------
+%% Function: stop(Pid) -> ok, {error, Reason}
+%% Description: Stops the server.
+%%--------------------------------------------------------------------
+stop(Pid) when is_pid(Pid) ->
+    gen_server:call(Pid, stop).
+
+
 %%====================================================================
 %% gen_server callbacks
 %%====================================================================
@@ -62,9 +71,9 @@
 %%                                      {stop, Reason, State}
 %% Description: Handling call messages
 %%--------------------------------------------------------------------
-handle_call(_Request, _From, State) ->
-    Reply = ok,
-    {reply, Reply, State}.
+handle_call(stop, _From, State) ->
+    State#state.acceptor ! stop,
+    {stop, stopped, ok, State}.
 
 %%--------------------------------------------------------------------
 %% Function: handle_cast(Msg, State) -> {noreply, State} |
@@ -119,6 +128,8 @@
     receive
         refresh ->
             error_logger:info_msg("Acceptor refreshing~n"),
-            ?MODULE:acceptor(ListenSocket, Service, Handler)
+            ?MODULE:acceptor(ListenSocket, Service, Handler);
+        stop ->
+            ok
     after 0      -> acceptor(ListenSocket, Service, Handler)
     end.