<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi,
<br>
<br>
Στις 23/2/2018 5:17 μμ, ο Michael Van Canneyt έγραψε:
<br>
<blockquote type="cite" style="color: #000000;">
<br>
<br>
On Fri, 23 Feb 2018, Luca Olivetti wrote:
<br>
<br>
<blockquote type="cite" style="color: #000000;">Hello,
<br>
<br>
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.
<br>
I see that even overriding the SocketHandler wouldn't change
that, since it's connect is only called <b class="moz-txt-star"><span
class="moz-txt-tag">*</span>after<span class="moz-txt-tag">*</span></b>
the fpconnect call succeeds.
<br>
Also, I see no way to interrupt a pending connect from another
thread.
<br>
<br>
</blockquote>
</blockquote>
< snip >
<br>
<blockquote type="cite" style="color: #000000;">This is on my todo
list. Unfortunately, the way sockets work, this means
<br>
putting the socket in non-blocking mode, call connect, and then
use select
<br>
or some other means to wait till the socket is done with the
connect, and
<br>
then put the socket again in blocking mode.
<br>
</blockquote>
try this :
<br>
<br>
copy the ssockets.pp from <fpc sources>\packages\fcl-net\src
dir to your project dir and add the following line
<br>
<br>
SetIOTimeout(FIOTimeout);
<br>
<br>
to Procedure TInetSocket.Connect; like this
<br>
<br>
Procedure TInetSocket.Connect;
<br>
<br>
Var
<br>
A : THostAddr;
<br>
addr: TInetSockAddr;
<br>
Res : Integer;
<br>
<br>
begin
<br>
A := StrToHostAddr(FHost);
<br>
if A.s_bytes[1] = 0 then
<br>
With THostResolver.Create(Nil) do
<br>
try
<br>
If Not NameLookup(FHost) then
<br>
raise ESocketError.Create(seHostNotFound, [FHost]);
<br>
A:=HostAddress;
<br>
finally
<br>
free;
<br>
end;
<br>
addr.sin_family := AF_INET;
<br>
addr.sin_port := ShortHostToNet(FPort);
<br>
addr.sin_addr.s_addr := HostToNet(a.s_addr);
<br>
SetIOTimeout(FIOTimeout);
<br>
{$ifdef unix}
<br>
<a class="moz-txt-link-freetext" href="Res:=ESysEINTR">Res:=ESysEINTR</a>;
<br>
While (Res=ESysEINTR) do
<br>
{$endif}
<br>
<a class="moz-txt-link-freetext"
href="Res:=fpConnect%28Handle">Res:=fpConnect(Handle</a>, @addr,
sizeof(addr));
<br>
If Not (Res<0) then
<br>
if not FHandler.Connect then
<br>
begin
<br>
<a class="moz-txt-link-freetext" href="Res:=-1">Res:=-1</a>;
<br>
CloseSocket(Handle);
<br>
end;
<br>
If (Res<0) then
<br>
Raise ESocketError.Create(seConnectFailed,
[Format('%s:%d',[FHost, FPort])]);
<br>
end;
<br>
<br>
It works for me ....
<br>
<br>
regards,
<br>
<br>
<span class="moz-txt-tag">-- <br>
</span>Dimitrios Chr. Ioannidis
</body>
</html>