aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2012-12-28 15:14:11 +0100
committerKim Alvefur <zash@zash.se>2012-12-28 15:14:11 +0100
commit45f6b0c64c3ab63603fe8bc8b29f2dbc835b4e92 (patch)
tree0203d6bd6df69296fe7defc78a44293a3e08767d /net
parent93fcefee1c694c8917be74879d4d204730904e07 (diff)
parent71f54b16f9bf4a2561f80058affb049850c90327 (diff)
downloadprosody-45f6b0c64c3ab63603fe8bc8b29f2dbc835b4e92.tar.gz
prosody-45f6b0c64c3ab63603fe8bc8b29f2dbc835b4e92.zip
Merge 0.9->trunk
Diffstat (limited to 'net')
-rw-r--r--net/server_event.lua17
-rw-r--r--net/server_select.lua23
2 files changed, 28 insertions, 12 deletions
diff --git a/net/server_event.lua b/net/server_event.lua
index f2626f5f..e69530ff 100644
--- a/net/server_event.lua
+++ b/net/server_event.lua
@@ -6,7 +6,6 @@
notes:
-- when using luaevent, never register 2 or more EV_READ at one socket, same for EV_WRITE
-- you cant even register a new EV_READ/EV_WRITE callback inside another one
- -- never call eventcallback:close( ) from inside eventcallback
-- to do some of the above, use timeout events or something what will called from outside
-- dont let garbagecollect eventcallbacks, as long they are running
-- when using luasec, there are 4 cases of timeout errors: wantread or wantwrite during reading or writing
@@ -121,14 +120,8 @@ do
self.position = new_position or self.position
return self.position;
end
- function interface_mt:_close() -- regs event to start self:_destroy()
- local callback = function( )
- self:_destroy();
- self.eventclose = nil
- return -1
- end
- self.eventclose = addevent( base, nil, EV_TIMEOUT, callback, 0 )
- return true
+ function interface_mt:_close()
+ return self:_destroy();
end
function interface_mt:_start_connection(plainssl) -- should be called from addclient
@@ -248,7 +241,7 @@ do
debug( "closing client with id:", self.id, self.fatalerror )
self:_lock( true, true, true ) -- first of all, lock the interface to avoid further actions
local _
- _ = self.eventread and self.eventread:close( ) -- close events; this must be called outside of the event callbacks!
+ _ = self.eventread and self.eventread:close( )
if self.type == "client" then
_ = self.eventwrite and self.eventwrite:close( )
_ = self.eventhandshake and self.eventhandshake:close( )
@@ -258,7 +251,7 @@ do
_ = self.eventwritetimeout and self.eventwritetimeout:close( )
_ = self.eventreadtimeout and self.eventreadtimeout:close( )
_ = self.ondisconnect and self:ondisconnect( self.fatalerror ~= "client to close" and self.fatalerror) -- call ondisconnect listener (wont be the case if handshake failed on connect)
- _ = self.conn and self.conn:close( ) -- close connection, must also be called outside of any socket registered events!
+ _ = self.conn and self.conn:close( ) -- close connection
_ = self._server and self._server:counter(-1);
self.eventread, self.eventwrite = nil, nil
self.eventstarthandshake, self.eventhandshake, self.eventclose = nil, nil, nil
@@ -342,7 +335,7 @@ do
debug( "try to close server with id:", tostring(self.id))
self.fatalerror = "server to close"
self:_lock( true )
- self:_close( 0 ) -- add new event to remove the server interface
+ self:_close( 0 )
return true
end
end
diff --git a/net/server_select.lua b/net/server_select.lua
index 8cb4e235..97b9f199 100644
--- a/net/server_select.lua
+++ b/net/server_select.lua
@@ -185,6 +185,9 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, maxco
end
handler.remove = function( )
connections = connections - 1
+ if handler then
+ handler.resume( )
+ end
end
handler.close = function()
socket:close( )
@@ -197,6 +200,25 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, maxco
--mem_free( )
out_put "server.lua: closed server handler and removed sockets from list"
end
+ handler.pause = function()
+ if not handler.paused then
+ socket:close( )
+ _sendlistlen = removesocket( _sendlist, socket, _sendlistlen )
+ _readlistlen = removesocket( _readlist, socket, _readlistlen )
+ _socketlist[ socket ] = nil
+ socket = nil;
+ handler.paused = true;
+ end
+ end
+ handler.resume = function()
+ if handler.paused then
+ socket = socket_bind( ip, serverport );
+ socket:settimeout( 0 )
+ _readlistlen = addsocket(_readlist, socket, _readlistlen)
+ _socketlist[ socket ] = handler
+ handler.paused = false;
+ end
+ end
handler.ip = function( )
return ip
end
@@ -208,6 +230,7 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, maxco
end
handler.readbuffer = function( )
if connections > maxconnections then
+ handler.pause( )
out_put( "server.lua: refused new client connection: server full" )
return false
end