/[lcore]/trunk/lcoreselect.pas
ViewVC logotype

Diff of /trunk/lcoreselect.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10 by plugwash, Sun Mar 30 21:39:57 2008 UTC revision 82 by plugwash, Sat Feb 20 13:48:27 2010 UTC
# Line 21  Line 21 
21    {$ifdef VER1_0}    {$ifdef VER1_0}
22      linux,      linux,
23    {$else}    {$else}
24      baseunix,unix,unixutil,      baseunix,unix,unixutil,sockets,
25    {$endif}    {$endif}
26    fd_utils;    fd_utils;
27  var  var
# Line 31  Line 31 
31  function getfdsrmaster : fdset; {$ifdef useinline}inline;{$endif}  function getfdsrmaster : fdset; {$ifdef useinline}inline;{$endif}
32  function getfdswmaster : fdset; {$ifdef useinline}inline;{$endif}  function getfdswmaster : fdset; {$ifdef useinline}inline;{$endif}
33    
34    procedure lcoreinit;
35    
36  implementation  implementation
37  uses  uses
38    lcore,sysutils,    lcore,sysutils,
39    classes,pgtypes,bfifo,    classes,pgtypes,bfifo,
40    {$ifndef nosignal}    {$ifndef nosignal}
41      lsignal;      lsignal,
42    {$endif}    {$endif}
43      ltimevalstuff;
44    
45  {$include unixstuff.inc}  {$include unixstuff.inc}
 {$include ltimevalstuff.inc}  
46    
47  const  const
48    absoloutemaxs_select = (sizeof(fdset)*8)-1;    absoloutemaxs_select = (sizeof(fdset)*8)-1;
# Line 82  Line 84 
84      end;      end;
85      temptimer := currenttimer;      temptimer := currenttimer;
86      currenttimer := currenttimer.nexttimer;      currenttimer := currenttimer.nexttimer;
     if temptimer.released then temptimer.free;  
87    end;    end;
88  end;  end;
89    
# Line 92  Line 93 
93    tempsocket    : tlasio  ;    tempsocket    : tlasio  ;
94    socketcount   : integer ; // for debugging perposes :)    socketcount   : integer ; // for debugging perposes :)
95    dw,bt:integer;    dw,bt:integer;
96      fd : integer;
97  begin  begin
98      //writeln('entering processasios');
99  {  inc(lcoretestcount);}  {  inc(lcoretestcount);}
100    
101      //the message loop will exit if all lasio's and ltimer's and lsignal's are destroyed      //the message loop will exit if all lasio's and ltimer's and lsignal's are destroyed
# Line 104  Line 107 
107    for dw := (maxs shr 5) downto 0 do if (fdsr[dw] or fdsw[dw]) <> 0 then begin    for dw := (maxs shr 5) downto 0 do if (fdsr[dw] or fdsw[dw]) <> 0 then begin
108      for bt := 0 to 31 do if (fdsr[dw] or fdsw[dw]) and (1 shl bt) <> 0 then begin      for bt := 0 to 31 do if (fdsr[dw] or fdsw[dw]) and (1 shl bt) <> 0 then begin
109        inc(socketcount);        inc(socketcount);
110        currentsocket := fdreverse[dw shl 5 or bt];        fd := dw shl 5 or bt;
111          //writeln('reversing fd ',fd);
112          currentsocket := fdreverse[fd];
113        {if not assigned(currentsocket) then raise exception.create('currentsocket not assigned');        {if not assigned(currentsocket) then raise exception.create('currentsocket not assigned');
114        if currentsocket.fdhandlein < 0 then raise exception.create('currentsocket.fdhandlein out of range');}        if currentsocket.fdhandlein < 0 then raise exception.create('currentsocket.fdhandlein out of range');}
115        {i've seen the out of range case actually happening, so it can happen. test: just close the fd - beware}        {i've seen the out of range case actually happening, so it can happen. test: just close the fd - beware}
116        if not assigned(currentsocket) then begin        if not assigned(currentsocket) then begin
117          fdclose(dw shl 5 or bt);          fdclose(fd);
118          continue          continue
119        end;        end;
120        if currentsocket.fdhandlein < 0 then begin        if currentsocket.fdhandlein < 0 then begin
121          fdclose(dw shl 5 or bt);          fdclose(fd);
122          continue          continue
123        end;        end;
124        try        try
125          currentsocket.handlefdtrigger(fd_isset(currentsocket.fdhandlein,fdsr),fd_isset(currentsocket.fdhandleout,fdsw));          currentsocket.handlefdtrigger(fd_isset(fd,fdsr),fd_isset(fd,fdsw));
126        except        except
127          on E: exception do begin          on E: exception do begin
128            currentsocket.HandleBackGroundException(e);            currentsocket.HandleBackGroundException(e);
# Line 133  Line 138 
138      end;      end;
139    end;    end;
140    
   if asinreleaseflag then begin  
     asinreleaseflag := false;  
     currentsocket := firstasin;  
     while assigned(currentsocket) do begin  
       tempsocket := currentsocket;  
       currentsocket := currentsocket.nextasin;  
       if tempsocket.released then begin  
         tempsocket.free;  
       end;  
     end;  
   end;  
