-
- -- check capacity
- if not self.threadlimit or #self.running < self.threadlimit then
-
- self:dprint("Accepted incoming connection from " .. sock:getpeername())
-
- table.insert( self.running, {
- coroutine.create( self.handler[connection].clhandler ),
- sock
- } )
-
- self:dprint("Created " .. tostring(self.running[#self.running][1]))
-
- -- reject client
- else
- self:dprint("Rejected incoming connection from " .. sock:getpeername())
-
- if self.handler[connection].errhandler then
- self.handler[connection].errhandler( sock )
+
+ if sock then
+ -- check capacity
+ if not self.threadlimit or #self.running < self.threadlimit then
+
+ if self.debug then
+ self:dprint("Accepted incoming connection from " .. sock:getpeername())
+ end
+
+ table.insert( self.running, {
+ coroutine.create( self.handler[connection].clhandler ),
+ sock
+ } )
+
+ if self.debug then
+ self:dprint("Created " .. tostring(self.running[#self.running][1]))
+ end
+
+ -- reject client
+ else
+ if self.debug then
+ self:dprint("Rejected incoming connection from " .. sock:getpeername())
+ end
+
+ if self.handler[connection].errhandler then
+ self.handler[connection].errhandler( sock )
+ end
+
+ sock:close()