Comparison

net/server_epoll.lua @ 7553:4f3e4a092348

net.server_epoll: Make addclient use wrapclient
author Kim Alvefur <zash@zash.se>
date Wed, 10 Aug 2016 20:57:05 +0200
parent 7552:f1ae74ebeb81
child 7554:c2decf88e249
comparison
equal deleted inserted replaced
7552:f1ae74ebeb81 7553:4f3e4a092348
420 420
421 function interface:onconnect() 421 function interface:onconnect()
422 self.onreadable = nil; 422 self.onreadable = nil;
423 self.onwriteable = nil; 423 self.onwriteable = nil;
424 self.listeners.onconnect(self); 424 self.listeners.onconnect(self);
425 end
426
427 local function addclient(addr, port, listeners, pattern, tls)
428 local conn, err = socket.connect(addr, port);
429 if not conn then return conn, err; end
430 return wrapsocket(conn, nil, pattern, listeners, tls);
431 end 425 end
432 426
433 local function addserver(addr, port, listeners, pattern, tls) 427 local function addserver(addr, port, listeners, pattern, tls)
434 local conn, err = socket.bind(addr, port, cfg.tcp_backlog); 428 local conn, err = socket.bind(addr, port, cfg.tcp_backlog);
435 if not conn then return conn, err; end 429 if not conn then return conn, err; end
461 onwriteable = interface.onconnect; 455 onwriteable = interface.onconnect;
462 peer = { addr, port }; 456 peer = { addr, port };
463 }, interface_mt); 457 }, interface_mt);
464 fds[client:getfd()] = client; 458 fds[client:getfd()] = client;
465 client:setflags(false, true); 459 client:setflags(false, true);
460 return client;
461 end
462
463 local function addclient(addr, port, listeners, pattern, tls)
464 local conn, err = socket.connect(addr, port);
465 if not conn then return conn, err; end
466 conn:settimeout(0);
467 local client = wrapclient(conn, addr, port, listeners, pattern, tls);
468 if tls then
469 client._tls = false;
470 client:starttls();
471 else
472 client:setflags(true, true);
473 end
466 return client; 474 return client;
467 end 475 end
468 476
469 local function link(from, to) 477 local function link(from, to)
470 from.listeners = setmetatable({ 478 from.listeners = setmetatable({