Software /
code /
prosody
Comparison
net/server_event.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 | 3149:5aca2f01c0f9 |
comparison
equal
deleted
inserted
replaced
3002:d1f864ed44c0 | 3003:48871a549b4c |
---|---|
843 end | 843 end |
844 signal_events[signal_num] = base:addevent(signal_num, EV_SIGNAL, _handler); | 844 signal_events[signal_num] = base:addevent(signal_num, EV_SIGNAL, _handler); |
845 return signal_events[signal_num]; | 845 return signal_events[signal_num]; |
846 end | 846 end |
847 | 847 |
848 local function link(sender, receiver, buffersize) | |
849 sender:set_mode(buffersize); | |
850 local sender_locked; | |
851 | |
852 function receiver:ondrain() | |
853 if sender_locked then | |
854 sender:resume(); | |
855 sender_locked = nil; | |
856 end | |
857 end | |
858 | |
859 function sender:onincoming(data) | |
860 receiver:write(data); | |
861 if receiver.writebufferlen >= buffersize then | |
862 sender_locked = true; | |
863 sender:pause(); | |
864 end | |
865 end | |
866 end | |
867 | |
848 return { | 868 return { |
849 | 869 |
850 cfg = cfg, | 870 cfg = cfg, |
851 base = base, | 871 base = base, |
852 loop = loop, | 872 loop = loop, |
873 link = link, | |
853 event = event, | 874 event = event, |
854 event_base = base, | 875 event_base = base, |
855 addevent = newevent, | 876 addevent = newevent, |
856 addserver = addserver, | 877 addserver = addserver, |
857 addclient = addclient, | 878 addclient = addclient, |