Hi,

Στις 23/2/2018 5:17 μμ, ο Michael Van Canneyt έγραψε:


On Fri, 23 Feb 2018, Luca Olivetti wrote:

Hello,

the TFpHttpClient has an IoTimeout property, which in turn sets the IOTimeout of its FSocket (TInetSocket), however there's no way to set a connection timeout. I see that even overriding the SocketHandler wouldn't change that, since it's connect is only called *after* the fpconnect call succeeds.
Also, I see no way to interrupt a pending connect from another thread.

< snip >
This is on my todo list. Unfortunately, the way sockets work, this means
putting the socket in non-blocking mode, call connect, and then use select
or some other means to wait till the socket is done with the connect, and
then put the socket again in blocking mode.
try this :

  copy the ssockets.pp from <fpc sources>\packages\fcl-net\src dir to your project dir and add the following line

SetIOTimeout(FIOTimeout);

to Procedure TInetSocket.Connect; like this

Procedure TInetSocket.Connect;

Var
  A : THostAddr;
  addr: TInetSockAddr;
  Res : Integer;

begin
  A := StrToHostAddr(FHost);
  if A.s_bytes[1] = 0 then
    With THostResolver.Create(Nil) do
      try
        If Not NameLookup(FHost) then
          raise ESocketError.Create(seHostNotFound, [FHost]);
        A:=HostAddress;
      finally
        free;
      end;
  addr.sin_family := AF_INET;
  addr.sin_port := ShortHostToNet(FPort);
  addr.sin_addr.s_addr := HostToNet(a.s_addr);
  SetIOTimeout(FIOTimeout);
  {$ifdef unix}
Res:=ESysEINTR;
    While (Res=ESysEINTR) do
  {$endif}
Res:=fpConnect(Handle, @addr, sizeof(addr));
  If Not (Res<0) then
    if not FHandler.Connect then
      begin
Res:=-1;
      CloseSocket(Handle);
      end;
  If (Res<0) then
    Raise ESocketError.Create(seConnectFailed, [Format('%s:%d',[FHost, FPort])]);
end;

It works for me ....

regards,

--
Dimitrios Chr. Ioannidis
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to