Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved connect logic into separate function

  • Loading branch information...
commit 6a87ca5361423eaeddaeffc173d18de4d7154c15 1 parent 91d2515
András Veres-Szentkirályi authored
Showing with 10 additions and 5 deletions.
  1. +9 −4 ircbot.erl
  2. +1 −1  ircbot.hrl
13 ircbot.erl
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
2  ircbot.hrl
View
@@ -1 +1 @@
--record(ms, {channel, modpids, socket, rawsubscribers = []}).
+-record(ms, {channel, modpids, socket, rawsubscribers = [], host, port}).
Please sign in to comment.
Something went wrong with that request. Please try again.