From cda2e4bba1a2bc9bd3e48076f236ac843086aff3 Mon Sep 17 00:00:00 2001 From: beware Date: Mon, 30 Jun 2014 22:42:35 +0000 Subject: [PATCH] fix 2 send related bugs git-svn-id: file:///svnroot/lcore/trunk@139 b1de8a11-f9be-4011-bde0-cc7ace90066a --- lcore.pas | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lcore.pas b/lcore.pas index d346c52..097ea79 100644 --- a/lcore.pas +++ b/lcore.pas @@ -106,6 +106,10 @@ interface lasterror:integer; destroying:boolean; recvbufsize:integer; + datasentcalled:boolean; + {$ifdef mswindows} + sendflushlasterror:integer; + {$endif} function receivestr:tbufferstring; virtual; procedure close; procedure abort; @@ -484,12 +488,17 @@ begin result := -1; exit; end; + datasentcalled := false; lensent := sendq.get(data,packetbasesize*2); if assigned(data) then result := myfdwrite(fdhandleout,data^,lensent) else result := 0; if result = -1 then lensent := 0 else lensent := result; + {$ifdef mswindows} + if (result = -1) then sendflushlasterror := getlasterror else sendflushlasterror := 0; + {$endif} + //sendq := copy(sendq,lensent+1,length(sendq)-lensent); sendq.del(lensent); @@ -562,14 +571,14 @@ begin end else begin {$ifdef mswindows} - if getlasterror=WSAEWOULDBLOCK then begin + if sendflushlasterror=WSAEWOULDBLOCK then begin //the asynchronous nature of windows messages means we sometimes //get here with the buffer full //so do nothing in that case end else {$endif} begin - internalclose({$ifdef mswindows}getlasterror{$else}linuxerror{$endif}); + internalclose({$ifdef mswindows}sendflushlasterror{$else}linuxerror{$endif}); end end; end; @@ -577,7 +586,13 @@ begin end else begin //everything is sent fire off ondatasent event if fdhandleout >= 0 then eventcore.wmasterclr(fdhandleout);//fd_clr(fdhandleout,fdswmaster); - if assigned(ondatasent) then tltask.create(self.dodatasent,self,0,0); + if assigned(ondatasent) then begin + if not datasentcalled then begin + tltask.create(self.dodatasent,self,0,0); + datasentcalled := true; + end; + end; + end; if assigned(onfdwrite) then onfdwrite(self,0); end; -- 2.30.2