Permalink
Browse files

Moved connect logic into separate function

  • Loading branch information...
1 parent 91d2515 commit 6a87ca5361423eaeddaeffc173d18de4d7154c15 @dnet committed Oct 24, 2010
Showing with 10 additions and 5 deletions.
  1. +9 −4 ircbot.erl
  2. +1 −1 ircbot.hrl
View
@@ -27,14 +27,19 @@ start(Channel, Host, Port) ->
start(Channel, Host, Port, []).
start(Channel, Host, Port, Modules) ->
+ Socket = connect(Channel, Host, Port),
+ Master = self(),
+ ModPids = lists:map(
+ fun({M, P}) -> apply(M, ircmain, [Master | P]) end, Modules),
+ master(#ms{channel = Channel, modpids = ModPids,
+ socket = Socket, host = Host, port = Port}).
+
+connect(Channel, Host, Port) ->
% active true means receiving data in messages
{ok, Socket} = gen_tcp:connect(Host, Port,
[binary, {active, true}]),
send_init(Socket, Channel),
- Master = self(),
- ModPids = lists:map(
- fun({M, P}) -> apply(M, ircmain, [Master | P]) end, Modules),
- master(#ms{channel = Channel, modpids = ModPids, socket = Socket}).
+ Socket.
master(State = #ms{socket = Socket}) ->
receive
View
@@ -1 +1 @@
--record(ms, {channel, modpids, socket, rawsubscribers = []}).
+-record(ms, {channel, modpids, socket, rawsubscribers = [], host, port}).

0 comments on commit 6a87ca5

Please sign in to comment.