Skip to content
Browse files

Removed case ladder and pattern matched-out variables from record in …

…state
  • Loading branch information...
1 parent 3d64ff9 commit cbd188a9b643f3196e539eef0fda4038db048ae7 Gianfranco Alongi committed Mar 13, 2012
Showing with 15 additions and 14 deletions.
  1. +14 −11 Two/Solution/src/port.erl
  2. +1 −3 Two/Solution/src/server.erl
View
25 Two/Solution/src/port.erl
@@ -26,19 +26,22 @@ open(FileDir,Port,ModuleName) ->
error ->
{error,compile_error};
{ok,Module,Binary} ->
- {module,Module} = code:load_binary(Module,ErlSource,Binary),
- case erlang:function_exported(Module,handle,1) of
- false ->
- {error,no_handle_function_exported};
- true ->
- {ok,Sock} = gen_tcp:listen(Port,[{active,false}]),
- {ok,#port{type = ModuleName,
- socket = Sock,
- number = Port}}
- end
+ try_load(ModuleName,Module,ErlSource,Binary,Port)
end
- end.
+ end.
+try_load(ModuleName,Module,ErlSource,Binary,Port) ->
+ {module,Module} = code:load_binary(Module,ErlSource,Binary),
+ case erlang:function_exported(Module,handle,1) of
+ false ->
+ {error,no_handle_function_exported};
+ true ->
+ {ok,Sock} = gen_tcp:listen(Port,[{active,false}]),
+ {ok,#port{type = ModuleName,
+ socket = Sock,
+ number = Port}}
+ end.
+
-spec(close(#port{}) -> ok).
close(Port) ->
View
4 Two/Solution/src/server.erl
@@ -84,10 +84,8 @@ perform_command(#port_command{type = list},State) ->
perform_command(#port_command{type = open,arguments = Args}, State) ->
[Port,Type] = pick([port,type],Args),
- Bindings = State#state.bindings,
+ #state{bindings = Bindings, files_dir = Dir, ports = Ports} = State,
File = proplists:get_value(Type,Bindings),
- Dir = State#state.files_dir,
- Ports = State#state.ports,
Pid = spawn(fun() ->
{ok,PortRecord} = port:open(Dir,Port,File),
port_loop(PortRecord)

0 comments on commit cbd188a

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