Software /
code /
prosody
Comparison
net/server_epoll.lua @ 9497:183ff7a8051b
net.server_epoll: Add support for the conn_type argument to addclient
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 12 Oct 2018 16:26:19 +0200 |
parent | 9477:0738f5276e0a |
child | 9498:cc593002f2e2 |
comparison
equal
deleted
inserted
replaced
9496:4ac3103787cc | 9497:183ff7a8051b |
---|---|
623 end | 623 end |
624 return client; | 624 return client; |
625 end | 625 end |
626 | 626 |
627 -- New outgoing TCP connection | 627 -- New outgoing TCP connection |
628 local function addclient(addr, port, listeners, read_size, tls_ctx) | 628 local function addclient(addr, port, listeners, read_size, tls_ctx, typ) |
629 local n = inet_pton(addr); | 629 local create; |
630 if not n then return nil, "invalid-ip"; end | 630 if not typ then |
631 local create | 631 local n = inet_pton(addr); |
632 if #n == 16 then | 632 if not n then return nil, "invalid-ip"; end |
633 create = socket.tcp6 or socket.tcp; | 633 if #n == 16 then |
634 else | 634 typ = "tcp6"; |
635 create = socket.tcp4 or socket.tcp; | 635 else |
636 typ = "tcp4"; | |
637 end | |
638 end | |
639 if typ then | |
640 create = socket[typ]; | |
641 end | |
642 if type(create) ~= "function" then | |
643 return nil, "invalid socket type"; | |
636 end | 644 end |
637 local conn, err = create(); | 645 local conn, err = create(); |
638 conn:settimeout(0); | 646 conn:settimeout(0); |
639 conn:connect(addr, port); | 647 conn:connect(addr, port); |
640 local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx) | 648 local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx) |