-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
print("CRASH_POINT.LUA START") | ||
|
||
require("splay.base") | ||
local math = require("math") | ||
local net = require("splay.net") | ||
local misc = require("splay.misc") | ||
|
||
function receive(s) | ||
local ip, port = s:getpeername() | ||
while events.yield() do | ||
local data, err = s:receive("*l") | ||
print("I received : "..data) | ||
-- CRASH POINT 2 : STOP : AFTER 6 | ||
end | ||
end | ||
|
||
function send(s) | ||
while events.yield() do | ||
-- CRASH POINT 1 : RECOVERY 1 : AFTER 3 | ||
events.sleep(0.5) | ||
print("I send data") | ||
s:send("I AM "..job.position.."\n") | ||
end | ||
end | ||
|
||
function init(s, connect) | ||
local ip, port = s:getpeername() | ||
print("Connection accepted with : "..ip..":"..port) | ||
end | ||
|
||
function final(s) | ||
local ip, port = s:getpeername() | ||
print("Closing: "..ip..":"..port) | ||
end | ||
|
||
events.run(function() | ||
-- Accept connection from other nodes | ||
net.server(job.me.port, {initialize = init, send = send, receive = receive, finalize = final}) | ||
|
||
-- Launch connection to each orther node | ||
events.thread(function () | ||
events.sleep(1) | ||
for i, n in pairs(job.nodes) do | ||
if n.port ~= job.me.port or n.ip ~= job.me.ip then | ||
print("Try to begin connection to "..n.ip..":"..n.port.." - index "..i) | ||
net.client(n, {initialize = init, send = send, receive = receive, finalize = final}) | ||
end | ||
end | ||
end) | ||
|
||
-- Crash point or kill before | ||
end) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters