From a5e04c97106d122f8b04fc8aa1d4f19dcca1c956 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tom=C3=A1=C5=A1=20Brada?= Date: Wed, 2 Dec 2015 17:52:22 +0100 Subject: [PATCH] Upload REKTing. --- Upload.pas | 14 +++++++++----- UploadThread.pas | 7 ++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Upload.pas b/Upload.pas index c87de0a..34a0030 100644 --- a/Upload.pas +++ b/Upload.pas @@ -117,7 +117,7 @@ procedure tPrv.DoLSEG(count:byte; base,limit: array of LongWord); var l,fb:LongWord; var tbytes:LongWOrd; begin - writeln('Upload: ',string(ch^.remote),'/',chan,' LSEG'); + write('Upload: ',string(ch^.remote),'/',chan,' LSEG '); if not isOpen then begin ch^.StreamInit(err,3); err.WriteByte(upEPROTO); @@ -166,6 +166,7 @@ procedure tPrv.DoLSEG(count:byte; base,limit: array of LongWord); err.WriteWord(tbytes,4); err.WriteByte(uc.seg); ch^.Send(err); + writeln('x',uc.seg); Start; end; @@ -309,7 +310,7 @@ procedure tPrv.ChatTimeout(willwait:LongWord); begin if WillWait<8000 then exit; writeln('Upload: prv for ',string(ch^.remote),'/',chan,' ChatTimeout'); - Close; + Close(false); end; {***AGGREGATOR***} @@ -377,7 +378,7 @@ end; procedure tAggr.Start(ac:byte); begin - //writeln('Upload: aggr for ',string(remote),' start chan ',ac); + //writeln('Upload: aggr for ',string(remote),'/',ac,' start seg=',chan[ac]^.uc.seg); assert(assigned(chan[ac])); EnterCriticalSection(thr.crit); assert(not assigned(thr.chans[ac])); @@ -385,7 +386,8 @@ procedure tAggr.Start(ac:byte); chan[ac]^.uc.wcur:=chan[ac]^.uc.weight; UnShedule(@Periodic); Shedule(700,@Periodic); - if thr.stop or thr.wait then ResetMark else {do not reset if running}; + {do not reset if resuming from wait} + if thr.stop {or thr.wait} then ResetMark else {do not reset if running}; thr.Start; {wake up, or start if not running} LeaveCriticalSection(thr.crit); end; @@ -408,9 +410,11 @@ procedure tAggr.Periodic; for i:=0 to high(chan) do if assigned(chan[i]) then with chan[i]^ do begin if not active then continue; EnterCriticalSection(thr.crit); + //writeln('periodic ',thr.stop,thr.wait,uc.seg); e:=uc.Seg=0; LeaveCriticalSection(thr.crit); - if e then NotifyDone; + if e + then NotifyDone; end; exit end; if acks=0 then begin diff --git a/UploadThread.pas b/UploadThread.pas index 8f9c6f2..0beaece 100644 --- a/UploadThread.pas +++ b/UploadThread.pas @@ -28,6 +28,7 @@ type tUploadThr=object buffer:array [0..2047] of byte; stop:boolean; {the therad is stopped or stopping} wait:boolean; {the therad is waiting for data} + waitc:byte; procedure Main; procedure Init(source:tNetAddr); @@ -75,9 +76,13 @@ procedure tUploadThr.Main; end; if wait then begin LeaveCriticalSection(crit); + if waitc>10 + then stop:=true + else inc(waitc); sleep(200); continue; end; + waitc:=0; LastTime:=SysUtils.Now; chan:=chans[curc]; seg:=@chan^.s[chan^.seg]; @@ -142,7 +147,7 @@ procedure tUploadThr.Done; EnterCriticalSection(crit); stop:=true; LeaveCriticalSection(crit); - WaitForThreadterminate(thrid,999999); + WaitForThreadterminate(thrid,65535); DoneCriticalSection(crit); end; END. \ No newline at end of file -- 2.11.4.GIT