From a7e16d5d03ca30598101edb3b9956994a6c24c0d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tom=C3=A1=C5=A1=20Brada?= Date: Fri, 16 Oct 2015 11:52:21 +0200 Subject: [PATCH] Touching teh uploadz. --- opcode.pas | 1 + upmgr.pas | 84 ++++++++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 56 insertions(+), 29 deletions(-) diff --git a/opcode.pas b/opcode.pas index c229dba..4fd8487 100644 --- a/opcode.pas +++ b/opcode.pas @@ -23,6 +23,7 @@ const {FS opcodes} upErrChanInUse=3; upErrNotFound=4; upErrIO=5; + upErrSegNoGet=6; IMPLEMENTATION END. \ No newline at end of file diff --git a/upmgr.pas b/upmgr.pas index 2ffd0f4..12359f4 100644 --- a/upmgr.pas +++ b/upmgr.pas @@ -18,6 +18,7 @@ tPrv=object weight,wcur:Word; isOpen,Active:boolean; seglen:LongWord; + oinfo:tStoreObjectInfo; datafile:file of byte; procedure Init(ag:tAggr_ptr; var nchat:tChat; msg: tSMsg); procedure OnMsg(msg:tSMsg; data:boolean); @@ -57,41 +58,61 @@ DONE(); procedure tPrv.DoGET(const fid:tfid; base,limit:LongWord); var err:tmemorystream; - var info:tStoreObjectInfo; begin - Assert(not(active or isOpen)); //todo + if isOpen then oinfo.Close; + if Active then Stop; //opt ch^.Ack; - info.Open(fid); - if not info.final then begin - info.rc:=200; - Close(info.hnd); - end; - if info.rc>0 then begin + oinfo.Open(fid); + {if not oinfo.final then begin + oinfo.rc:=200; + Close(oinfo.hnd); + end;} + if oinfo.rc>0 then begin ch^.StreamInit(err,3); err.WriteByte(upFAIL); - if (info.rc=1)or(not info.final) then err.WriteByte(upErrNotFound) - else begin err.WriteByte(upErrIO); err.WriteByte(info.rc) end; + if oinfo.rc=1 then err.WriteByte(upErrNotFound) + else begin err.WriteByte(upErrIO); err.WriteByte(oinfo.rc) end; ch^.Send(err); end else begin + datafile:=oinfo.hnd; + isopen:=true; + DoSeg(base,limit); + end; +end; + +procedure tPrv.DoSEG(base,limit:LongWord); + var err:tmemorystream; + begin + if isOpen then begin ch^.StreamInit(err,12); + oinfo.SegSeek(base); + if oinfo.rc>0 then begin + err.WriteByte(upFAIL); + err.WriteByte(upErrIO); + err.WriteByte(oinfo.rc); + ch^.Send(err); + if Active then Stop; + end else begin err.WriteByte(upINFO); - datafile:=info.hnd; - isopen:=true; + datafile:=oinfo.hnd; err.WriteWord(0,2); - err.WriteWord(info.length,4); + err.WriteWord(oinfo.length,4); seglen:=limit; - if info.length0 then goto malformed; base:=msg.stream.ReadWord(4); limit:=msg.stream.ReadWord(4); DoSEG(base, limit); end; -} else goto malformed; end; exit; malformed: @@ -209,7 +235,7 @@ procedure tPrv.ChatTimeout(willwait:LongWord); if WillWait<30000 then exit; wasactive:=active; if Active then Stop; - if isOpen then Close(datafile); + if isOpen then oinfo.Close; isOpen:=false; ch^.Close; ch:=nil; @@ -224,8 +250,8 @@ procedure tPrv.IdleTimeout; ch^.Send(err); ch^.Close; end; - if Active then Stop; - if isOpen then Close(datafile); + Assert(not Active); {is idle} + if isOpen then oinfo.Close; {may still be open} aggr^.UnRef; FreeMem(@self,sizeof(self)); end; @@ -243,7 +269,7 @@ procedure tPrv.Init(ag:tAggr_ptr; var nchat:tChat; msg: tSMsg); wcur:=0; isOpen:=false; Active:=false; inc(aggr^.Cnt); - Shedule(15000,@IdleTimeout); + Shedule(5000,@IdleTimeout); OnMsg(msg,true); end; -- 2.11.4.GIT