X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;ds=sidebyside;f=net%2Fserver_event.lua;h=b467a84dc6c147e6f8ca034fb1e0809d5dcf25a7;hb=4e9ad86f42f78e32d5a983b62277a0552c853a9c;hp=1a77953d2ce02d5c7c1d755aa833942c73f6882f;hpb=6868881f8edc7c0f4b34b17a9e5ba0e0cad70d71;p=prosody.git diff --git a/net/server_event.lua b/net/server_event.lua index 1a77953d..b467a84d 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -290,7 +290,8 @@ do -- Public methods function interface_mt:write(data) - vdebug( "try to send data to client, id/data:", self.id, data ) + if self.nowriting then return nil, "locked" end + --vdebug( "try to send data to client, id/data:", self.id, data ) data = tostring( data ) local len = string_len( data ) local total = len + self.writebufferlen @@ -308,6 +309,7 @@ do return true end function interface_mt:close(now) + if self.nointerface then return nil, "locked"; end debug( "try to close client connection with id:", self.id ) if self.type == "client" then self.fatalerror = "client to close" @@ -370,7 +372,9 @@ do return self.addr end - + function interface_mt:set_sslctx(sslctx) + self._sslctx = sslctx; + end function interface_mt:starttls() debug( "try to start ssl at client id:", self.id ) @@ -386,6 +390,7 @@ do end self._usingssl = true self.startsslcallback = function( ) -- we have to start the handshake outside of a read/write event + self.startsslcallback = nil self:_start_ssl(); self.eventstarthandshake = nil return -1 @@ -470,7 +475,7 @@ do interface.eventwritetimeout = false end end - local succ, err, byte = interface.send( interface.conn, interface.writebuffer, 1, interface.writebufferlen ) + local succ, err, byte = interface.conn:send( interface.writebuffer, 1, interface.writebufferlen ) --vdebug( "write data:", interface.writebuffer, "error:", err, "part:", byte ) if succ then -- writing succesful interface.writebuffer = "" @@ -511,7 +516,7 @@ do end end end - local usingssl, receive = interface._usingssl, interface.receive; + interface.readcallback = function( event ) -- called on read events --vdebug( "new client read event, id/ip/port:", interface, ip, port ) if interface.noreading or interface.fatalerror then -- leave this event @@ -526,7 +531,7 @@ do interface.eventread = nil return -1 else -- can read - if usingssl then -- handle luasec + if interface._usingssl then -- handle luasec if interface.eventwritetimeout then -- ok, in the past writecallback was regged local ret = interface.writecallback( ) -- call it --vdebug( "tried to write in readcallback, result:", ret ) @@ -536,8 +541,8 @@ do interface.eventreadtimeout = nil end end - local buffer, err, part = receive( client, pattern ) -- receive buffer with "pattern" - --vdebug( "read data:", buffer, "error:", err, "part:", part ) + local buffer, err, part = interface.conn:receive( pattern ) -- receive buffer with "pattern" + --vdebug( "read data:", tostring(buffer), "error:", tostring(err), "part:", tostring(part) ) buffer = buffer or part or "" local len = string_len( buffer ) if len > cfg.MAX_READ_LENGTH then -- check buffer length @@ -547,7 +552,7 @@ do interface.eventread = nil return -1 end - if err and ( "timeout" ~= err ) then + if err and ( err ~= "timeout" and err ~= "wantread" ) then if "wantwrite" == err then -- need to read on write event if not interface.eventwrite then -- register new write event if needed interface.eventwrite = addevent( base, interface.conn, EV_WRITE, interface.writecallback, cfg.WRITE_TIMEOUT )