Hello.
nfds This argument should be set to the highest-numbered file
descriptor in any of the three sets, plus 1.
...
class function TSocketAPI.Readable(const ASocket: TSocket; const ATimeout: Integer): Integer;
var
{$IFDEF MSWINDOWS}
LFDSet: TFDSet;
LTime_val: TTimeval;
{$ELSE}
LFDSet: {$IFDEF DELPHI}fd_set{$ELSE}TFDSet{$ENDIF};
LTime_val: timeval;
{$ENDIF}
P: PTimeVal;
begin
if (ATimeout >= 0) then
begin
LTime_val.tv_sec := ATimeout div 1000;
LTime_val.tv_usec := 1000 * (ATimeout mod 1000);
P := @LTime_val;
end else
P := nil;
{$IFDEF MSWINDOWS}
FD_ZERO(LFDSet);
FD_SET(ASocket, LFDSet);
Result := Net.Winsock2.select(0, @LFDSet, nil, nil, P);
{$ELSE MSWINDOWS}
{$IFDEF DELPHI}
FD_ZERO(LFDSet);
_FD_SET(ASocket, LFDSet);
// not correct for linux
//Result := Posix.SysSelect.select(0, @LFDSet, nil, nil, P);
// correct for linux
Result := Posix.SysSelect.select(ASocket + 1, @LFDSet, nil, nil, P);
{$ELSE DELPHI}
fpFD_ZERO(LFDSet);
fpFD_SET(ASocket, LFDSet);
Result := fpSelect(0, @LFDSet, nil, nil, P);
{$ENDIF DELPHI}
{$ENDIF MSWINDOWS}
end;
Hello.
Posix.SysSelect.selectfirst argument is0for Linux, but this is not correct according to manual: https://man7.org/linux/man-pages/man2/select.2.htmlPosix.SysSelect.selectfirst argument needs to beASocket + 1for Linux.