- be safe for either "ethernet v1" or "PPPoE", both take 8 bytes\r
- IPv6 header: 40 bytes (IPv4 is 20)\r
- TCP/UDP header: 20 bytes\r
+ packetbasesize is deprecated and should not be used anymore\r
}\r
packetbasesize = 1432;\r
- receivebufsize=packetbasesize*8;\r
+ receivebufsize=16384;\r
\r
var\r
absolutemaxs:integer=0;\r
lasterror:integer;\r
destroying:boolean;\r
recvbufsize:integer;\r
+ datasentcalled:boolean;\r
+ {$ifdef mswindows}\r
+ sendflushlasterror:integer;\r
+ {$endif}\r
+\r
+ sendflushmaxwrite:integer;\r
+ //how much to write to the socket internally in one go. higher values allow faster throughput especially if latency is high\r
+ //but it also causes onsenddata to be called less often (typically once for every sendflushmaxwrite bytes)\r
+\r
function receivestr:tbufferstring; virtual;\r
procedure close;\r
procedure abort;\r
\r
var\r
firsttimer : tltimer ;\r
- firsttask , lasttask , currenttask : tltask ;\r
+ firsttask , lasttask : tltask ;\r
\r
numread : integer ;\r
mustrefreshfds : boolean ;\r
state := wsclosed;\r
fdhandlein := -1;\r
fdhandleout := -1;\r
+ sendflushmaxwrite := 16384;\r
end;\r
\r
destructor tlasio.destroy;\r
result := -1;\r
exit;\r
end;\r
+ datasentcalled := false;\r
+\r
+ lensent := sendflushmaxwrite;\r
+ if (lensent <= 0) then lensent := sendq.size;\r
\r
- lensent := sendq.get(data,packetbasesize*2);\r
+ lensent := sendq.get(data,lensent);\r
if assigned(data) then result := myfdwrite(fdhandleout,data^,lensent) else result := 0;\r
\r
if result = -1 then lensent := 0 else lensent := result;\r
\r
+ {$ifdef mswindows}\r
+ if (result = -1) then sendflushlasterror := getlasterror else sendflushlasterror := 0;\r
+ {$endif}\r
+\r
//sendq := copy(sendq,lensent+1,length(sendq)-lensent);\r
sendq.del(lensent);\r
\r
\r
end else begin\r
{$ifdef mswindows}\r
- if getlasterror=WSAEWOULDBLOCK then begin\r
+ if sendflushlasterror=WSAEWOULDBLOCK then begin\r
//the asynchronous nature of windows messages means we sometimes\r
//get here with the buffer full\r
//so do nothing in that case\r
end else\r
{$endif}\r
begin\r
- internalclose({$ifdef mswindows}getlasterror{$else}linuxerror{$endif});\r
+ internalclose({$ifdef mswindows}sendflushlasterror{$else}linuxerror{$endif});\r
end \r
end;\r
end;\r
end else begin\r
//everything is sent fire off ondatasent event\r
if fdhandleout >= 0 then eventcore.wmasterclr(fdhandleout);//fd_clr(fdhandleout,fdswmaster);\r
- if assigned(ondatasent) then tltask.create(self.dodatasent,self,0,0);\r
+ if assigned(ondatasent) then begin\r
+ if not datasentcalled then begin\r
+ tltask.create(self.dodatasent,self,0,0);\r
+ datasentcalled := true;\r
+ end;\r
+ end;\r
+\r
end;\r
if assigned(onfdwrite) then onfdwrite(self,0);\r
end;\r
{$ifndef mswindows}\r
procedure tltimer.resettimes;\r
begin\r
- gettimeofday(nextts);\r
+ gettimemonotonic(nextts);\r
{if not initialevent then} tv_add(nextts,interval);\r
end;\r
{$endif}\r
\r
procedure processtasks;//inline;\r
var\r
- temptask : tltask ;\r
-\r
+ currenttask:tltask;\r
begin\r
\r
- if not assigned(currenttask) then begin\r
+ while assigned(firsttask) do begin\r
currenttask := firsttask;\r
- firsttask := nil;\r
- lasttask := nil;\r
- end;\r
- while assigned(currenttask) do begin\r
+ firsttask := firsttask.nexttask;\r
+ if not assigned(firsttask) then lasttask := nil;\r
\r
if assigned(currenttask.handler) then currenttask.handler(currenttask.wparam,currenttask.lparam);\r
- if assigned(currenttask) then begin\r
- temptask := currenttask;\r
- currenttask := currenttask.nexttask;\r
- temptask.free;\r
- end;\r
- //writeln('processed a task');\r
+ currenttask.free;\r
end;\r
-\r
+ currenttask := nil;\r
end;\r
\r
\r
procedure disconnecttasks(aobj:tobject);\r
var\r
currenttasklocal : tltask ;\r
- counter : byte ;\r
+\r
begin\r
- for counter := 0 to 1 do begin\r
- if counter = 0 then begin\r
- currenttasklocal := firsttask; //main list of tasks\r
- end else begin\r
- currenttasklocal := currenttask; //needed in case called from a task\r
- end;\r
- // note i don't bother to destroy the links here as that will happen when\r
- // the list of tasks is processed anyway\r
- while assigned(currenttasklocal) do begin\r
- if currenttasklocal.obj = aobj then begin\r
- currenttasklocal.obj := nil;\r
- currenttasklocal.handler := nil;\r
- end;\r
- currenttasklocal := currenttasklocal.nexttask;\r
+ currenttasklocal := firsttask; //main list of tasks\r
+\r
+ // note i don't bother to destroy the links here as that will happen when\r
+ // the list of tasks is processed anyway\r
+ while assigned(currenttasklocal) do begin\r
+ if currenttasklocal.obj = aobj then begin\r
+ currenttasklocal.obj := nil;\r
+ currenttasklocal.handler := nil;\r
end;\r
+ currenttasklocal := currenttasklocal.nexttask;\r
end;\r
end;\r
\r