lcore.org gitweb
/
lcore.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix a typo in previous commit
[lcore.git]
/
lcore.pas
diff --git
a/lcore.pas
b/lcore.pas
index da0fd66b89365b4272b74707dd40de189c7f2f58..69da11ea8089e1bebbe7b3377755c778463691d4 100755
(executable)
--- a/
lcore.pas
+++ b/
lcore.pas
@@
-35,7
+35,13
@@
interface
\r
\r
const
\r
\r
\r
const
\r
- packetbasesize = 1460;
\r
+ {how this number is made up:
\r
+ - ethernet: MTU 1500
\r
+ - 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
+ }
\r
+ packetbasesize = 1432;
\r
receivebufsize=packetbasesize*8;
\r
\r
var
\r
receivebufsize=packetbasesize*8;
\r
\r
var
\r
@@
-67,8
+73,9
@@
interface
TSendData = procedure (Sender: TObject; BytesSent: Integer) of object;
\r
\r
tlcomponent = class(tcomponent)
\r
TSendData = procedure (Sender: TObject; BytesSent: Integer) of object;
\r
\r
tlcomponent = class(tcomponent)
\r
+ private
\r
+ procedure releasetaskhandler(wparam,lparam:longint);
\r
public
\r
public
\r
- released:boolean;
\r
procedure release; virtual;
\r
destructor destroy; override;
\r
end;
\r
procedure release; virtual;
\r
destructor destroy; override;
\r
end;
\r
@@
-88,8
+95,6
@@
interface
onsenddata : tsenddata ;
\r
ondatasent : tsocketevent ;
\r
//connected : boolean ;
\r
onsenddata : tsenddata ;
\r
ondatasent : tsocketevent ;
\r
//connected : boolean ;
\r
- nextasin : tlasio ;
\r
- prevasin : tlasio ;
\r
\r
recvq : tfifo;
\r
OnBgException : TBgExceptionEvent ;
\r
\r
recvq : tfifo;
\r
OnBgException : TBgExceptionEvent ;
\r
@@
-221,7
+226,6
@@
procedure messageloop;
procedure exitmessageloop;
\r
\r
var
\r
procedure exitmessageloop;
\r
\r
var
\r
- firstasin : tlasio ;
\r
firsttimer : tltimer ;
\r
firsttask , lasttask , currenttask : tltask ;
\r
\r
firsttimer : tltimer ;
\r
firsttask , lasttask , currenttask : tltask ;
\r
\r
@@
-279,12
+283,15
@@
begin
inherited destroy;
\r
end;
\r
\r
inherited destroy;
\r
end;
\r
\r
-
\r
+procedure tlcomponent.releasetaskhandler(wparam,lparam:longint);
\r
+begin
\r
+ free;
\r
+end;
\r
\r
\r
procedure tlcomponent.release;
\r
begin
\r
\r
\r
procedure tlcomponent.release;
\r
begin
\r
-
released := true
;
\r
+
addtask(releasetaskhandler,self,0,0)
;
\r
end;
\r
\r
procedure tlasio.release;
\r
end;
\r
\r
procedure tlasio.release;
\r
@@
-337,26
+344,12
@@
begin
state := wsclosed;
\r
fdhandlein := -1;
\r
fdhandleout := -1;
\r
state := wsclosed;
\r
fdhandlein := -1;
\r
fdhandleout := -1;
\r
- nextasin := firstasin;
\r
- prevasin := nil;
\r
- if assigned(nextasin) then nextasin.prevasin := self;
\r
- firstasin := self;
\r
-
\r
- released := false;
\r
end;
\r
\r
destructor tlasio.destroy;
\r
begin
\r
destroying := true;
\r
if state <> wsclosed then close;
\r
end;
\r
\r
destructor tlasio.destroy;
\r
begin
\r
destroying := true;
\r
if state <> wsclosed then close;
\r
- if prevasin <> nil then begin
\r
- prevasin.nextasin := nextasin;
\r
- end else begin
\r
- firstasin := nextasin;
\r
- end;
\r
- if nextasin <> nil then begin
\r
- nextasin.prevasin := prevasin;
\r
- end;
\r
recvq.free;
\r
sendq.free;
\r
inherited destroy;
\r
recvq.free;
\r
sendq.free;
\r
inherited destroy;
\r
@@
-399,6
+392,9
@@
end;
procedure tlasio.internalclose(error:word);
\r
begin
\r
if (state<>wsclosed) and (state<>wsinvalidstate) then begin
\r
procedure tlasio.internalclose(error:word);
\r
begin
\r
if (state<>wsclosed) and (state<>wsinvalidstate) then begin
\r
+ // -2 is a special indication that we should just exist silently
\r
+ // (used for connect failure handling when socket creation fails)
\r
+ if (fdhandlein = -2) and (fdhandleout = -2) then exit;
\r
if (fdhandlein < 0) or (fdhandleout < 0) then raise exception.create('internalclose called with invalid fd handles');
\r
eventcore.rmasterclr(fdhandlein);//fd_clr(fdhandlein,fdsrmaster);
\r
eventcore.wmasterclr(fdhandleout);//fd_clr(fdhandleout,fdswmaster);
\r
if (fdhandlein < 0) or (fdhandleout < 0) then raise exception.create('internalclose called with invalid fd handles');
\r
eventcore.rmasterclr(fdhandlein);//fd_clr(fdhandlein,fdsrmaster);
\r
eventcore.wmasterclr(fdhandleout);//fd_clr(fdhandleout,fdswmaster);
\r
@@
-489,7
+485,10
@@
var
// fdstestr : fdset;
\r
// fdstestw : fdset;
\r
begin
\r
// fdstestr : fdset;
\r
// fdstestw : fdset;
\r
begin
\r
- if state <> wsconnected then exit;
\r
+ if state <> wsconnected then begin
\r
+ result := -1;
\r
+ exit;
\r
+ end;
\r
\r
lensent := sendq.get(data,packetbasesize*2);
\r
if assigned(data) then result := myfdwrite(fdhandleout,data^,lensent) else result := 0;
\r
\r
lensent := sendq.get(data,packetbasesize*2);
\r
if assigned(data) then result := myfdwrite(fdhandleout,data^,lensent) else result := 0;
\r
@@
-567,7
+566,16
@@
begin
internalclose(0);
\r
\r
end else begin
\r
internalclose(0);
\r
\r
end else begin
\r
- internalclose({$ifdef win32}getlasterror{$else}linuxerror{$endif});
\r
+ {$ifdef win32}
\r
+ if getlasterror=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 win32}getlasterror{$else}linuxerror{$endif});
\r
+ end
\r
end;
\r
end;
\r
\r
end;
\r
end;
\r
\r
@@
-734,8
+742,6
@@
begin
end;
\r
interval := 1000;
\r
enabled := true;
\r
end;
\r
interval := 1000;
\r
enabled := true;
\r
- released := false;
\r
-
\r
end;
\r
\r
destructor tltimer.destroy;
\r
end;
\r
\r
destructor tltimer.destroy;
\r
@@
-886,7
+892,6
@@
end;
\r
\r
begin
\r
\r
\r
begin
\r
- firstasin := nil;
\r
firsttask := nil;
\r
\r
\r
firsttask := nil;
\r
\r
\r