Comparison

net/server_epoll.lua @ 7800:dadf9ba290c5

server_epoll: Add some comments describing some functions
author Kim Alvefur <zash@zash.se>
date Sun, 01 Jan 2017 19:42:12 +0100
parent 7799:93643a61858a
child 7811:24f99d11b792
comparison
equal deleted inserted replaced
7799:93643a61858a 7800:dadf9ba290c5
570 end 570 end
571 client:init(); 571 client:init();
572 return client; 572 return client;
573 end 573 end
574 574
575 -- New outgoing TCP connection
575 local function addclient(addr, port, listeners, pattern, tls) 576 local function addclient(addr, port, listeners, pattern, tls)
576 local conn, err = socket.tcp(); 577 local conn, err = socket.tcp();
577 if not conn then return conn, err; end 578 if not conn then return conn, err; end
578 conn:settimeout(0); 579 conn:settimeout(0);
579 conn:connect(addr, port); 580 conn:connect(addr, port);
580 local client = wrapsocket(conn, nil, pattern, listeners, tls) 581 local client = wrapsocket(conn, nil, pattern, listeners, tls)
581 client:init(); 582 client:init();
582 return client, conn; 583 return client, conn;
583 end 584 end
584 585
586 -- Dump all data from one connection into another
585 local function link(from, to) 587 local function link(from, to)
586 from.listeners = setmetatable({ 588 from.listeners = setmetatable({
587 onincoming = function (_, data) 589 onincoming = function (_, data)
588 from:pause(); 590 from:pause();
589 to:write(data); 591 to:write(data);
602 -- net.adns 604 -- net.adns
603 function interface:set_send(new_send) 605 function interface:set_send(new_send)
604 self.send = new_send; 606 self.send = new_send;
605 end 607 end
606 608
609 -- Close all connections and servers
607 local function closeall() 610 local function closeall()
608 for fd, conn in pairs(fds) do -- luacheck: ignore 213/fd 611 for fd, conn in pairs(fds) do -- luacheck: ignore 213/fd
609 conn:close(); 612 conn:close();
610 end 613 end
611 end 614 end