Comparison

net/server.lua @ 563:099d8a102deb

Add TLS socket to readlist before handshake starts, fixes major slow-down on TLS connections
author Matthew Wild <mwild1@gmail.com>
date Fri, 05 Dec 2008 19:24:01 +0000
parent 562:04ee161d936b
child 564:779ab5b99e13
child 565:3a49d85cafbc
comparison
equal deleted inserted replaced
562:04ee161d936b 563:099d8a102deb
502 local wrote, read 502 local wrote, read
503 503
504 handler.starttls = function (now) 504 handler.starttls = function (now)
505 if not now then out_put("server.lua: we need to do tls, but delaying until later"); handler.need_tls = true; return; end 505 if not now then out_put("server.lua: we need to do tls, but delaying until later"); handler.need_tls = true; return; end
506 out_put( "server.lua: attempting to start tls on "..tostring(socket) ) 506 out_put( "server.lua: attempting to start tls on "..tostring(socket) )
507 local oldsocket = socket;
507 socket, err = ssl_wrap( socket, sslctx ) -- wrap socket 508 socket, err = ssl_wrap( socket, sslctx ) -- wrap socket
508 out_put("sslwrapped socket is "..tostring(socket)); 509 out_put("sslwrapped socket is "..tostring(socket));
509 if err then 510 if err then
510 out_put( "server.lua: ssl error: ", err ) 511 out_put( "server.lua: ssl error: ", err )
511 return nil, nil, err -- fatal error 512 return nil, nil, err -- fatal error
512 end 513 end
513 socket:settimeout( 1 ) 514 socket:settimeout(0);
515
516 -- Add the new socket to our system
517 socketlist[ socket ] = handler
518 readlen = readlen + 1
519 readlist[ readlen ] = socket
520
521 -- Remove traces of the old socket
522 readlen = removesocket( readlist, oldsocket, readlen )
523 socketlist [ oldsocket ] = nil;
524
514 send = socket.send 525 send = socket.send
515 receive = socket.receive 526 receive = socket.receive
516 close = socket.close 527 close = socket.close
517 handler.ssl = function( ) 528 handler.ssl = function( )
518 return true 529 return true
534 out_put( "server.lua: ssl handshake done" ) 545 out_put( "server.lua: ssl handshake done" )
535 writelen = ( wrote and removesocket( writelist, socket, writelen ) ) or writelen 546 writelen = ( wrote and removesocket( writelist, socket, writelen ) ) or writelen
536 handler.receivedata = handler._receivedata -- when handshake is done, replace the handshake function with regular functions 547 handler.receivedata = handler._receivedata -- when handshake is done, replace the handshake function with regular functions
537 handler.dispatchdata = handler._dispatchdata 548 handler.dispatchdata = handler._dispatchdata
538 handler.need_tls = nil 549 handler.need_tls = nil
539 socketlist[ client ] = handler
540 readlen = readlen + 1
541 readlist[ readlen ] = client
542 return true; 550 return true;
543 else 551 else
544 out_put( "server.lua: error during ssl handshake: ", err ) 552 out_put( "server.lua: error during ssl handshake: ", err )
545 if err == "wantwrite" then 553 if err == "wantwrite" then
546 if wrote == nil then 554 if wrote == nil then