[fpc-pascal] socket timeout

Luca Olivetti luca at ventoso.org
Tue Apr 16 17:25:54 CEST 2013


Al 16/04/13 12:20, En/na Michael Schnell ha escrit:
> On 04/16/2013 11:26 AM, Xiangrong Fang wrote:
>> How can I set the connection and read/write timeout when using socket
>> in free pascal?
> I seem to remember that synapse can do this.

Only in svn and it does it this way

if FConnectionTimeout > 0 then
begin
  // connect in non-blocking mode
  b := NonBlockMode;
  NonBlockMode := true;
  SockCheck(synsock.Connect(FSocket, Sin));
  if (FLastError = WSAEINPROGRESS) OR (FLastError = WSAEWOULDBLOCK) then
    if not CanWrite(FConnectionTimeout) then
      FLastError := WSAETIMEDOUT;
  NonBlockMode := b;
end
else
  SockCheck(synsock.Connect(FSocket, Sin));


NonBlockMode in turn uses fpIoCtl with the FIONBIO parameter,
WSAEINPROGRESS=EsysEINPROGRESS, WSAEWOULDBLOCK=EsysEWOULDBLOCK and
CanWrite  does an fpSelect

Bye
-- 
Luca




More information about the fpc-pascal mailing list