Having looked at the OverbyteIcsWSocket unit, I've noticed many IFDEF CLR which 
probably might be removed.

First of all, I think it's better to turn all buffers from PAnsiChar / array of 
AnsiChar to TBytes, as it is recommended by Embarcadero (though one would 
declare this type for compilers up to BDS2006).

Second, I see numerous cases of copying by for loops in CLR code, while on 
WIN32 it's done by Move. I also noticed System.Buffer.BlockCopy(FRcvdPtr, 0, 
Buffer, 0, FLineLength); in just one place instead of for loop, maybe this 
function should be used? Moreover, when copy from string to buffer is done, 
like here:

procedure TCustomWSocket.PutStringInSendBuffer(const Str : RawByteString);
{$IFDEF CLR}
var
    Data : TBytes;
    I    : Integer;
begin
    SetLength(Data, Length(Str));
    for I := 1 to Length(Str) do
        Data[I - 1] := Ord(Str[I]);
    PutDataInSendBuffer(Data, Length(Str));
{$ENDIF}

why not use Str.GetBytes method? (I suppose it to be realised in .Net from the 
very beginning)

Another places where I discovered possibly non-optimal defines:

1)

{$IFDEF CLR}
  TSockAddr          = OverbyteIcsWinSock.TSockAddr;  
{$ENDIF}
{$IFDEF WIN32}
  TSockAddr          = OverbyteIcsWinsock.TSockAddr;
    ip_mreq = record
        imr_multiaddr : in_addr;
        imr_interface : in_addr;
    end;
{$ENDIF}

=>

  TSockAddr          = OverbyteIcsWinSock.TSockAddr;  
{$IFDEF WIN32}
    ip_mreq = record
        imr_multiaddr : in_addr;
        imr_interface : in_addr;
    end;
{$ENDIF} ?

2)
    function    Send({$IFDEF CLR} const {$ENDIF} Data : TWSocketData; Len : 
Integer) : Integer; overload; virtual;
and
    function    SendTo(Dest       : TSockAddr;
                       DestLen    : Integer;
                       {$IFDEF CLR} const {$ENDIF} Data : TWSocketData;
                       Len        : Integer) : Integer; virtual;

why not declare it const for all platforms?

3)
in WSocket_accept there's too much conditions, even for D1 - I thought D1-D6 is 
unsupported in v7 ?

Some other remarks:

4)
function AddOptions(Opts: array of TWSocketOption): TWSocketOptions;
        Result := Result + [Opts[I]];
=> 
        Include(Result, Opts[I]);
as it is faster

5)
function  RemoveOption(
    Result := OptSet - [Opt];
=> 
        Exclude(Result, Opt);
the same

6) (possibly bug)
    for I := Low(LocalSockName.sin_zero) to High(LocalSockName.sin_zero) do
        LocalSockName.sin_zero[0] := #0;

LocalSockName.sin_zero[i] ?

7)
procedure TCustomSocksWSocket.SocksDoAuthenticate;
    TempS  := AnsiString(FSocksPassword);
    TempS  := AnsiString(FSocksUsercode);

Looks like one couldn't use Unicode characters in Socks login? Is it mistake or 
protocol restriction?


8)
        Phe := PHostent(@FDnsLookupBuffer);
        if phe <> nil then begin

Phe currently never could be nil, as FDnsLookupBuffer is declared as static 
array field

Of course, these are just small proposals, and I probably haven't taken into 
account some deep relations or something else, so please don't judge me too 
strictly.

--
Anton
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to