From 44dc132f5dc6ced75e4225826b4eb0dda63392ab Mon Sep 17 00:00:00 2001 From: beware Date: Sat, 20 Feb 2010 18:33:54 +0000 Subject: [PATCH] fd related central definition and small performance tweak in lcoreselect git-svn-id: file:///svnroot/lcore/trunk@83 b1de8a11-f9be-4011-bde0-cc7ace90066a --- fd_utils.pas | 13 +++++++++---- lcoreselect.pas | 8 +++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/fd_utils.pas b/fd_utils.pas index de89e5f..290eb05 100755 --- a/fd_utils.pas +++ b/fd_utils.pas @@ -23,8 +23,13 @@ unit fd_utils; interface +const + FDwordshift=5; + FDwordmaxbit=(1 shl FDwordshift)-1; + type - FDSet= Array [0..255] of longint; {31} + FDword=longint; + FDSet= Array [0..255] of fdword; {31} PFDSet= ^FDSet; Procedure FD_Clr(fd:longint;var fds:fdSet); @@ -44,7 +49,7 @@ Procedure FD_Clr(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif} { Remove fd from the set of filedescriptors} begin if (fd < 0) then raise exception.create('FD_Clr fd out of range: '+inttostr(fd)); - fds[fd shr 5]:=fds[fd shr 5] and (not (1 shl (fd and 31))); + fds[fd shr fdwordshift]:=fds[fd shr fdwordshift] and (not (1 shl (fd and fdwordmaxbit))); end; Procedure FD_Zero(var fds:fdSet); @@ -57,7 +62,7 @@ Procedure FD_Set(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif} { Add fd to the set of filedescriptors } begin if (fd < 0) then raise exception.create('FD_set fd out of range: '+inttostr(fd)); - fds[fd shr 5]:=fds[fd shr 5] or (1 shl (fd and 31)); + fds[fd shr fdwordshift]:=fds[fd shr fdwordshift] or (1 shl (fd and fdwordmaxbit)); end; Function FD_IsSet(fd:longint;var fds:fdSet):boolean;{$ifdef useinline}inline;{$endif} @@ -67,6 +72,6 @@ begin result := false; exit; end; - FD_IsSet:=((fds[fd shr 5] and (1 shl (fd and 31)))<>0); + FD_IsSet:=((fds[fd shr fdwordshift] and (1 shl (fd and fdwordmaxbit)))<>0); end; end. diff --git a/lcoreselect.pas b/lcoreselect.pas index feb8ef8..659bfce 100755 --- a/lcoreselect.pas +++ b/lcoreselect.pas @@ -93,6 +93,7 @@ var tempsocket : tlasio ; socketcount : integer ; // for debugging perposes :) dw,bt:integer; + currentfdword:fdword; fd : integer; begin //writeln('entering processasios'); @@ -104,10 +105,11 @@ begin {------- test optimised loop} socketcount := 0; - for dw := (maxs shr 5) downto 0 do if (fdsr[dw] or fdsw[dw]) <> 0 then begin - for bt := 0 to 31 do if (fdsr[dw] or fdsw[dw]) and (1 shl bt) <> 0 then begin + for dw := (maxs shr fdwordshift) downto 0 do if (fdsr[dw] or fdsw[dw]) <> 0 then begin + currentfdword := (fdsr[dw] or fdsw[dw]); + for bt := fdwordmaxbit downto 0 do if currentfdword and (1 shl bt) <> 0 then begin inc(socketcount); - fd := dw shl 5 or bt; + fd := dw shl fdwordshift or bt; //writeln('reversing fd ',fd); currentsocket := fdreverse[fd]; {if not assigned(currentsocket) then raise exception.create('currentsocket not assigned'); -- 2.30.2