[随笔]20100619 gen_server module

  服务器模块              返回模块
-----------------            ---------------
gen_server:start_link  -----> Module:init/1
gen_server:call
gen_server:multi_call  -----> Module:handle_call/3
gen_server:cast
gen_server:abcast      -----> Module:handle_cast/2
-                         -----> Module:handle_info/2
-                         -----> Module:terminate/2
-                         -----> Module:code_change/3

 

 

 

一、函数start_link——创建一个gen_server进程,并注册为Module.

start_link(Module, Args, Options) -> Result

start_link(ServerName, Module, Args, Options) -> Result



各参数类型

ServerName = {local,Name} | {global,GlobalName}   {Name = atom(), GlobalName = term()}

Module = atom()

Args = term()

Options = [Option]

 Option = {debug,Dbgs} | {timeout,Time} | {spawn_opt,SOpts}

  Dbgs = [Dbg] "Dbg = trace | log | statistics | {log_to_file,FileName} | {install,{Func,FuncState}}"

  SOpts = [term()]

返回值= {ok,Pid} | ignore | {error,Error}

 Pid = pid()

 Error = {already_started,Pid} | term()

: 如果成功创建并被初使化返回{ok, Pid},则Pid为这个进程的pid;如果已经存在Module这个进程,返回{error, ,{already_started,Pid}},则Pid为这个进程的pid.





 

 

你可能感兴趣的:(server)