From 397798876c8de96686490ef08bbdbeebbd940229 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tom=C3=A1=C5=A1=20Brada?= Date: Wed, 21 Oct 2015 18:04:35 +0200 Subject: [PATCH] Few fixes in support units. --- Chat.pas | 7 +++---- ServerLoop.pas | 6 +++--- Store1.pas | 2 +- TC.pas | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Chat.pas b/Chat.pas index f7d67df..9391ffc 100644 --- a/Chat.pas +++ b/Chat.pas @@ -55,7 +55,7 @@ uses SysUtils; procedure tChat.Init(const iremote:tNetAddr); begin remote:=iremote; - opcode:=128; + opcode:=128+Random(128); while ServerLoop.IsMsgHandled(opcode,remote) do inc(opcode); InitFrom(remote,opcode); end; @@ -139,7 +139,6 @@ end; procedure tChat.Done; begin - {called from sheduler, Done is unsheduled, Resend is not sheduled since ack was received when Done was sheduled} if txLen>0 then FreeMem(txPk,txLen); SetMsgHandler(opcode,remote,nil); if assigned(DisposeHook) then DisposeHook @@ -184,11 +183,11 @@ procedure tChat.OnReply(msg:tSMsg); if (aseq=txSeq)and(txLen>0) {it is current} then begin if txTime>0 then RTT:=Round((Now-txTime)*MsecsPerDay); FreeMem(txPk,txLen); + UnShedule(@Resend); + if Closed then Shedule(5,@Done); TxLen:=0; txPk:=nil; if assigned(callback) then callback(msg,false); - ServerLoop.UnShedule(@Resend); - if Closed then ServerLoop.Shedule(5000,@Done); end else {write(' old-ack')it is ack of old data, do nothing}; end; if seq>0 then {some data} begin diff --git a/ServerLoop.pas b/ServerLoop.pas index 705c0d3..c27d882 100644 --- a/ServerLoop.pas +++ b/ServerLoop.pas @@ -163,7 +163,7 @@ procedure UnSetMsgHandler(const from:tNetAddr; opcode:byte); Dispose(PT[h]); PT[h]:=nil; {go reverse exit on null, hash them, match: move to H and stop} - i:=h-1; + if h=0 then i:=high(PT) else i:=h-1; while (i<>h)and assigned(PT[i]) do begin if (PT[i]^.remote.hash+PT[i]^.opcode)=h then begin PT[h]:=PT[i]; @@ -276,7 +276,7 @@ procedure ShedRun; inc(tasks); end; if pollTimeout=0 then pollTimeOut:=1; - //writeln('ServerLoop: tasks=',tasks); + //if delta >4990 then writeln('ServerLoop: tasks=',tasks); end; procedure Main; @@ -358,7 +358,7 @@ procedure UnShedule(h:tOnTimer); pcur:=@ShedTop; cur:=pcur^; while assigned(cur) do begin - if cur^.cb=h then begin + if 0=CompareByte(cur^.cb,h,sizeof(h)) then begin pcur^:=cur^.next; {unlink from main list} cur^.next:=ShedUU; ShedUU:=cur; {link to unused} cur:=pcur^; diff --git a/Store1.pas b/Store1.pas index 8480241..3195cb3 100644 --- a/Store1.pas +++ b/Store1.pas @@ -46,7 +46,7 @@ end; procedure tStoreObjectInfo.Open(const fid:tfid); begin mkfilen(filename,'f',fid); - dh:=FileOpen(filename,fmOpenRead); + dh:=FileOpen(filename,fmOpenRead or fmShareDenyWrite); if dh<>-1 then begin rc:=0; final:=true; diff --git a/TC.pas b/TC.pas index 508059d..e9ec2d2 100644 --- a/TC.pas +++ b/TC.pas @@ -216,7 +216,6 @@ procedure tTCS.TransmitDelay; var txwait:real; var burst:word; begin - txLastSize:=0; txwait:=0; burst:=0; if (siMark=0)and(cur.Size0) then exit; {no burst, no shedule next} -- 2.11.4.GIT