Select in socket of Delphi 2007 (a friend sent it to me:
http://www.sendspace.com/file/06ev02):
function TBaseSocket.Select(ReadReady, WriteReady, ExceptFlag: PBoolean;
TimeOut: Integer): Boolean;
var
ReadFds: TFDset;
ReadFdsptr: PFDset;
WriteFds: TFDset;
WriteFdsptr: PFDset;
ExceptFds: TFDset;
ExceptFdsptr: PFDset;
tv: timeval;
Timeptr: PTimeval;
begin
Result := False;
if Active then
begin
if Assigned(ReadReady) then
begin
ReadFdsptr := @ReadFds;
FD_ZERO(ReadFds);
FD_SET(FSocket, ReadFds);
end
else
ReadFdsptr := nil;
if Assigned(WriteReady) then
begin
WriteFdsptr := @WriteFds;
FD_ZERO(WriteFds);
FD_SET(FSocket, WriteFds);
end
else
WriteFdsptr := nil;
if Assigned(ExceptFlag) then
begin
ExceptFdsptr := @ExceptFds;
FD_ZERO(ExceptFds);
FD_SET(FSocket, ExceptFds);
end
else
ExceptFdsptr := nil;
if TimeOut >= 0 then
begin
tv.tv_sec := TimeOut div 1000;
tv.tv_usec := 1000 * (TimeOut mod 1000);
Timeptr := @tv;
end
else
Timeptr := nil;
Try
{$IFDEF MSWINDOWS}
Result := ErrorCheck(WinSock.select(FSocket + 1, ReadFdsptr,
WriteFdsptr, ExceptFdsptr, Timeptr)) > 0;
{$ENDIF}
{$IFDEF LINUX}
Result := ErrorCheck(Libc.select(FSocket + 1, ReadFdsptr,
WriteFdsptr, ExceptFdsptr, Timeptr)) > 0;
{$ENDIF}
except
Result := False;
end;
if Assigned(ReadReady) then
ReadReady^ := FD_ISSET(FSocket, ReadFds);
if Assigned(WriteReady) then
WriteReady^ := FD_ISSET(FSocket, WriteFds);
if Assigned(ExceptFlag) then
ExceptFlag^ := FD_ISSET(FSocket, ExceptFds);
end;
end;
--
Silvio Clécio
My public projects - github.com/silvioprog
_______________________________________________
fpc-pascal maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal