Comparison

net/server_epoll.lua @ 9835:20bf5b47c1fb

net.server: New API for creating server listeners server.listen(interface, port, listeners, options);
author Kim Alvefur <zash@zash.se>
date Thu, 13 Sep 2018 21:16:37 +0200
parent 9825:5ccce16c6449
child 9847:adc0672b700e
comparison
equal deleted inserted replaced
9834:a657df70cc31 9835:20bf5b47c1fb
635 self:updatenames(); 635 self:updatenames();
636 self.onconnect = noop; 636 self.onconnect = noop;
637 self:on("connect"); 637 self:on("connect");
638 end 638 end
639 639
640 local function addserver(addr, port, listeners, read_size, tls_ctx) 640 local function listen(addr, port, listeners, config)
641 local conn, err = socket.bind(addr, port, cfg.tcp_backlog); 641 local conn, err = socket.bind(addr, port, cfg.tcp_backlog);
642 if not conn then return conn, err; end 642 if not conn then return conn, err; end
643 conn:settimeout(0); 643 conn:settimeout(0);
644 local server = setmetatable({ 644 local server = setmetatable({
645 conn = conn; 645 conn = conn;
646 created = gettime(); 646 created = gettime();
647 listeners = listeners; 647 listeners = listeners;
648 read_size = read_size; 648 read_size = config and config.read_size;
649 onreadable = interface.onacceptable; 649 onreadable = interface.onacceptable;
650 tls_ctx = tls_ctx; 650 tls_ctx = config and config.tls_ctx;
651 tls_direct = tls_ctx and true or false; 651 tls_direct = config and config.tls_direct;
652 sockname = addr; 652 sockname = addr;
653 sockport = port; 653 sockport = port;
654 }, interface_mt); 654 }, interface_mt);
655 server:add(true, false); 655 server:add(true, false);
656 return server; 656 return server;
657 end
658
659 -- COMPAT
660 local function addserver(addr, port, listeners, read_size, tls_ctx)
661 return listen(addr, port, listeners, {
662 read_size = read_size;
663 tls_ctx = tls_ctx;
664 tls_direct = tls_ctx and true or false;
665 });
657 end 666 end
658 667
659 -- COMPAT 668 -- COMPAT
660 local function wrapclient(conn, addr, port, listeners, read_size, tls_ctx) 669 local function wrapclient(conn, addr, port, listeners, read_size, tls_ctx)
661 local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx); 670 local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx);
790 return { 799 return {
791 get_backend = function () return "epoll"; end; 800 get_backend = function () return "epoll"; end;
792 addserver = addserver; 801 addserver = addserver;
793 addclient = addclient; 802 addclient = addclient;
794 add_task = addtimer; 803 add_task = addtimer;
804 listen = listen;
795 at = at; 805 at = at;
796 loop = loop; 806 loop = loop;
797 closeall = closeall; 807 closeall = closeall;
798 setquitting = setquitting; 808 setquitting = setquitting;
799 wrapclient = wrapclient; 809 wrapclient = wrapclient;