Changeset

846:77244ba297ac

net.server: Some fixes for SSL/TLS handshake handling
author Matthew Wild <mwild1@gmail.com>
date Fri, 27 Feb 2009 18:40:17 +0000
parents 845:fc3dced9801e
children 847:2d424936723c
files net/server.lua
diffstat 1 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/net/server.lua	Fri Feb 27 17:56:07 2009 +0000
+++ b/net/server.lua	Fri Feb 27 18:40:17 2009 +0000
@@ -480,16 +480,19 @@
     if sslctx then    -- ssl?
         ssl = true
         local wrote
+        local read
         local handshake = coroutine_wrap( function( client )    -- create handshake coroutine
                 local err
                 for i = 1, 10 do    -- 10 handshake attemps
+                    _sendlistlen = ( wrote and removesocket( _sendlist, socket, _sendlistlen ) ) or _sendlistlen
+                    _readlistlen = ( read and removesocket( _readlist, socket, _readlistlen ) ) or _readlistlen
+                    read, wrote = nil, nil
                     _, err = client:dohandshake( )
                     if not err then
                         --out_put( "server.lua: ssl handshake done" )
-                        _sendlistlen = ( wrote and removesocket( _sendlist, socket, _sendlistlen ) ) or _sendlistlen
                         handler.readbuffer = _readbuffer    -- when handshake is done, replace the handshake function with regular functions
                         handler.sendbuffer = _sendbuffer
-                        --return dispatch( handler )
+                        -- return dispatch( handler )
                         return true
                     else
                         out_put( "server.lua: error during ssl handshake: ", err )
@@ -497,6 +500,10 @@
                             _sendlistlen = _sendlistlen + 1
                             _sendlist[ _sendlistlen ] = client
                             wrote = true
+                        elseif err == "wantread" and not read then
+                                _readlistlen = _readlistlen + 1
+                                _readlist [ _readlistlen ] = client
+                                read = true
                         end
                         --coroutine_yield( handler, nil, err )    -- handshake not finished
                         coroutine_yield( )
@@ -558,8 +565,8 @@
                 handler.starttls = nil
                 needtls = nil
 
-                handler.receivedata = handler.handshake
-                handler.dispatchdata = handler.handshake
+                handler.readbuffer = handshake
+                handler.sendbuffer = handshake
                 handshake( socket )    -- do handshake
             end
             handler.readbuffer = _readbuffer