Comparison

net/server_select.lua @ 3003:48871a549b4c

net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
author Matthew Wild <mwild1@gmail.com>
date Wed, 05 May 2010 15:25:48 +0100
parent 3002:d1f864ed44c0
child 3007:9d122a6ae674
child 3008:23915803adbf
comparison
equal deleted inserted replaced
3002:d1f864ed44c0 3003:48871a549b4c
673 _socketlist[ socket ] = nil 673 _socketlist[ socket ] = nil
674 socket:close( ) 674 socket:close( )
675 --mem_free( ) 675 --mem_free( )
676 end 676 end
677 677
678 local function link(sender, receiver, buffersize)
679 sender:set_mode(buffersize);
680 local sender_locked;
681 local _sendbuffer = receiver.sendbuffer;
682 function receiver.sendbuffer()
683 _sendbuffer();
684 if sender_locked and receiver.bufferlen() < buffersize then
685 sender:lock_read(false); -- Unlock now
686 sender_locked = nil;
687 end
688 end
689
690 local _readbuffer = sender.readbuffer;
691 function sender.readbuffer()
692 _readbuffer();
693 if not sender_locked and receiver.bufferlen() >= buffersize then
694 sender_locked = true;
695 sender:lock_read(true);
696 end
697 end
698 end
699
678 ----------------------------------// PUBLIC //-- 700 ----------------------------------// PUBLIC //--
679 701
680 addserver = function( addr, port, listeners, pattern, sslctx ) -- this function provides a way for other scripts to reg a server 702 addserver = function( addr, port, listeners, pattern, sslctx ) -- this function provides a way for other scripts to reg a server
681 local err 703 local err
682 if type( listeners ) ~= "table" then 704 if type( listeners ) ~= "table" then
896 918
897 addclient = addclient, 919 addclient = addclient,
898 wrapclient = wrapclient, 920 wrapclient = wrapclient,
899 921
900 loop = loop, 922 loop = loop,
923 link = link,
901 stats = stats, 924 stats = stats,
902 closeall = closeall, 925 closeall = closeall,
903 addtimer = addtimer, 926 addtimer = addtimer,
904 addserver = addserver, 927 addserver = addserver,
905 getserver = getserver, 928 getserver = getserver,