aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--samples/forward.lua24
1 files changed, 1 insertions, 23 deletions
diff --git a/samples/forward.lua b/samples/forward.lua
index c213a59..ff65b84 100644
--- a/samples/forward.lua
+++ b/samples/forward.lua
@@ -72,16 +72,12 @@ end
72-- starts a connection in a non-blocking way 72-- starts a connection in a non-blocking way
73function connect(who, host, port) 73function connect(who, host, port)
74 who:settimeout(0) 74 who:settimeout(0)
75print("trying to connect peer", who, host, port)
76 local ret, err = who:connect(host, port) 75 local ret, err = who:connect(host, port)
77 if not ret and err == "timeout" then 76 if not ret and err == "timeout" then
78print("got timeout, will wait", who)
79 wait(who, "output") 77 wait(who, "output")
80 ret, err = who:connect(host, port) 78 ret, err = who:connect(host, port)
81print("connection results arrived", who, ret, err)
82 end 79 end
83 if not ret then 80 if not ret then
84print("connection failed", who, err)
85 kick(who) 81 kick(who)
86 kick(context[who].peer) 82 kick(context[who].peer)
87 else 83 else
@@ -104,7 +100,6 @@ function accept(server)
104 while true do 100 while true do
105 -- accept a new connection and start a new coroutine to deal with it 101 -- accept a new connection and start a new coroutine to deal with it
106 local client = server:accept() 102 local client = server:accept()
107print("accepted ", client)
108 if client then 103 if client then
109 -- create contexts for client and peer. 104 -- create contexts for client and peer.
110 local peer, err = socket.tcp() 105 local peer, err = socket.tcp()
@@ -139,7 +134,6 @@ end
139 134
140-- forwards all data arriving to the appropriate peer 135-- forwards all data arriving to the appropriate peer
141function forward(who) 136function forward(who)
142print("starting to foward", who)
143 who:settimeout(0) 137 who:settimeout(0)
144 while true do 138 while true do
145 -- wait until we have something to read 139 -- wait until we have something to read
@@ -173,24 +167,8 @@ end
173-- what happened, and routing it to wait until something else happens 167-- what happened, and routing it to wait until something else happens
174function go() 168function go()
175 while true do 169 while true do
176print("will select for reading")
177for i,v in ipairs(receiving) do
178 print(i, v)
179end
180print("will select for sending")
181for i,v in ipairs(sending) do
182 print(i, v)
183end
184 -- check which sockets are interesting and act on them 170 -- check which sockets are interesting and act on them
185 readable, writable = socket.select(receiving, sending, 3) 171 readable, writable = socket.select(receiving, sending)
186print("was readable")
187for i,v in ipairs(readable) do
188 print(i, v)
189end
190print("was writable")
191for i,v in ipairs(writable) do
192 print(i, v)
193end
194 -- for all readable connections, resume its thread 172 -- for all readable connections, resume its thread
195 for _, who in ipairs(readable) do 173 for _, who in ipairs(readable) do
196 receiving:remove(who) 174 receiving:remove(who)