diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-28 21:24:30 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-28 21:24:30 +0000 |
commit | d0560e0b4419cc6812f83b88b1cb9009481eab1f (patch) | |
tree | ab166219108807a501746d05e43abff64c3d1bbe | |
parent | f18d1b7cd0ec4708518ab5e18ea33b6eadca0301 (diff) | |
download | luasocket-d0560e0b4419cc6812f83b88b1cb9009481eab1f.tar.gz luasocket-d0560e0b4419cc6812f83b88b1cb9009481eab1f.tar.bz2 luasocket-d0560e0b4419cc6812f83b88b1cb9009481eab1f.zip |
Local index in for loop was getting changed...
-rw-r--r-- | samples/tinyirc.lua | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/samples/tinyirc.lua b/samples/tinyirc.lua index b0c4168..d3e56e7 100644 --- a/samples/tinyirc.lua +++ b/samples/tinyirc.lua | |||
@@ -1,11 +1,11 @@ | |||
1 | function set_add(set, sock) | 1 | function set_add(set, sock) |
2 | tinsert(set, sock) | 2 | table.insert(set, sock) |
3 | end | 3 | end |
4 | 4 | ||
5 | function set_remove(set, sock) | 5 | function set_remove(set, sock) |
6 | for i = 1, getn(set) do | 6 | for i = 1, table.getn(set) do |
7 | if set[i] == sock then | 7 | if set[i] == sock then |
8 | tremove(set, i) | 8 | table.remove(set, i) |
9 | break | 9 | break |
10 | end | 10 | end |
11 | end | 11 | end |
@@ -20,10 +20,10 @@ if arg then | |||
20 | port2 = arg[3] or port2 | 20 | port2 = arg[3] or port2 |
21 | end | 21 | end |
22 | 22 | ||
23 | server1, error = bind(host, port1) | 23 | server1, error = socket.bind(host, port1) |
24 | if not server1 then print(error) exit() end | 24 | if not server1 then print(error) exit() end |
25 | server1:timeout(1) | 25 | server1:timeout(1) |
26 | server2, error = bind(host, port2) | 26 | server2, error = socket.bind(host, port2) |
27 | if not server2 then print(error) exit() end | 27 | if not server2 then print(error) exit() end |
28 | server2:timeout(1) | 28 | server2:timeout(1) |
29 | 29 | ||
@@ -35,7 +35,7 @@ sock_id[server2] = 2 | |||
35 | next_id = 3 | 35 | next_id = 3 |
36 | 36 | ||
37 | while 1 do | 37 | while 1 do |
38 | local readable, _, error = select(sock_set, nil) | 38 | local readable, _, error = socket.select(sock_set, nil) |
39 | for _, sock in readable do | 39 | for _, sock in readable do |
40 | -- is it a server socket | 40 | -- is it a server socket |
41 | if sock_id[sock] < 3 then | 41 | if sock_id[sock] < 3 then |
@@ -44,8 +44,8 @@ while 1 do | |||
44 | incomming:timeout(1) | 44 | incomming:timeout(1) |
45 | sock_id[incomming] = next_id | 45 | sock_id[incomming] = next_id |
46 | set_add(sock_set, incomming) | 46 | set_add(sock_set, incomming) |
47 | write("Added client id ", next_id, ". ", | 47 | io.write("Added client id ", next_id, ". ", |
48 | getn(sock_set)-2, " total.\n") | 48 | table.getn(sock_set)-2, " total.\n") |
49 | next_id = next_id + 1 | 49 | next_id = next_id + 1 |
50 | end | 50 | end |
51 | -- it is a client socket | 51 | -- it is a client socket |
@@ -55,17 +55,17 @@ while 1 do | |||
55 | if error then | 55 | if error then |
56 | sock:close() | 56 | sock:close() |
57 | set_remove(sock_set, sock) | 57 | set_remove(sock_set, sock) |
58 | write("Removed client number ", id, ". ", | 58 | io.write("Removed client number ", id, ". ", |
59 | getn(sock_set)-2, " total.\n") | 59 | getn(sock_set)-2, " total.\n") |
60 | else | 60 | else |
61 | write("Broadcasting line '", id, "> ", line, "'.\n") | 61 | io.write("Broadcasting line '", id, "> ", line, "'.\n") |
62 | _, writable, error = select(nil, sock_set, 1) | 62 | __, writable, error = socket.select(nil, sock_set, 1) |
63 | if not error then | 63 | if not error then |
64 | for _, outgoing in writable do | 64 | for ___, outgoing in writable do |
65 | write("Sending to client ", sock_id[outgoing], "\n") | 65 | io.write("Sending to client ", sock_id[outgoing], "\n") |
66 | outgoing:send(id, "> ", line, "\r\n") | 66 | outgoing:send(id, "> ", line, "\r\n") |
67 | end | 67 | end |
68 | else write("No one ready to listen!!!\n") end | 68 | else io.write("No one ready to listen!!!\n") end |
69 | end | 69 | end |
70 | end | 70 | end |
71 | end | 71 | end |