141    {    {
142    !!! issues:    !!! issues:
143    - sockets which are released may not be freed because theyre never processed by the loop    - sockets which are released may not be freed because theyre never processed by the loop
# Line 182  Line 176 
176      end;      end;
177    end; *)    end; *)
178  {  debugout('socketcount='+inttostr(socketcount));}  {  debugout('socketcount='+inttostr(socketcount));}
179      //writeln('leaving processasios');
180  end;  end;
181    
182  procedure tselecteventcore.processmessages;  procedure tselecteventcore.processmessages;
# Line 293  Line 288 
288    repeat    repeat
289    
290      //the message loop will exit if all lasio's and ltimer's and lsignal's are destroyed      //the message loop will exit if all lasio's and ltimer's and lsignal's are destroyed
     if (not assigned(firstasin)) and (not assigned(firsttimer)) {$ifndef nosignal} and (not assigned(firstsignal)){$endif} then exit;  
     {fd_zero(FDSR);  
     fd_zero(FDSW);  
     currentsocket := firstasin;  
     if not assigned(currentsocket) then exit; //the message loop will exit if all lsockets are destroyed  
   
     repeat  
       if (not currentsocket.released) and (currentsocket.state<>wsclosed) then fd_set(currentsocket.fdhandlein,fdsr);  
       if (not currentsocket.released) and (currentsocket.state=wsconnecting) then fd_set(currentsocket.fdhandleout,fdsw);  
       if currentsocket is tlsocket then begin  
          if (not currentsocket.released) and (currentsocket.state=wsconnected) and(tlsocket(currentsocket).sendq <> '') then fd_set(currentsocket.fdhandleout,fdsw);  
       end;  
       tempsocket := currentsocket;  
       currentsocket := currentsocket.nextasin;  
       if tempsocket.released then begin  
         tempsocket.free;  
       end;  
     until not assigned(currentsocket);  
     }  
291      processtasks;      processtasks;
292      //currenttask := nil;      //currenttask := nil;
293      {beware}      {beware}
# Line 356  Line 332 
332    
333  procedure tselecteventcore.rmasterset(fd : integer;islistensocket : boolean);  procedure tselecteventcore.rmasterset(fd : integer;islistensocket : boolean);
334  begin  begin
335      //writeln('rmasterset called with fd ',fd);
336    if fd > absoloutemaxs then raise esocketexception.create('file discriptor out of range');    if fd > absoloutemaxs then raise esocketexception.create('file discriptor out of range');
337    if fd > maxs then maxs := fd;    if fd > maxs then maxs := fd;
338    if fd_isset(fd,fdsrmaster) then exit;    if fd_isset(fd,fdsrmaster) then exit;
# Line 365  Line 342 
342    
343  procedure tselecteventcore.rmasterclr(fd: integer);  procedure tselecteventcore.rmasterclr(fd: integer);
344  begin  begin
345      //writeln('rmasterclr called with fd ',fd);
346    if not fd_isset(fd,fdsrmaster) then exit;    if not fd_isset(fd,fdsrmaster) then exit;
347    fd_clr(fd,fdsrmaster);    fd_clr(fd,fdsrmaster);
348    
# Line 373  Line 351 
351    
352  procedure tselecteventcore.wmasterset(fd : integer);  procedure tselecteventcore.wmasterset(fd : integer);
353  begin  begin
354      //writeln('wmasterset called with fd ',fd);
355    if fd > absoloutemaxs then raise esocketexception.create('file discriptor out of range');    if fd > absoloutemaxs then raise esocketexception.create('file discriptor out of range');
356    if fd > maxs then maxs := fd;    if fd > maxs then maxs := fd;
357    
# Line 383  Line 362 
362    
363  procedure tselecteventcore.wmasterclr(fd: integer);  procedure tselecteventcore.wmasterclr(fd: integer);
364  begin  begin
365      //writeln('wmasterclr called with fd ',fd);
366    if not fd_isset(fd,fdswmaster) then exit;    if not fd_isset(fd,fdswmaster) then exit;
367    fd_clr(fd,fdswmaster);    fd_clr(fd,fdswmaster);
368  end;  end;
# Line 392  Line 372 
372    fdreverse[fd] := reverseto;    fdreverse[fd] := reverseto;
373  end;  end;
374    
375    var
376      inited:boolean;
377    
378    procedure lcoreinit;
379  begin  begin
380      if inited then exit;
381      inited := true;
382    eventcore := tselecteventcore.create;    eventcore := tselecteventcore.create;
383    
384    absoloutemaxs := absoloutemaxs_select;    absoloutemaxs := absoloutemaxs_select;
# Line 402  Line 386 
386    maxs := 0;    maxs := 0;
387    fd_zero(fdsrmaster);    fd_zero(fdsrmaster);
388    fd_zero(fdswmaster);    fd_zero(fdswmaster);
389    end;
390    
391  end.  end.

Legend:
Removed from v.10  
changed lines
  Added in v.82

No admin address has been configured">No admin address has been configured
ViewVC Help
Powered by ViewVC 1.1.22