535 local wrote |
535 local wrote |
536 local read |
536 local read |
537 handshake = coroutine_wrap( function( client ) -- create handshake coroutine |
537 handshake = coroutine_wrap( function( client ) -- create handshake coroutine |
538 local err |
538 local err |
539 for i = 1, _maxsslhandshake do |
539 for i = 1, _maxsslhandshake do |
540 _sendlistlen = ( wrote and removesocket( _sendlist, socket, _sendlistlen ) ) or _sendlistlen |
540 _sendlistlen = ( wrote and removesocket( _sendlist, client, _sendlistlen ) ) or _sendlistlen |
541 _readlistlen = ( read and removesocket( _readlist, socket, _readlistlen ) ) or _readlistlen |
541 _readlistlen = ( read and removesocket( _readlist, client, _readlistlen ) ) or _readlistlen |
542 read, wrote = nil, nil |
542 read, wrote = nil, nil |
543 _, err = client:dohandshake( ) |
543 _, err = client:dohandshake( ) |
544 if not err then |
544 if not err then |
545 out_put( "server.lua: ssl handshake done" ) |
545 out_put( "server.lua: ssl handshake done" ) |
546 handler.readbuffer = _readbuffer -- when handshake is done, replace the handshake function with regular functions |
546 handler.readbuffer = _readbuffer -- when handshake is done, replace the handshake function with regular functions |
547 handler.sendbuffer = _sendbuffer |
547 handler.sendbuffer = _sendbuffer |
548 _ = status and status( handler, "ssl-handshake-complete" ) |
548 _ = status and status( handler, "ssl-handshake-complete" ) |
549 _readlistlen = addsocket(_readlist, socket, _readlistlen) |
549 _readlistlen = addsocket(_readlist, client, _readlistlen) |
550 return true |
550 return true |
551 else |
551 else |
552 out_put( "server.lua: error during ssl handshake: ", tostring(err) ) |
552 out_put( "server.lua: error during ssl handshake: ", tostring(err) ) |
553 if err == "wantwrite" and not wrote then |
553 if err == "wantwrite" and not wrote then |
554 _sendlistlen = addsocket(_sendlist, client, _sendlistlen) |
554 _sendlistlen = addsocket(_sendlist, client, _sendlistlen) |