X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/968c333d05db5d5ecf3599f8e304c67e64f21159..309429a3acfa50bd4e928b8a5728dc863e9c767b:/lcore.pas

diff --git a/lcore.pas b/lcore.pas
old mode 100755
new mode 100644
index c936b59..097ea79
--- a/lcore.pas
+++ b/lcore.pas
@@ -45,7 +45,7 @@ interface
     receivebufsize=packetbasesize*8;
 
   var
-    absoloutemaxs:integer=0;
+    absolutemaxs:integer=0;
 
   type
     {$ifdef ver1_0}
@@ -84,8 +84,8 @@ interface
     public
       state              : tsocketstate      ;
       ComponentOptions   : TWSocketOptions;
-      fdhandlein         : Longint           ;  {file discriptor}
-      fdhandleout        : Longint           ;  {file discriptor}
+      fdhandlein         : Longint           ;  {file descriptor}
+      fdhandleout        : Longint           ;  {file descriptor}
 
       onsessionclosed    : tsocketevent      ;
       ondataAvailable    : tsocketevent      ;
@@ -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;
@@ -164,7 +168,7 @@ interface
 //      finitialevent       : boolean           ;
       fontimer            : tnotifyevent      ;
       fenabled            : boolean           ;
-      finterval	          : integer	     ; {miliseconds, default 1000}
+      finterval	          : integer	     ; {milliseconds, default 1000}
       {$ifndef mswindows}
         procedure resettimes;
       {$endif}
@@ -173,7 +177,7 @@ interface
       procedure setenabled(newvalue : boolean);
       procedure setinterval(newvalue : integer);
     public
-      //making theese public for now, this code should probablly be restructured later though
+      //making these public for now, this code should probably be restructured later though
       prevtimer          : tltimer           ;
       nexttimer          : tltimer           ;
       nextts	         : ttimeval          ;
@@ -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;
@@ -590,7 +605,7 @@ begin
       if (numread=0) and (not mustrefreshfds) then begin
         {if i remember correctly numread=0 is caused by eof
         if this isn't dealt with then you get a cpu eating infinite loop
-        however if onsessionconencted has called processmessages that could
+        however if onsessionconnected has called processmessages that could
         cause us to drop to here with an empty recvq and nothing left to read
         and we don't want that to cause the socket to close}
 
@@ -834,7 +849,7 @@ begin
     end else begin
       currenttasklocal := currenttask; //needed in case called from a task
     end;
-    // note i don't bother to sestroy the links here as that will happen when
+    // note i don't bother to destroy the links here as that will happen when
     // the list of tasks is processed anyway
     while assigned(currenttasklocal) do begin
       if currenttasklocal.obj = aobj then begin